Exemplo n.º 1
0
        private void OnAsyns()
        {
            //new Thread(new ThreadStart(() =>
            //{

            //})).Start();

            // get event add new message, change title, change avatar
            Service.Client.OnAsync(
                path: "Conversations/" + Model.Key + "/ChangedTime",
                changed: (sender, args, context) =>
            {
                if (DateTime.Parse(args.Data) > this.LoadedTime)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        LoadChange(ConversationService.GetConversationById(Model.Key));
                    });
                }
            }
                );


            // get event user is entering
            Service.Client.OnAsync(
                path: "Conversations/" + Model.Key + "/Members",
                changed: (sender, args, context) =>
            {
                var users = ConversationService.GetUsersEnteringOfConversation(Model.Key);
                UserEnteringContainer.Dispatcher.Invoke(() =>
                {
                    if (users.Count > 0)
                    {
                        UserEnteringContainer.Children.Clear();
                        foreach (var user in users)
                        {
                            UserModel model = null;
                            UserInfors.TryGetValue(user.Key, out model);
                            UserEnteringContainer.Children.Add(new ConversationUserEnteringControl(model));
                        }

                        UserEnteringWrapper.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        UserEnteringWrapper.Visibility = Visibility.Collapsed;
                    }
                });
            }
                );
        }
Exemplo n.º 2
0
 private void OnAsyns()
 {
     Service.Client.OnAsync(
         path: "Conversations/" + Model.Key + "/ChangedTime",
         changed: (s, args, context) =>
     {
         if (DateTime.Parse(args.Data) > this.LoadedTime)
         {
             this.Dispatcher.Invoke(() =>
             {
                 LoadChange(ConversationService.GetConversationById(Model.Key));
             });
         }
     }
         );
 }
Exemplo n.º 3
0
        private void OnAsyns()
        {
            //new Thread(new ThreadStart(() =>
            //{

            //})).Start();

            Service.Client.OnAsync(
                path: "Conversations/" + Model.Key,
                changed: (sender, args, context) =>
            {
                if (args.Path == "/Title")
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        this.ConversationTitle.Text = args.Data;
                    });
                }
                else
                if (args.Path == "/Avatar")
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        this.ConversationAvatar.ImageSource = Ultilities.ConvertBase64StringToBitmapImage(args.Data);
                    });
                }
                else
                if (args.Path == "/ChangedTime" && IsShowing == false)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        Model = ConversationService.GetConversationById(Model.Key);
                        Load();
                    });
                }
                else
                if (args.Path == "/Members/" + Service.UserID + "/SeenTime")
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        Model = ConversationService.GetConversationById(Model.Key);
                        Load();
                    });
                }
            }
                );
        }
Exemplo n.º 4
0
        public void Load()
        {
            if (!string.IsNullOrEmpty(ConversationID))
            {
                Model = ConversationService.GetConversationById(ConversationID);
            }

            if (Model.Value != null)
            {
                // Load danh sách tạm user để tăng hiệu suất load thông tin user đang nhập văn bản
                this.UserInfors = ConversationService.GetUsersOfConversation(Model.Key);

                // Load conversation avatar
                this.ConversationAvatar.ImageSource = Ultilities.ConvertBase64StringToBitmapImage(Model.Value.Avatar);

                // Load conversation title
                this.ConversationTitle.Text = Model.Value.Title;

                // Load messages
                this.MessageContainer1.Children.Clear();
                foreach (var message in Model.Value.Messages.OrderBy(m => m.Value.SendTime))
                {
                    if (message.Value.UserID == "SYS")
                    {
                        this.MessageContainer1.Children.Add(new SystemMesageControl(message));
                    }
                    else
                    if (message.Value.UserID == UserService.UserID)
                    {
                        this.MessageContainer1.Children.Add(new SentMessageControl(message));
                    }
                    else
                    {
                        this.MessageContainer1.Children.Add(new ReceivedMessageControl(message));
                    }
                }


                // Load system emojis
                if (SystemValues.Emojis != null)
                {
                    foreach (var emoji in SystemValues.Emojis)
                    {
                        SystemEmojisContainer.Children.Add(new EmojiControl(this, emoji));
                    }
                }

                // Load system stickers
                if (SystemValues.Stickers != null)
                {
                    foreach (var sticker in SystemValues.Stickers)
                    {
                        SystemStickerContainer.Children.Add(new StickerControl(this, sticker));
                    }
                }

                this.LoadedTime = DateTime.Now;
            }

            OnAsyns();
        }