Exemplo n.º 1
0
        public void SendLeftMessages(AbstractMessage msg, bool isSimulating = false, bool reversed = false, bool loadConversation = false)
        {
            Console.WriteLine(msg.SenderID);

            if (reversed)
            {
                if (_headBubbleChat == null)
                {
                    _headBubbleChat = new BubbleChat();
                    _headBubbleChat.SetAva(msg.SenderID);
                    _headBubbleChat.NickName.Foreground = iconColor.Foreground;
                    spMessagesContainer.Children.Insert(0, _headBubbleChat);
                }
            }
            else
            {
                if (_previousBubbleChat == null)
                {
                    _previousBubbleChat = new BubbleChat();
                    _previousBubbleChat.SetAva(msg.SenderID);
                    _previousBubbleChat.NickName.Foreground = iconColor.Foreground;
                    spMessagesContainer.Children.Add(_previousBubbleChat);
                }
            }

            Bubble          b         = null;
            ThumbnailBubble thumbnail = null;
            var             app       = MainWindow.chatApplication;

            if (BubbleTypeParser.Parse(msg) == BubbleType.Text)
            {
                b          = new Bubble();
                b.Messages = (msg as TextMessage).Message;
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Attachment)
            {
                b          = new Bubble();
                b.Messages = (msg as AttachmentMessage).FileName;
                b.SetLink((msg as AttachmentMessage).FileID);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Image)
            {
                string    fileID   = (msg as ImageMessage).FileID;
                string    fileName = (msg as ImageMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Left;
                thumbnail.Margin = new Thickness(5, 0, 0, 0);
                Console.WriteLine("Image sent");
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Video)
            {
                string    fileID   = (msg as VideoMessage).FileID;
                string    fileName = (msg as VideoMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Left;
                thumbnail.Margin = new Thickness(5, 0, 0, 0);
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Sticker)
            {
                MessageCore.Sticker.Sticker sticker = (msg as StickerMessage).Sticker;
                MessageCore.Sticker.Sticker.LoadedStickers.TryGetValue(sticker.ID, out var result);
                SendStickerOnTheLeft(result, reversed, _previousBubbleChat, _headBubbleChat);
            }

            if (b != null)
            {
                b.Type = BubbleTypeParser.Parse(msg);
                b.ControlUpdate();

                b.SetSeen(false);
                b.SetBG(Color.FromRgb(246, 246, 246));
                b.SetDirect(true); // true = left false = right
            }

            if (reversed)
            {
                if (b != null)
                {
                    _headBubbleChat.InsertBubble(0, b);
                }
                if (thumbnail != null)
                {
                    _headBubbleChat.InsertMedia(thumbnail);
                }
                if (loadConversation)
                {
                    MessagesContainer.ScrollToEnd();
                }
                else
                {
                    MessagesContainer.ScrollToHome();
                }
            }
            else
            {
                if (b != null)
                {
                    _previousBubbleChat.AddBubble(b);
                }
                if (thumbnail != null)
                {
                    _previousBubbleChat.AddMedia(thumbnail);
                }
                MessagesContainer.ScrollToEnd();
            }

            if (thumbnail != null)
            {
                thumbnail.Click += ThumbnailClick;
            }

            app.model.CurrentUserMessages.Add(new BubbleInfo(msg, true));
            app.model.Conversations[app.model.currentSelectedConversation].Bubbles.Add(new BubbleInfo(msg, true));
        }
Exemplo n.º 2
0
        public void SendMessage(AbstractMessage msg, bool isSimulating = false, bool reversed = false, bool loadConversation = false) //on the Rightside
        {
            if (reversed)
            {
                _headBubbleChat = null;
            }
            else
            {
                _previousBubbleChat = null;
            }

            Bubble          b         = null;
            ThumbnailBubble thumbnail = null;
            var             app       = MainWindow.chatApplication;

            if (BubbleTypeParser.Parse(msg) == BubbleType.Text)
            {
                b          = new Bubble();
                b.Messages = (msg as TextMessage).Message;
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Attachment)
            {
                b          = new Bubble();
                b.Messages = (msg as AttachmentMessage).FileName;
                b.SetLink((msg as AttachmentMessage).FileID);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Image)
            {
                string    fileID   = (msg as ImageMessage).FileID;
                string    fileName = (msg as ImageMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Right;
                thumbnail.Margin = new Thickness(0, 0, 16, 0);
                // thumbnail.IsActive = true;
                Console.WriteLine("Image sent");
                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Video)
            {
                string    fileID   = (msg as VideoMessage).FileID;
                string    fileName = (msg as VideoMessage).FileName;
                MediaInfo media    = GetMediaInfo(fileID, fileName, app.model.currentSelectedConversation);
                thumbnail = new ThumbnailBubble(media);
                thumbnail.HorizontalAlignment = HorizontalAlignment.Right;
                thumbnail.Margin = new Thickness(0, 0, 16, 0);
                // thumbnail.IsActive = true;

                AddMedia(fileID, fileName, isSimulating);
            }
            else if (BubbleTypeParser.Parse(msg) == BubbleType.Sticker)
            {
                MessageCore.Sticker.Sticker sticker = (msg as StickerMessage).Sticker;
                //var result;
                MessageCore.Sticker.Sticker.LoadedStickers.TryGetValue(sticker.ID, out var result);
                SendStickerOnTheRight(result, reversed);
            }

            if (b != null)
            {
                b.Type = BubbleTypeParser.Parse(msg);
                b.ControlUpdate();

                b.SetBG(bubbleColor);

                b.IsLeft = false;

                if (bubbleColor.R + bubbleColor.G + bubbleColor.B >= 565)
                {
                    b.SetTextColor(Colors.Black);
                }
                else
                {
                    b.SetTextColor(Colors.White);
                }
                b.SetDirect(false);// true = left false = right
                b.SetSeen(false);
            }

            if (reversed)
            {
                if (b != null)
                {
                    spMessagesContainer.Children.Insert(0, b);
                }
                if (thumbnail != null)
                {
                    spMessagesContainer.Children.Insert(0, thumbnail);
                }
                if (loadConversation)
                {
                    MessagesContainer.ScrollToEnd();
                }
                else
                {
                    MessagesContainer.ScrollToHome();
                }
            }
            else
            {
                if (b != null)
                {
                    spMessagesContainer.Children.Add(b);
                }
                if (thumbnail != null)
                {
                    spMessagesContainer.Children.Add(thumbnail);
                }
                MessagesContainer.ScrollToEnd();
            }

            if (thumbnail != null)
            {
                thumbnail.Click += ThumbnailClick;
            }

            app.model.CurrentUserMessages.Add(new BubbleInfo(msg, false));
            app.model.Conversations[app.model.currentSelectedConversation].Bubbles.Add(new BubbleInfo(msg, false));

            if (isSimulating)
            {
                return;
            }
            SendMessage packet = new SendMessage();

            packet.ConversationID = app.model.currentSelectedConversation;
            packet.Message        = msg;
            _ = ChatConnection.Instance.Send(packet);
        }