Example #1
0
        private async void Store_StoreChanged(ChatMessageStore sender, ChatMessageStoreChangedEventArgs args)
        {
            if (args.Id != _messageid)
            {
                return;
            }

            switch (args.Kind)
            {
            case ChatStoreChangedEventKind.MessageDeleted:
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                    {
                        MessageBody = "Deleted message";
                    });

                DropEvents();
                break;
            }

            case ChatStoreChangedEventKind.MessageModified:
            {
                (var body, var ts) = await GetMessageInfo();

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                    {
                        (MessageBody, TimeStamp) = (body, ts);
                    });

                break;
            }
            }
        }
        private async void Store_StoreChanged(ChatMessageStore sender, ChatMessageStoreChangedEventArgs args)
        {
            if (args.Id != _conversationid)
            {
                return;
            }

            switch (args.Kind)
            {
            case ChatStoreChangedEventKind.ConversationModified:
            {
                var conversation = await _store.GetConversationAsync(args.Id);

                if (conversation == null)
                {
                    DropEvents();
                    break;
                }

                (var str, var dt) = await GetLastMessageInfo();

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                    {
                        (DisplayDescription, TimeStamp) = (str, dt);
                    });

                break;
            }

            case ChatStoreChangedEventKind.ConversationDeleted:
            {
                DropEvents();
                break;
            }
            }
        }
Example #3
0
        private async void Store_StoreChanged(ChatMessageStore sender, ChatMessageStoreChangedEventArgs args)
        {
            if (args.Id != _conversationid)
            {
                return;
            }

            switch (args.Kind)
            {
            case ChatStoreChangedEventKind.ConversationModified:
            {
                var conversation = await _store.GetConversationAsync(args.Id);

                if (conversation == null)
                {
                    DropEvents();
                    break;
                }

                UpdateMessages();
                break;
            }
            }
        }
Example #4
0
        private async void Store_StoreChanged(ChatMessageStore sender, ChatMessageStoreChangedEventArgs args)
        {
            switch (args.Kind)
            {
            case ChatStoreChangedEventKind.ConversationModified:
            {
                var conversation = await _store.GetConversationAsync(args.Id);

                if (conversation == null)
                {
                    if (ChatConversations.Any(x => x.ConversationId == args.Id))
                    {
                        var  existingConversation = ChatConversations.First(x => x.ConversationId == args.Id);
                        bool wasSelected          = SelectedItem == existingConversation;

                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                      () =>
                            {
                                ChatConversations.Remove(existingConversation);

                                if (wasSelected && ChatConversations.Count != 0)
                                {
                                    SelectedItem = ChatConversations[0];
                                }
                            });
                    }
                    break;
                }

                if (!ChatConversations.Any(x => x.ConversationId == args.Id))
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                  () =>
                        {
                            ChatConversations.Insert(0, new ChatMenuItemControl(conversation.Id));
                            if (!ChatConversations.Contains(SelectedItem))
                            {
                                SelectedItem = ChatConversations[0];
                            }
                        });
                }

                /*else
                 * {
                 *  var existingConversation = ChatConversations.First(x => x.ConversationId == args.Id);
                 *  await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                 *  () =>
                 *  {
                 *      bool wasSelected = SelectedItem == existingConversation;
                 *      var newConvo = new ChatMenuItemControl(conversation.Id);
                 *
                 *      ChatConversations.Remove(existingConversation);
                 *      ChatConversations.Insert(0, newConvo);
                 *
                 *      if (wasSelected)
                 *          SelectedItem = newConvo;
                 *  });
                 * }*/
                break;
            }

            case ChatStoreChangedEventKind.ConversationDeleted:
            {
                if (ChatConversations.Any(x => x.ConversationId == args.Id))
                {
                    var  existingConversation = ChatConversations.First(x => x.ConversationId == args.Id);
                    bool wasSelected          = SelectedItem == existingConversation;

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                  () =>
                        {
                            ChatConversations.Remove(existingConversation);

                            if (wasSelected && ChatConversations.Count != 0)
                            {
                                SelectedItem = ChatConversations[0];
                            }
                        });
                }
                break;
            }
            }
        }