Пример #1
0
        private static (string Text, IList <TextEntity> Entities) UpdateMessagePinned(MessageViewModel message, ChatEventMessagePinned messagePinned, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            content = ReplaceWithLink(Strings.Resources.EventLogPinnedMessages, "un1", fromUser, ref entities);

            return(content, entities);
        }
Пример #2
0
        //private string GetFromLabel(TLMessage message, string title)
        //{
        //    return GetFromLabelInternal(message, title) + Environment.NewLine;
        //}

        private string GetFromLabel(MessageViewModel message, string title)
        {
            if (!string.IsNullOrWhiteSpace(title))
            {
                return(title);
            }

            if (message.IsChannelPost)
            {
                var chat = message.GetChat();
                if (chat != null)
                {
                    return(message.ProtoService.GetTitle(chat));
                }
            }
            else if (message.IsSaved())
            {
                if (message.ForwardInfo is MessageForwardedFromUser fromUser)
                {
                    return(message.ProtoService.GetUser(fromUser.SenderUserId)?.GetFullName());
                }
                else if (message.ForwardInfo is MessageForwardedPost post)
                {
                    return(message.ProtoService.GetTitle(message.ProtoService.GetChat(post.ChatId)));
                }
            }

            var user = message.GetSenderUser();

            if (user != null)
            {
                return(user.GetFullName());
            }

            //if (message.IsPost && (message.ToId is TLPeerChat || message.ToId is TLPeerChannel))
            //{
            //    return message.Parent?.DisplayName ?? string.Empty;
            //}
            //else if (message.IsSaved() && message.FwdFromUser is TLUser user)
            //{
            //    return user.FullName;
            //}

            //var from = message.From?.FullName ?? string.Empty;
            //if (message.ViaBot != null && message.FwdFrom == null)
            //{
            //    from += $" via @{message.ViaBot.Username}";
            //}

            //return from;
            return(title ?? string.Empty);
        }
Пример #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var venue = _message.Content as MessageVenue;

            if (venue == null)
            {
                return;
            }

            var user = _message.GetSenderUser();

            if (user != null)
            {
                _message.Delegate.OpenLocation(venue.Venue.Location, user.GetFullName());
            }
        }
