private void InsertMessage(TLMessageCommon message)
        {
            var messagesWithLinks = LinkUtils.ProcessLinks(new List <TLMessageBase> {
                message
            }, _mediaWebPagesCache);

            if (messagesWithLinks.Count > 0)
            {
                BeginOnUIThread(() =>
                {
                    InsertMessages(messagesWithLinks);

                    Status = string.Empty;
                    if (Items.Count == 0)
                    {
                        IsEmptyList = true;
                        NotifyOfPropertyChange(() => IsEmptyList);
                    }
                });
            }
        }
        public void Handle(TLMessageCommon message)
        {
            if (message == null)
            {
                return;
            }

            if (message.ToId is TLPeerUser)
            {
                var user = CurrentItem as TLUserBase;
                if (user != null)
                {
                    if (!message.Out.Value &&
                        user.Index == message.FromId.Value)
                    {
                        InsertMessage(message);
                    }
                    else if (message.Out.Value &&
                             user.Index == message.ToId.Id.Value)
                    {
                        InsertMessage(message);
                    }
                }
            }
            else if (message.ToId is TLPeerChat)
            {
                var chat = CurrentItem as TLChatBase;
                if (chat != null)
                {
                    if (chat.Index == message.ToId.Id.Value)
                    {
                        InsertMessage(message);
                    }
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var accentColor     = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
            var foregroundColor = new SolidColorBrush((Color)Application.Current.Resources["PhoneSubtleColor"]);

            TLMessageCommon message   = null;
            var             dialog    = value as TLDialog;
            var             broadcast = value as TLBroadcastDialog;

            if (dialog != null)
            {
                message = dialog.TopMessage as TLMessageCommon;
            }
            else if (broadcast != null)
            {
                message = broadcast.TopMessage as TLMessageCommon;
            }
            else
            {
                var encryptedDialog = value as TLEncryptedDialog;
                if (encryptedDialog != null)
                {
                    if (TLUtils.IsDisplayedDecryptedMessage(encryptedDialog.TopMessage))
                    {
                        var unreadDecrypted = encryptedDialog.TopMessage.Unread.Value;
                        var outDecrypted    = encryptedDialog.TopMessage.Out.Value;

                        return(unreadDecrypted && !outDecrypted ? accentColor : foregroundColor);
                    }

                    for (var i = 0; i < encryptedDialog.Messages.Count; i++)
                    {
                        if (TLUtils.IsDisplayedDecryptedMessage(encryptedDialog.Messages[i]))
                        {
                            var unreadDecrypted = encryptedDialog.Messages[i].Unread.Value;
                            var outDecrypted    = encryptedDialog.Messages[i].Out.Value;

                            return(unreadDecrypted && !outDecrypted ? accentColor : foregroundColor);
                        }
                    }

                    return(foregroundColor);
                }
            }

            if (message == null)
            {
                var decryptedMessage = value as TLDecryptedMessageBase;
                if (decryptedMessage != null)
                {
                    var unreadDecrypted = decryptedMessage.Unread.Value;
                    var outDecrypted    = decryptedMessage.Out.Value;

                    return(unreadDecrypted && !outDecrypted ? accentColor : foregroundColor);
                }

                return(foregroundColor);
            }

            var unread    = message.Unread.Value;
            var outFlag   = message.Out.Value;
            var useAccent = unread && !outFlag;

            return(useAccent ? accentColor : foregroundColor);
        }
Beispiel #4
0
        private static bool IsReadMessage(TLMessageCommon messageCommon,
                                          Dictionary <int, TLUpdateReadHistory> readChatOutbox, Dictionary <int, TLUpdateReadHistory> readChatInbox,
                                          Dictionary <int, TLUpdateReadHistory> readUserOutbox, Dictionary <int, TLUpdateReadHistory> readUserInbox,
                                          Dictionary <int, TLUpdateReadChannelOutbox> readChannelOutbox, Dictionary <int, TLUpdateReadChannelInbox> readChannelInbox)
        {
            if (messageCommon.ToId is TLPeerChat)
            {
                if (messageCommon.Out.Value)
                {
                    TLUpdateReadHistory updateReadHistory;
                    if (readChatOutbox.TryGetValue(messageCommon.ToId.Id.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
                else
                {
                    TLUpdateReadHistory updateReadHistory;
                    if (readChatInbox.TryGetValue(messageCommon.ToId.Id.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
            }
            else if (messageCommon.ToId is TLPeerUser)
            {
                if (messageCommon.Out.Value)
                {
                    TLUpdateReadHistory updateReadHistory;
                    if (readUserOutbox.TryGetValue(messageCommon.ToId.Id.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
                else
                {
                    TLUpdateReadHistory updateReadHistory;
                    if (readUserInbox.TryGetValue(messageCommon.FromId.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
            }
            else if (messageCommon.ToId is TLPeerChannel)
            {
                if (messageCommon.Out.Value)
                {
                    TLUpdateReadChannelOutbox updateReadHistory;
                    if (readChannelOutbox.TryGetValue(messageCommon.ToId.Id.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
                else
                {
                    TLUpdateReadChannelInbox updateReadHistory;
                    if (readChannelInbox.TryGetValue(messageCommon.ToId.Id.Value, out updateReadHistory) &&
                        updateReadHistory.MaxId.Value >= messageCommon.Index)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }