예제 #1
0
 private async void INSTANCE_ChatChanged(ChatDBManager handler, ChatChangedEventArgs args)
 {
     if (!(args.CHAT is null) && string.Equals(args.CHAT.id, chatId))
     {
         await SharedUtils.CallDispatcherAsync(() => Chat = args.CHAT).ConfAwaitFalse();
     }
 }
예제 #2
0
 private void INSTANCE_NewChatMessage(ChatDBManager handler, NewChatMessageEventArgs args)
 {
     if (string.Equals(Chat?.id, args.MESSAGE.chatId))
     {
         NewChatMessage?.Invoke(this, args);
     }
 }
예제 #3
0
 //--------------------------------------------------------Events:---------------------------------------------------------------------\\
 #region --Events--
 private void INSTANCE_ChatMessageChanged(ChatDBManager handler, ChatMessageChangedEventArgs args)
 {
     if (string.Equals(Chat?.id, args.MESSAGE.chatId))
     {
         ChatMessageChanged?.Invoke(this, args);
     }
 }
예제 #4
0
 private async void INSTANCE_ChatChanged(ChatDBManager handler, ChatChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (Chat != null && Chat.id.Equals(args.CHAT.id))
         {
             showProfile();
         }
     });
 }
예제 #5
0
 private async void INSTANCE_ChatMessageChanged(ChatDBManager handler, ChatMessageChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (Chat != null && lastChatMessage != null && Equals(args.MESSAGE.chatId, Chat.id) && Equals(lastChatMessage.id, args.MESSAGE.id))
         {
             showLastChatMessage(args.MESSAGE);
         }
     });
 }
예제 #6
0
 private async void INSTANCE_NewChatMessage(ChatDBManager handler, NewChatMessageEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (Chat.id.Equals(args.MESSAGE.chatId))
         {
             showLastChatMessage(args.MESSAGE);
         }
     });
 }
예제 #7
0
        private async void INSTANCE_ChatChanged(ChatDBManager handler, Data_Manager2.Classes.Events.ChatChangedEventArgs args)
        {
            if (args.REMOVED)
            {
                CHATS.RemoveId(args.CHAT.id);
                args.Cancel = true;
                return;
            }
            else
            {
                if (CHATS.UpdateChat(args.CHAT))
                {
                    args.Cancel = true;
                    return;
                }
            }

            ChatDataTemplate newChat = await Task.Run(() =>
            {
                // Add the new chat to the list of chats:
                foreach (XMPPClient c in ConnectionHandler.INSTANCE.getClients())
                {
                    if (Equals(args.CHAT.userAccountId, c.getXMPPAccount().getBareJid()))
                    {
                        if (args.CHAT.chatType == ChatType.MUC)
                        {
                            return(new ChatDataTemplate()
                            {
                                Chat = args.CHAT,
                                Client = c,
                                MucInfo = MUCDBManager.INSTANCE.getMUCInfo(args.CHAT.id)
                            });
                        }
                        else
                        {
                            return(new ChatDataTemplate()
                            {
                                Chat = args.CHAT,
                                Client = c
                            });
                        }
                    }
                }
                return(null);
            });

            if (!(newChat is null))
            {
                CHATS.Add(newChat);
            }
        }
예제 #8
0
 private async void INSTANCE_ChatMessageChanged(ChatDBManager handler, ChatMessageChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (Chat != null && Equals(args.MESSAGE.chatId, Chat.id))
         {
             Task.Run(async() =>
             {
                 for (int i = 0; i < chatMessages.Count; i++)
                 {
                     if (chatMessages[i].message != null && Equals(chatMessages[i].message.id, args.MESSAGE.id))
                     {
                         // Only the main thread should update the list to prevent problems:
                         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => chatMessages[i].message = args.MESSAGE);
                     }
                 }
             });
         }
     });
 }
예제 #9
0
 //--------------------------------------------------------Events:---------------------------------------------------------------------\\
 #region --Events--
 private async void INSTANCE_NewChatMessage(ChatDBManager handler, NewChatMessageEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         ChatMessageTable msg = args.MESSAGE;
         if (Chat != null && Chat.id.Equals(msg.chatId))
         {
             // Only update for unread messages:
             if (msg.state == MessageState.UNREAD)
             {
                 msg.state = MessageState.READ;
                 ChatDBManager.INSTANCE.setChatMessage(msg, false, true);
             }
             chatMessages.Add(new ChatMessageDataTemplate()
             {
                 message = msg,
                 chat    = Chat
             });
         }
     });
 }
예제 #10
0
        private void INSTANCE_ChatChanged(ChatDBManager handler, ChatChangedEventArgs args)
        {
            Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Backup selected chat:
                ChatTemplate selectedChat = null;
                if (masterDetail_pnl.SelectedItem != null && masterDetail_pnl.SelectedItem is ChatTemplate)
                {
                    selectedChat = masterDetail_pnl.SelectedItem as ChatTemplate;
                }

                if (args.REMOVED)
                {
                    CHATS.RemoveId(args.CHAT.id);
                    args.Cancel = true;

                    // Restore selected chat:
                    if (selectedChat != null && !string.Equals(args.CHAT.id, selectedChat.chat.id))
                    {
                        masterDetail_pnl.SelectedItem = selectedChat;
                    }
                    return;
                }
                else
                {
                    if (CHATS.UpdateChat(args.CHAT))
                    {
                        args.Cancel = true;
                        // Restore selected chat:
                        if (selectedChat != null)
                        {
                            masterDetail_pnl.SelectedItem = selectedChat;
                        }
                        return;
                    }
                }

                Task.Run(() =>
                {
                    // Add the new chat to the list of chats:
                    foreach (XMPPClient c in ConnectionHandler.INSTANCE.getClients())
                    {
                        if (Equals(args.CHAT.userAccountId, c.getXMPPAccount().getIdAndDomain()))
                        {
                            ChatTemplate chatElement = new ChatTemplate {
                                chat = args.CHAT, client = c
                            };
                            if (args.CHAT.chatType == ChatType.MUC)
                            {
                                chatElement.mucInfo = MUCDBManager.INSTANCE.getMUCInfo(args.CHAT.id);
                            }

                            if (currentChatQuery == null || doesChatTemplateMatchesFilter(chatElement, currentChatQuery))
                            {
                                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    CHATS.Add(chatElement);
                                    // Restore selected chat:
                                    if (selectedChat != null)
                                    {
                                        masterDetail_pnl.SelectedItem = selectedChat;
                                    }
                                }).AsTask();
                            }
                        }
                    }
                });
            }).AsTask();
        }