Пример #4
0
        private static (string Text, IList <TextEntity> Entities) UpdateUsernameChanged(MessageViewModel message, ChatEventUsernameChanged usernameChanged, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (string.IsNullOrEmpty(usernameChanged.NewUsername))
            {
                content = ReplaceWithLink(Strings.Resources.EventLogRemovedGroupLink, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogChangedGroupLink, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #5
0
        private static (string Text, IList <TextEntity> Entities) UpdateDescriptionChanged(MessageViewModel message, ChatEventDescriptionChanged descriptionChanged, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (message.IsChannelPost)
            {
                content = ReplaceWithLink(Strings.Resources.EventLogEditedChannelDescription, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogEditedGroupDescription, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #6
0
        private static (string Text, IList <TextEntity> Entities) UpdateMessageEdited(MessageViewModel message, ChatEventMessageEdited messageEdited, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (messageEdited.NewMessage.Content is MessageText)
            {
                content = ReplaceWithLink(Strings.Resources.EventLogEditedMessages, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogEditedCaption, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #7
0
        private static (string Text, IList <TextEntity> Entities) UpdateIsAllHistoryAvailableToggled(MessageViewModel message, ChatEventIsAllHistoryAvailableToggled isAllHistoryAvailableToggled, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (isAllHistoryAvailableToggled.IsAllHistoryAvailable)
            {
                content = ReplaceWithLink(Strings.Resources.EventLogToggledInvitesHistoryOn, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogToggledInvitesHistoryOff, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #8
0
        private static (string Text, IList <TextEntity> Entities) UpdateStickerSetChanged(MessageViewModel message, ChatEventStickerSetChanged stickerSetChanged, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (stickerSetChanged.NewStickerSetId == 0)
            {
                content = ReplaceWithLink(Strings.Resources.EventLogRemovedStickersSet, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogChangedStickersSet, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #9
0
        private static (string Text, IList <TextEntity> Entities) UpdateSignMessagesToggled(MessageViewModel message, ChatEventSignMessagesToggled signMessagesToggled, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            var fromUser = message.GetSenderUser();

            if (signMessagesToggled.SignMessages)
            {
                content = ReplaceWithLink(Strings.Resources.EventLogToggledSignaturesOn, "un1", fromUser, ref entities);
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.EventLogToggledSignaturesOff, "un1", fromUser, ref entities);
            }

            return(content, entities);
        }
Пример #10
0
        private void ConvertEdited(MessageViewModel message)
        {
            //var message = ViewModel;
            //var bot = false;
            //if (message.From != null)
            //{
            //    bot = message.From.IsBot;
            //}

            var bot = false;

            var sender = message.GetSenderUser();

            if (sender != null && sender.Type is UserTypeBot)
            {
                bot = true;
            }

            EditedLabel.Text = message.EditDate != 0 && message.ViaBotUserId == 0 && !bot && !(message.ReplyMarkup is ReplyMarkupInlineKeyboard) ? $"{Strings.Resources.EditedMessage}\u00A0\u2009" : string.Empty;
        }
Пример #11
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var location = _message.Content as MessageLocation;

            if (location == null)
            {
                return;
            }

            if (location.LivePeriod > 0)
            {
            }
            else
            {
                var user = _message.GetSenderUser();
                if (user != null)
                {
                    _message.Delegate.OpenLocation(location.Location, user.GetFullName());
                }
            }
        }
Пример #12
0
        private string GetFromLabel(MessageViewModel message, string title)
        {
            if (!string.IsNullOrWhiteSpace(title))
            {
                return(title);
            }

            if (message.IsChannelPost)
            {
                var chat = message.GetChat();
                if (chat != null)
                {
                    return(message.ProtoService.GetTitle(chat));
                }
            }
            else if (message.IsSaved())
            {
                if (message.ForwardInfo?.Origin is MessageForwardOriginUser fromUser)
                {
                    return(message.ProtoService.GetUser(fromUser.SenderUserId)?.GetFullName());
                }
                else if (message.ForwardInfo?.Origin is MessageForwardOriginChannel post)
                {
                    return(message.ProtoService.GetTitle(message.ProtoService.GetChat(post.ChatId)));
                }
                else if (message.ForwardInfo?.Origin is MessageForwardOriginHiddenUser fromHiddenUser)
                {
                    return(fromHiddenUser.SenderName);
                }
            }

            var user = message.GetSenderUser();

            if (user != null)
            {
                return(user.GetFullName());
            }

            return(title ?? string.Empty);
        }
Пример #13
0
        private static (string, IList <TextEntity>) UpdateChatAddMembers(MessageViewModel message, MessageChatAddMembers chatAddMembers, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            int singleUserId = 0;

            if (singleUserId == 0 && chatAddMembers.MemberUserIds.Count == 1)
            {
                singleUserId = chatAddMembers.MemberUserIds[0];
            }

            var fromUser = message.GetSenderUser();

            if (singleUserId != 0)
            {
                var whoUser = message.ProtoService.GetUser(singleUserId);
                if (singleUserId == message.SenderUserId)
                {
                    var chat       = message.GetChat();
                    var supergroup = chat.Type as ChatTypeSupergroup;
                    if (supergroup != null && supergroup.IsChannel)
                    {
                        if (singleUserId == message.ProtoService.GetMyId())
                        {
                            content = Strings.Resources.ChannelJoined;
                        }
                        else
                        {
                            content = ReplaceWithLink(Strings.Resources.EventLogChannelJoined, "un1", fromUser, ref entities);
                        }
                    }
                    else
                    {
                        if (supergroup != null && !supergroup.IsChannel)
                        {
                            if (singleUserId == message.ProtoService.GetMyId())
                            {
                                content = Strings.Resources.ChannelMegaJoined;
                            }
                            else
                            {
                                content = ReplaceWithLink(Strings.Resources.ActionAddUserSelfMega, "un1", fromUser, ref entities);
                            }
                        }
                        else if (message.IsOutgoing)
                        {
                            content = Strings.Resources.ActionAddUserSelfYou;
                        }
                        else
                        {
                            content = ReplaceWithLink(Strings.Resources.ActionAddUserSelf, "un1", fromUser, ref entities);
                        }
                    }
                }
                else
                {
                    if (message.IsOutgoing)
                    {
                        content = ReplaceWithLink(Strings.Resources.ActionYouAddUser, "un2", whoUser, ref entities);
                    }
                    else if (singleUserId == message.ProtoService.GetMyId())
                    {
                        var chat       = message.GetChat();
                        var supergroup = chat.Type as ChatTypeSupergroup;
                        if (supergroup != null)
                        {
                            if (supergroup.IsChannel)
                            {
                                content = ReplaceWithLink(Strings.Resources.ChannelAddedBy, "un1", fromUser, ref entities);
                            }
                            else
                            {
                                content = ReplaceWithLink(Strings.Resources.MegaAddedBy, "un1", fromUser, ref entities);
                            }
                        }
                        else
                        {
                            content = ReplaceWithLink(Strings.Resources.ActionAddUserYou, "un1", fromUser, ref entities);
                        }
                    }
                    else
                    {
                        content = ReplaceWithLink(Strings.Resources.ActionAddUser, "un1", fromUser, ref entities);
                        content = ReplaceWithLink(content, "un2", whoUser, ref entities);
                    }
                }
            }
            else
            {
                if (message.IsOutgoing)
                {
                    content = ReplaceWithLink(Strings.Resources.ActionYouAddUser, "un2", chatAddMembers.MemberUserIds, message.ProtoService, ref entities);
                }
                else
                {
                    content = ReplaceWithLink(Strings.Resources.ActionAddUser, "un1", message.GetSenderUser(), ref entities);
                    content = ReplaceWithLink(content, "un2", chatAddMembers.MemberUserIds, message.ProtoService, ref entities);
                }
            }

            return(content, entities);
        }
Пример #14
0
        private static (string, IList <TextEntity>) UpdateBasicGroupChatCreate(MessageViewModel message, MessageBasicGroupChatCreate basicGroupChatCreate, bool active)
        {
            var content  = string.Empty;
            var entities = active ? new List <TextEntity>() : null;

            if (message.IsOutgoing)
            {
                content = Strings.Resources.ActionYouCreateGroup;
            }
            else
            {
                content = ReplaceWithLink(Strings.Resources.ActionCreateGroup, "un1", message.GetSenderUser(), ref entities);
            }

            return(content, entities);
        }
Пример #15
0
        private void UpdateMessageHeader(MessageViewModel message)
        {
            MaybeUseInner(ref message);

            var paragraph = HeaderLabel;
            var admin     = AdminLabel;
            var parent    = Header;

            paragraph.Inlines.Clear();

            if (message == null)
            {
                return;
            }

            var chat = message.GetChat();

            var sticker = message.Content is MessageSticker;
            var light   = sticker || message.Content is MessageVideoNote;
            var shown   = false;

            if (!light && message.IsFirst && !message.IsOutgoing && !message.IsChannelPost && (chat.Type is ChatTypeBasicGroup || chat.Type is ChatTypeSupergroup))
            {
                var sender = message.GetSenderUser();

                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(new Run {
                    Text = sender?.GetFullName()
                });
                hyperlink.UnderlineStyle = UnderlineStyle.None;
                hyperlink.Foreground     = PlaceholderHelper.GetBrush(message.SenderUserId);
                hyperlink.Click         += (s, args) => From_Click(message);

                paragraph.Inlines.Add(hyperlink);
                shown = true;
            }
            else if (!light && message.IsChannelPost && chat.Type is ChatTypeSupergroup)
            {
                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(new Run {
                    Text = message.ProtoService.GetTitle(chat)
                });
                hyperlink.UnderlineStyle = UnderlineStyle.None;
                //hyperlink.Foreground = Convert.Bubble(message.ChatId);
                hyperlink.Click += (s, args) => From_Click(message);

                paragraph.Inlines.Add(hyperlink);
                shown = true;
            }
            else if (!light && message.IsFirst && message.IsSaved())
            {
                var title = string.Empty;
                if (message.ForwardInfo is MessageForwardedFromUser fromUser)
                {
                    title = message.ProtoService.GetUser(fromUser.SenderUserId)?.GetFullName();
                }
                else if (message.ForwardInfo is MessageForwardedPost post)
                {
                    title = message.ProtoService.GetTitle(message.ProtoService.GetChat(post.ForwardedFromChatId));
                }

                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(new Run {
                    Text = title ?? string.Empty
                });
                hyperlink.UnderlineStyle = UnderlineStyle.None;
                //hyperlink.Foreground = Convert.Bubble(message.FwdFrom?.FromId ?? message.FwdFrom?.ChannelId ?? 0);
                hyperlink.Click += (s, args) => FwdFrom_Click(message);

                paragraph.Inlines.Add(hyperlink);
                shown = true;
            }

            if (shown)
            {
                if (admin != null && !message.IsOutgoing && message.Delegate != null && message.Delegate.IsAdmin(message.SenderUserId))
                {
                    paragraph.Inlines.Add(new Run {
                        Text = " " + Strings.Resources.ChatAdmin, Foreground = null
                    });
                }
            }

            var forward = false;

            if (message.ForwardInfo != null && !sticker && !message.IsSaved())
            {
                if (paragraph.Inlines.Count > 0)
                {
                    paragraph.Inlines.Add(new LineBreak());
                }

                paragraph.Inlines.Add(new Run {
                    Text = Strings.Resources.ForwardedMessage, FontWeight = FontWeights.Normal
                });
                paragraph.Inlines.Add(new LineBreak());
                paragraph.Inlines.Add(new Run {
                    Text = Strings.Resources.From + " ", FontWeight = FontWeights.Normal
                });

                var title = string.Empty;
                if (message.ForwardInfo is MessageForwardedFromUser fromUser)
                {
                    title = message.ProtoService.GetUser(fromUser.SenderUserId)?.GetFullName();
                }
                else if (message.ForwardInfo is MessageForwardedPost post)
                {
                    title = message.ProtoService.GetTitle(message.ProtoService.GetChat(post.ChatId));
                }

                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(new Run {
                    Text = title
                });
                hyperlink.UnderlineStyle = UnderlineStyle.None;
                hyperlink.Foreground     = light ? new SolidColorBrush(Colors.White) : paragraph.Foreground;
                hyperlink.Click         += (s, args) => FwdFrom_Click(message);

                paragraph.Inlines.Add(hyperlink);
                forward = true;
            }

            //if (message.HasViaBotId && message.ViaBot != null && !message.ViaBot.IsDeleted && message.ViaBot.HasUsername)
            var viaBot = message.ProtoService.GetUser(message.ViaBotUserId);

            if (viaBot != null && viaBot.Type is UserTypeBot && !string.IsNullOrEmpty(viaBot.Username))
            {
                var hyperlink = new Hyperlink();
                hyperlink.Inlines.Add(new Run {
                    Text = (paragraph.Inlines.Count > 0 ? " via @" : "via @"), FontWeight = FontWeights.Normal
                });
                hyperlink.Inlines.Add(new Run {
                    Text = viaBot.Username
                });
                hyperlink.UnderlineStyle = UnderlineStyle.None;
                hyperlink.Foreground     = light ? new SolidColorBrush(Colors.White) : paragraph.Foreground;
                hyperlink.Click         += (s, args) => ViaBot_Click(message);

                if (paragraph.Inlines.Count > 0 && !forward)
                {
                    paragraph.Inlines.Insert(1, hyperlink);
                }
                else
                {
                    paragraph.Inlines.Add(hyperlink);
                }
            }

            if (paragraph.Inlines.Count > 0)
            {
                if (admin != null && shown && !message.IsOutgoing && message.Delegate != null && message.Delegate.IsAdmin(message.SenderUserId))
                {
                    admin.Visibility = Visibility.Visible;
                }
                else if (admin != null)
                {
                    admin.Visibility = Visibility.Collapsed;
                }

                paragraph.Inlines.Add(new Run {
                    Text = " "
                });
                paragraph.Visibility = Visibility.Visible;
                parent.Visibility    = Visibility.Visible;
            }
            else
            {
                if (admin != null)
                {
                    admin.Visibility = Visibility.Collapsed;
                }

                paragraph.Visibility = Visibility.Collapsed;
                parent.Visibility    = message.ReplyToMessageId != 0 ? Visibility.Visible : Visibility.Collapsed;
            }
        }