private void SetHubConnectionHandlerToRecieveLeftBehindMessages(string yourPhoneNumber, Page chatPage, Friend friendChattingWith)
        {
            ScrollView  scrollViewChatMsgArea = (ScrollView)chatPage.FindByName("scrollViewChatMsgArea");
            StackLayout chat_messages_area    = (StackLayout)chatPage.FindByName("chat_messages_area");

            hubConnection.On <List <ChatMessage> >(yourPhoneNumber + "-left_behind", async(leftBehindChatMessages) =>
            {
                List <PrimaryKeyLeftBehindMsg> listOfPrimaryKeysForLeftBehindMsgs = new List <PrimaryKeyLeftBehindMsg>(); //Used to tell chatchub that messages have been received
                foreach (ChatMessage leftBehindChatMsg in leftBehindChatMessages)
                {
                    if ((leftBehindChatMsg.SeenByRecipient).Equals("no"))
                    {
                        //PLACE THE LEFT BEHIND MESSAGE IN YOUR CHAT AREA
                        leftBehindChatMsg.Writer = "Friend";
                        ChatMessageLabelGenerator.CreateAndDisplayChatMessageLabel(leftBehindChatMsg, friendChattingWith, chat_messages_area);
                        scrollViewChatMsgArea.ScrollToAsync(chat_messages_area, ScrollToPosition.End, false);

                        //PLACE THE MESSAGE IN YOUR DATABASE
                        await PlaceChatMessageInDatabase(leftBehindChatMsg.Msg, "Friend", friendChattingWith);

                        //PLACE THE PRIMARY KEY OF THIS MESSAGE IN A LIST
                        PrimaryKeyLeftBehindMsg primaryKey = new PrimaryKeyLeftBehindMsg();
                        primaryKey.MsgID = leftBehindChatMsg.MsgID; primaryKey.PhoneNumWriter = leftBehindChatMsg.PhoneNumOfWriter;
                        listOfPrimaryKeysForLeftBehindMsgs.Add(primaryKey);
                    }
                }
                //TELL CHAT HUB THAT THESE LEFT BEHIND MESSAGES HAVE BEEN RECEIVED
                await hubConnection.InvokeAsync("MessagesReceived", yourPhoneNumber, listOfPrimaryKeysForLeftBehindMsgs);
            });
        }
        private void SetHubConnectionhandlerToRecieveChatMsg(string yourPhoneNumber, Page chatPage, Friend friendChattingWith)
        {
            hubConnection.On <ChatMessage>(yourPhoneNumber, async(chatMessage) =>
            {
                //Friend friendChattingWith = (Friend)BindingContext;
                if (friendChattingWith.ID == chatMessage.PhoneNumOfWriter) //if the person's phone # that sent me the message is = to the phone # of the person i started the chat with
                {
                    ScrollView scrollViewChatMsgArea = (ScrollView)chatPage.FindByName("scrollViewChatMsgArea");
                    StackLayout chat_messages_area   = (StackLayout)chatPage.FindByName("chat_messages_area");

                    //CREATE AND DISPLAY THE CHAT MESSAGE THAT WAS RECIEVED
                    chatMessage.Writer = "Friend";
                    ChatMessageLabelGenerator.CreateAndDisplayChatMessageLabel(chatMessage, friendChattingWith, chat_messages_area);

                    //SCROLL TO THE END POSITION OF THE SCROLL VIEW SO WE CAN SEE THE MESSAGE ADDED
                    scrollViewChatMsgArea.ScrollToAsync(chat_messages_area, ScrollToPosition.End, false);

                    //PLACE THE MESSAGE RECEIVED IN THE DATABASE
                    await PlaceChatMessageInDatabase(chatMessage.Msg, "Friend", friendChattingWith);

                    //TELL THE HUB I RECEIVED THE MESSAGE
                    List <PrimaryKeyLeftBehindMsg> listOfPrimaryKeysForLeftBehindMsgs = new List <PrimaryKeyLeftBehindMsg>();
                    PrimaryKeyLeftBehindMsg primaryKey = new PrimaryKeyLeftBehindMsg();
                    primaryKey.MsgID = chatMessage.MsgID; primaryKey.PhoneNumWriter = chatMessage.PhoneNumOfWriter;
                    listOfPrimaryKeysForLeftBehindMsgs.Add(primaryKey);
                    await hubConnection.InvokeAsync("MessagesReceived", yourPhoneNumber, listOfPrimaryKeysForLeftBehindMsgs);
                }
            });
        }
Exemplo n.º 3
0
        public async Task MarkChatMessageAsSeen(string phoneNumOfMsgReceiver, PrimaryKeyLeftBehindMsg primaryKeyOfLeftBehindMsg)
        {
            string sql = "UPDATE " + "[" + phoneNumOfMsgReceiver + "] "
                         + "SET " + ApplicationConstants.SEEN_COLUMN + " = 'Yes' "
                         + "WHERE " + ApplicationConstants.MSG_ID + " = " + primaryKeyOfLeftBehindMsg.MsgID
                         + " AND " + ApplicationConstants.MSG_PHONE_NUM_WRITER + " = " + "'" + primaryKeyOfLeftBehindMsg.PhoneNumWriter + "';";

            await SQLNonQueryExecutor.ExecuteNonQuery(sql, Configuration);
        }