Exemplo n.º 1
0
 public Task SendPost(PostItem message)
 {
     Console.WriteLine("In SendPost");
     try
     {
         SendToWeb("Post", message.Body);
         return(_proxy.Invoke("SendToSecretFilesClient", message));
     }
     catch (InvalidOperationException ie) {
         UserDialogs.Instance.Alert("Not yet connected to server");
     }
     return(null);
 }
Exemplo n.º 2
0
        static void HandlePost(PostItem postMessage)           //not working check server
        {
            Console.WriteLine("Post data received, processing");
            //add data to new postitemstacklayout, add to top of scrollfeed.content
            if (postMessage is PostItem)
            {
                Console.WriteLine("Recieved from SignalR: post by {0}, post body: {1}, in group {2}",
                                  postMessage.Title, postMessage.Body, postMessage.GroupID);

                GlobalVars.CurrentChat.AddReceivedPostUI(postMessage);
            }

            //ChatClient.SendToWeb("intercepted post", postMessage.Title);
        }
Exemplo n.º 3
0
        /*public async Task<List<PostItem>> GetPostItemsByGroupOrderByRecentAsync(string groupid, bool syncItems = false)
         * {
         *      Console.WriteLine("In GetPostItemsByGroupAsync");
         *      try
         *      {
         *              List<PostItem> items = await postsTable
         *                      .Where(PostItem => PostItem.GroupID == groupid)//.OrderByDescending (PostItem => PostItem.reactionCount )
         *                      .ToListAsync();
         *
         *              Console.WriteLine("Done w GetPostItemsByGroupAsync");
         *              items.Reverse();
         *              return items;
         *      }
         *      catch (MobileServiceInvalidOperationException msioe)
         *      {
         *              Console.WriteLine(@"Invalid sync operation: {0}", msioe.Message);
         *      }
         *      catch (WebException we)
         *      {
         *              //UserDialogs.Instance.WarnToast ("Your data connection is a bit slow right now", null, 2000);
         *      }
         *      catch (TaskCanceledException)
         *      {
         *              //UserDialogs.Instance.WarnToast ("Your data connection is a bit slow right now", null, 2000);
         *
         *      }
         *      catch (Exception e)
         *      {
         *              Console.WriteLine(@"Sync error: {0} - {1}", e.ToString(), e.Message);
         *      }
         *      return null;
         * }*/

        public async Task SavePostItemsTaskAsync(PostItem item)
        {
            try
            {
                if (item.ID == null)
                {
                    await postsTable.InsertAsync(item);
                }
                else
                {
                    await postsTable.UpdateAsync(item);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("SavePostItemsTaskAsync error: " + e.Message);
            }
        }
Exemplo n.º 4
0
        partial void SendButton_TouchUpInside(UIButton sender)
        {
            var newPost = new PostItem
            {
                Title   = "Chris Verceles",
                Body    = TextField.Text,
                UserId  = Settings.UserId,
                GroupID = this.SecretFile.ID
            };

            //Add chat bubble to UI
            AddLocalClientPostToUI(newPost, PostStatusType.SendingPost);

            //send message to chat serv
            Console.WriteLine("Sending post to server");
            ChatMessageService.PostToThread(newPost);

            ResetTextField();
        }
Exemplo n.º 5
0
        //called by ChatMessageService when receiving a post from server
        public void AddReceivedPostUI(PostItem item)
        {
            InvokeOnMainThread(() => {
                ChatBubbleViewExtension postBubble = null;

                //if posted by this account, then find pending post then undo transparency
                if (string.Equals(item.UserId, Settings.UserId))
                {
                    var bubbleArr = PendingPostBubbles.ToArray();
                    for (int c = 0; c < bubbleArr.Length; c++)
                    {
                        Console.WriteLine("Searching for matching post, iteration {0}", c);
                        if (IsSamePostItem(bubbleArr[c].PostData, item))
                        {
                            Console.WriteLine("Found possible matching post w same title and body, iteration {0} with body {1} and alpha {2}",
                                              c, bubbleArr[c].PostData.Body, bubbleArr[c].Alpha);
                            if (IsPending(bubbleArr[c]))
                            {
                                Console.WriteLine("Found pending post, iteration {0} with body {1} and alpha {2}",
                                                  c, bubbleArr[c].PostData.Body, bubbleArr[c].Alpha);
                                bubbleArr[c].Alpha = 1.0f;
                                Console.WriteLine("Set alpha to {0}", bubbleArr[c].Alpha);
                            }
                            //else?
                        }
                        else
                        {
                            Console.WriteLine("iteration {0}, not a match", c);
                        }
                    }
                }
                else
                {
                    postBubble = CreateChatBubble(item, PostStatusType.Received2ndPartyPostFromServer);
                }

                ChatScrollView.ContentSize = new CGSize(ChatScrollView.ContentSize.Width,
                                                        ChatBubbleY + TextField.Frame.Height + SmileyButton.Frame.Height + 100);
            });
        }
Exemplo n.º 6
0
        //called by client app when user composes message
        public void AddLocalClientPostToUI(PostItem item, PostStatusType postStatus)
        {
            InvokeOnMainThread(() => {
                Console.WriteLine("Adding post, ChatBubbleY is {0}", ChatBubbleY);

                ChatBubbleViewExtension postBubble =
                    CreateChatBubble(item, postStatus);

                if (postStatus == PostStatusType.SendingPost)
                {
                    Console.WriteLine("Adding post w body {0} to pending list", item.Body);
                    PendingPosts.Add(item);
                    postBubble.Alpha    = 0.5f;
                    postBubble.PostData = item;
                    PendingPostBubbles.Add(postBubble);
                }

                ChatScrollView.ContentSize = new CGSize(ChatScrollView.ContentSize.Width,
                                                        ChatBubbleY + TextField.Frame.Height + SmileyButton.Frame.Height + 100);
                Console.WriteLine("Added post, ChatBubbleY is {0}", ChatBubbleY);
            });
        }
Exemplo n.º 7
0
        ChatBubbleViewExtension CreateChatBubble(PostItem post, PostStatusType postStatus)
        {
            bool IsLocal = false;

            if (postStatus == PostStatusType.SendingPost || postStatus == PostStatusType.PreviousPost)
            {
                IsLocal = true;
            }

            Console.WriteLine("postStatus is {0}, IsLocal is {1}", postStatus.ToString(), IsLocal);

            //base measurements
            var    verticalImageAdjustment = 5f;
            var    ChatAreaSpacing         = 10f;
            var    ImageDimension          = 22f;
            nfloat labelSpacing            = 5;
            var    ChatBubbleWidth         = 200; //use DecideChatBubbleWidth(
            var    ChatBubbleHeight        = 100; //heightDiff *1.5f;

            //dependent measurements
            ChatBubbleY += ChatBubbleHeight + ChatAreaSpacing;
            labelWidth   = ChatBubbleWidth - (ChatBubbleWidth - (labelSpacing * 2));
            labelHeight  = ChatBubbleHeight - (ChatBubbleHeight - (labelSpacing * 2));

            var ImageAndBubbleFrame = new CGRect(0, ChatBubbleY, ChatScrollView.Frame.Width, ChatBubbleHeight);
            var ImageX      = IsLocal ? ImageAndBubbleFrame.Width - ChatAreaSpacing - ImageDimension : ChatAreaSpacing;
            var ChatBubbleX = IsLocal ? ImageX - ChatBubbleWidth - ChatAreaSpacing : ImageDimension + (ChatAreaSpacing * 2);

            //profile pic
            var ProfileImageView = new UIImageView();

            ProfileImageView.Image       = UIImage.FromFile("profilepics/people.png");
            ProfileImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
            ProfileImageView.Frame       = new CGRect(ImageX,
                                                      verticalImageAdjustment,
                                                      ImageDimension,
                                                      ImageDimension);

            //chat bubble without the profile pic
            var ChatFrame = new CGRect(ChatBubbleX,
                                       0,
                                       ChatBubbleWidth,
                                       ChatBubbleHeight);
            var ChatMessage = new UIView();

            ChatMessage.BackgroundColor    = UIColor.White;
            ChatMessage.Layer.CornerRadius = 12;
            ChatMessage.Frame = ChatFrame;

            //this is the username
            var TitleLabel = new UILabel(new CGRect(labelSpacing, labelSpacing, labelWidth, labelHeight));

            TitleLabel.TextColor     = UIColor.LightGray;
            TitleLabel.TextAlignment = UITextAlignment.Left;
            TitleLabel.Font          = UIFont.SystemFontOfSize(14);
            TitleLabel.Text          = post.Title;
            TitleLabel.SizeToFit();

            //message content
            var BodyLabel = new UILabel(new CGRect(labelSpacing, TitleLabel.Frame.Height + (labelSpacing * 2), labelWidth, labelHeight));

            BodyLabel.TextColor = UIColor.Black;
            BodyLabel.Text      = post.Body;
            BodyLabel.Font      = UIFont.SystemFontOfSize(15);
            BodyLabel.SizeToFit();
            BodyLabel.Lines         = 50;
            BodyLabel.LineBreakMode = UILineBreakMode.WordWrap;

            //time message was sent
            var TimeStampLabel = new UILabel(new CGRect(ChatBubbleWidth - (labelWidth * 4), ChatBubbleHeight - labelHeight - (labelSpacing * 2)
                                                        , labelWidth, labelHeight));

            TimeStampLabel.TextAlignment = UITextAlignment.Left;
            TimeStampLabel.Font          = UIFont.SystemFontOfSize(12);
            TimeStampLabel.Text          = string.Format("{0}:{1}", DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes);
            TimeStampLabel.TextColor     = UIColor.LightGray;
            TimeStampLabel.SizeToFit();

            //add message text into one bubble view
            ChatMessage.AddSubview(TitleLabel);
            ChatMessage.BringSubviewToFront(TitleLabel);
            ChatMessage.AddSubview(BodyLabel);
            ChatMessage.BringSubviewToFront(BodyLabel);
            ChatMessage.AddSubview(TimeStampLabel);
            ChatMessage.BringSubviewToFront(TimeStampLabel);
            ChatMessage.SizeToFit();

            //add image and text bubble together
            //this is the chat bubble containing text and the profile pic
            var ImageAndBubbleViewContainer = new ChatBubbleViewExtension();

            ImageAndBubbleViewContainer.BackgroundColor = UIColor.Clear;
            ImageAndBubbleViewContainer.Frame           = ImageAndBubbleFrame;
            ImageAndBubbleViewContainer.AddSubview(ProfileImageView);
            ImageAndBubbleViewContainer.BringSubviewToFront(ProfileImageView);
            ImageAndBubbleViewContainer.AddSubview(ChatMessage);
            ImageAndBubbleViewContainer.BringSubviewToFront(ChatMessage);

            //add image and text bubble to chat window
            ChatScrollView.AddSubview(ImageAndBubbleViewContainer);
            ChatScrollView.BringSubviewToFront(ImageAndBubbleViewContainer);

            return(ImageAndBubbleViewContainer);
        }