Exemple #1
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            UsernamePanel.Visibility = fullInfo.CanSetUsername ? Visibility.Visible : Visibility.Collapsed;

            //GroupStickers.Content = fullInfo.sticker
            GroupStickersPanel.Visibility = fullInfo.CanSetStickerSet ? Visibility.Visible : Visibility.Collapsed;


            ViewModel.About                 = fullInfo.Description;
            ViewModel.InviteLink            = fullInfo.InviteLink;
            ViewModel.IsAllHistoryAvailable = fullInfo.IsAllHistoryAvailable;


            if (fullInfo.StickerSetId == 0 || !fullInfo.CanSetStickerSet)
            {
                return;
            }

            ViewModel.ProtoService.Send(new GetStickerSet(fullInfo.StickerSetId), result =>
            {
                this.BeginOnUIThread(() =>
                {
                    if (result is StickerSet set && ViewModel.Chat?.Id == chat.Id)
                    {
                        GroupStickers.Badge = set.Title;
                    }
                });
            });
Exemple #2
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            ViewModel.InviteLink = fullInfo.InviteLink?.InviteLink;

            if (fullInfo.InviteLink == null && string.IsNullOrEmpty(group.Username))
            {
                ViewModel.ProtoService.Send(new CreateChatInviteLink(chat.Id, string.Empty, 0, 0, false));
            }
        }
Exemple #3
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            Blacklist.Badge         = fullInfo.BannedCount;
            ViewModel.SlowModeDelay = fullInfo.SlowModeDelay;

            SlowmodePanel.Footer = fullInfo.SlowModeDelay > 0
                ? string.Format(Strings.Resources.SlowmodeInfoSelected, fullInfo.SlowModeDelay)
                : Strings.Resources.SlowmodeInfoOff;
        }
Exemple #4
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            ViewModel.InviteLink = fullInfo.InviteLink;

            if (string.IsNullOrEmpty(fullInfo.InviteLink) && string.IsNullOrEmpty(group.Username))
            {
                ViewModel.ProtoService.Send(new GenerateChatInviteLink(chat.Id));
            }
        }
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            ProfileHeader?.UpdateSupergroupFullInfo(chat, group, fullInfo);

            if (MediaFrame.Content is ChatSharedMediaPageBase sharedMedia)
            {
                sharedMedia.Header.UpdateSupergroupFullInfo(chat, group, fullInfo);
            }
        }
Exemple #6
0
        /// <summary>
        /// determines if supergroup is valid and CanGetMembers==true
        /// </summary>
        /// <param name="chatId">supergroup chatId to check</param>
        /// <param name="timeOut">timeout in milliseconds for operations</param>
        /// <returns>supergroup chat instance on valid, null otherwise</returns>
        private async Task <ChatTypeSupergroup> isSuperGroupMembersReachable(long chatId, int timeOut = 30000)
        {
            // gatehring supergroup chat
            var res = await _api.executeCommand(new GetChat(chatId), typeof(Chat), timeOut);

            // check if gathering chat timedout
            if (res.status == Enum.ResponseStatus.TimedOut)
            {
                Logger.Debug("retry isSuperGroupMembersReachable with chatId={0}", chatId);
                return(await isSuperGroupMembersReachable(chatId, timeOut));
            }

            // check if gathering chat failed
            if (res.status == Enum.ResponseStatus.Failed)
            {
                return(null);
            }

            // casting response
            Chat chat = res.obj as Chat;

            // check if chat is supergroup
            if (chat.Type is ChatTypeSupergroup superGroup)
            {
retry:
                // gathering supergroup information
                res = await _api.executeCommand(new GetSupergroupFullInfo(superGroup.SupergroupId), typeof(SupergroupFullInfo), timeOut);

                // check if supergroup information timedout
                if (res.status == Enum.ResponseStatus.TimedOut)
                {
                    Logger.Debug("retry GetSupergroupFullInfo for {0}", superGroup.SupergroupId);
                    goto retry;
                }

                // check if sueprgroup information failed
                if (res.status == Enum.ResponseStatus.Failed)
                {
                    return(null);
                }

                // casting response
                SupergroupFullInfo info = res.obj as SupergroupFullInfo;

                // check if supergroup members are visible
                if (info.CanGetMembers)
                {
                    return(superGroup);
                }
            }

            return(null);
        }
Exemple #7
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            GetEntities(fullInfo.Description);
            DescriptionPanel.Visibility = string.IsNullOrEmpty(fullInfo.Description) ? Visibility.Collapsed : Visibility.Visible;

            Admins.Badge      = fullInfo.AdministratorCount;
            Admins.Visibility = fullInfo.AdministratorCount > 0 ? Visibility.Visible : Visibility.Collapsed;

            Banned.Badge      = fullInfo.BannedCount;
            Banned.Visibility = fullInfo.BannedCount > 0 ? Visibility.Visible : Visibility.Collapsed;

            Restricted.Badge      = fullInfo.RestrictedCount;
            Restricted.Visibility = fullInfo.RestrictedCount > 0 ? Visibility.Visible : Visibility.Collapsed;

            Members.Badge      = fullInfo.MemberCount;
            Members.Visibility = fullInfo.CanGetMembers && group.IsChannel ? Visibility.Visible : Visibility.Collapsed;
        }
        public async void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            SavedStickers.Remove(_groupSet);

            var refresh = true;

            var appData = ApplicationData.Current.LocalSettings.CreateContainer("Channels", ApplicationDataCreateDisposition.Always);

            if (appData.Values.TryGetValue("Stickers" + group.Id, out object stickersObj))
            {
                var stickersId = (long)stickersObj;
                if (stickersId == fullInfo.StickerSetId)
                {
                    refresh = false;
                }
            }

            if (fullInfo.StickerSetId != 0 && refresh)
            {
                if (fullInfo.StickerSetId == _groupSet.Id && chat.Id == _groupSet.ChatId)
                {
                    SavedStickers.Add(_groupSet);
                    return;
                }

                var response = await ProtoService.SendAsync(new GetStickerSet(fullInfo.StickerSetId));

                if (response is StickerSet stickerSet)
                {
                    BeginOnUIThread(() =>
                    {
                        _groupSet.Update(chat.Id, stickerSet);

                        if (_groupSet.Stickers != null && _groupSet.Stickers.Count > 0)
                        {
                            SavedStickers.Add(_groupSet);
                        }
                        else
                        {
                            SavedStickers.Remove(_groupSet);
                        }
                    });
                }
            }
        }
Exemple #9
0
        private async void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            var already = Items.FirstOrDefault(x => x.Id == fullInfo.StickerSetId);

            if (already != null)
            {
                SelectedItem = already;
            }
            else
            {
                var response = await ProtoService.SendAsync(new GetStickerSet(fullInfo.StickerSetId));

                if (response is StickerSet set)
                {
                    SelectedItem = new StickerSetInfo(set.Id, set.Title, set.Name, set.IsInstalled, set.IsArchived, set.IsOfficial, set.IsMasks, set.IsViewed, set.Stickers.Count, set.Stickers);
                }
            }
        }
Exemple #10
0
        private void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            Delegate?.UpdateSupergroupFullInfo(chat, group, fullInfo);

            if (fullInfo.LinkedChatId != 0)
            {
                var linkedChat = CacheService.GetChat(fullInfo.LinkedChatId);
                if (linkedChat != null)
                {
                    Items.ReplaceWith(new[] { linkedChat });
                }
                else
                {
                    LoadSuitableChats();
                }
            }
            else
            {
                LoadSuitableChats();
            }
        }
Exemple #11
0
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            var linkedChat = ViewModel.CacheService.GetChat(fullInfo.LinkedChatId);

            if (linkedChat != null)
            {
                if (group.IsChannel)
                {
                    TextBlockHelper.SetMarkdown(Headline, string.Format(Strings.Resources.DiscussionChannelGroupSetHelp2, linkedChat.Title));
                    LayoutRoot.Footer = Strings.Resources.DiscussionChannelHelp2;
                }
                else
                {
                    TextBlockHelper.SetMarkdown(Headline, string.Format(Strings.Resources.DiscussionGroupHelp, linkedChat.Title));
                    LayoutRoot.Footer = Strings.Resources.DiscussionChannelHelp2;
                }
            }
            else
            {
            }
        }
        public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
        {
            GroupStickersPanel.Visibility = fullInfo.CanSetStickerSet ? Visibility.Visible : Visibility.Collapsed;


            ViewModel.About = fullInfo.Description;
            ViewModel.IsAllHistoryAvailable = fullInfo.IsAllHistoryAvailable;

            ChatType.Visibility = fullInfo.CanSetUsername ? Visibility.Visible : Visibility.Collapsed;
            ChatHistory.Badge   = fullInfo.IsAllHistoryAvailable ? Strings.Resources.ChatHistoryVisible : Strings.Resources.ChatHistoryHidden;

            var linkedChat = ViewModel.CacheService.GetChat(fullInfo.LinkedChatId);

            if (linkedChat != null)
            {
                ChatLinked.Badge = linkedChat.Title;
            }
            else
            {
                ChatLinked.Badge = Strings.Resources.DiscussionInfo;
            }

            Admins.Badge    = fullInfo.AdministratorCount;
            Members.Badge   = fullInfo.MemberCount;
            Blacklist.Badge = fullInfo.BannedCount;

            if (group.CanInviteUsers())
            {
                if (fullInfo.InviteLink == null && string.IsNullOrEmpty(group.Username))
                {
                    InviteLinkPanel.Visibility = Visibility.Collapsed;
                    ViewModel.ProtoService.Send(new CreateChatInviteLink(chat.Id, string.Empty, 0, 0, false));
                }
                else if (string.IsNullOrEmpty(group.Username))
                {
                    InviteLink.Text            = fullInfo.InviteLink?.InviteLink;
                    RevokeLink.Visibility      = Visibility.Visible;
                    InviteLinkPanel.Visibility = Visibility.Visible;
                }
                else
                {
                    InviteLink.Text            = MeUrlPrefixConverter.Convert(ViewModel.CacheService, group.Username);
                    RevokeLink.Visibility      = Visibility.Collapsed;
                    InviteLinkPanel.Visibility = Visibility.Visible;
                }
            }
            else
            {
                InviteLinkPanel.Visibility = Visibility.Collapsed;
            }

            ChatBasicPanel.Visibility = ChatType.Visibility == Visibility.Visible ||
                                        ChatHistory.Visibility == Visibility.Visible ||
                                        ChatLinked.Visibility == Visibility.Visible
                    ? Visibility.Visible
                    : Visibility.Collapsed;

            if (fullInfo.StickerSetId == 0 || !fullInfo.CanSetStickerSet)
            {
                return;
            }

            ViewModel.ProtoService.Send(new GetStickerSet(fullInfo.StickerSetId), result =>
            {
                this.BeginOnUIThread(() =>
                {
                    if (result is StickerSet set && ViewModel.Chat?.Id == chat.Id)
                    {
                        GroupStickers.Badge = set.Title;
                    }
                });
            });
 public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
 {
 }
        private async void SendExecute()
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            var                about      = _about.Format();
            var                title      = _title.Trim();
            string             oldAbout   = null;
            Supergroup         supergroup = null;
            SupergroupFullInfo fullInfo   = null;

            if (chat.Type is ChatTypeSupergroup)
            {
                var item  = ProtoService.GetSupergroup(chat);
                var cache = ProtoService.GetSupergroupFull(chat);

                if (item == null || cache == null)
                {
                    return;
                }

                oldAbout   = cache.Description;
                supergroup = item;
                fullInfo   = cache;

                if (item.IsChannel && _isSignatures != item.SignMessages)
                {
                    var response = await ProtoService.SendAsync(new ToggleSupergroupSignMessages(item.Id, _isSignatures));

                    if (response is Error)
                    {
                        // TODO:
                    }
                }
            }
            else if (chat.Type is ChatTypeBasicGroup basicGroup)
            {
                var item  = ProtoService.GetBasicGroup(basicGroup.BasicGroupId);
                var cache = ProtoService.GetBasicGroupFull(basicGroup.BasicGroupId);

                oldAbout = cache.Description;
            }

            if (!string.Equals(title, chat.Title))
            {
                var response = await ProtoService.SendAsync(new SetChatTitle(chat.Id, title));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (!string.Equals(about, oldAbout))
            {
                var response = await ProtoService.SendAsync(new SetChatDescription(chat.Id, about));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (_photo != null)
            {
                var response = await ProtoService.SendAsync(new SetChatPhoto(chat.Id, await _photo.ToGeneratedAsync()));

                if (response is Error)
                {
                    // TODO:
                }
            }
            else if (_deletePhoto)
            {
                var response = await ProtoService.SendAsync(new SetChatPhoto(chat.Id, new InputFileId(0)));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (_isAllHistoryAvailable && chat.Type is ChatTypeBasicGroup)
            {
                var response = await ProtoService.SendAsync(new UpgradeBasicGroupChatToSupergroupChat(chat.Id));

                if (response is Chat result && result.Type is ChatTypeSupergroup super)
                {
                    chat     = result;
                    fullInfo = await ProtoService.SendAsync(new GetSupergroupFullInfo(super.SupergroupId)) as SupergroupFullInfo;
                }
                else if (response is Error)
                {
                    // TODO:
                }
            }
        private async void SendExecute()
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            var                about      = _about.Format();
            var                title      = _title.Trim();
            string             oldAbout   = null;
            Supergroup         supergroup = null;
            SupergroupFullInfo fullInfo   = null;

            if (chat.Type is ChatTypeSupergroup)
            {
                var item  = ProtoService.GetSupergroup(chat);
                var cache = ProtoService.GetSupergroupFull(chat);

                if (item == null || cache == null)
                {
                    return;
                }

                oldAbout   = cache.Description;
                supergroup = item;
                fullInfo   = cache;

                if (item.IsChannel && _isSignatures != item.SignMessages)
                {
                    var response = await ProtoService.SendAsync(new ToggleSupergroupSignMessages(item.Id, _isSignatures));

                    if (response is Error)
                    {
                        // TODO:
                    }
                }
            }
            else if (chat.Type is ChatTypeBasicGroup basicGroup)
            {
                var item  = ProtoService.GetBasicGroup(basicGroup.BasicGroupId);
                var cache = ProtoService.GetBasicGroupFull(basicGroup.BasicGroupId);

                oldAbout = cache.Description;
            }

            if (!string.Equals(title, chat.Title))
            {
                var response = await ProtoService.SendAsync(new SetChatTitle(chat.Id, title));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (!string.Equals(about, oldAbout))
            {
                var response = await ProtoService.SendAsync(new SetChatDescription(chat.Id, about));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (_photo is StorageVideo media)
            {
                var props = await media.File.Properties.GetVideoPropertiesAsync();

                var duration = media.EditState.TrimStopTime - media.EditState.TrimStartTime;
                if (duration.TotalSeconds > 9)
                {
                    media.EditState.TrimStopTime = media.EditState.TrimStartTime + TimeSpan.FromSeconds(9);
                }

                var conversion = new VideoConversion();
                conversion.Mute          = true;
                conversion.TrimStartTime = media.EditState.TrimStartTime;
                conversion.TrimStopTime  = media.EditState.TrimStopTime;
                conversion.Transcode     = true;
                conversion.Transform     = true;
                //conversion.Rotation = file.EditState.Rotation;
                conversion.OutputSize = new Size(500, 500);
                //conversion.Mirror = transform.Mirror;
                conversion.CropRectangle = new Rect(
                    media.EditState.Rectangle.X * props.Width,
                    media.EditState.Rectangle.Y * props.Height,
                    media.EditState.Rectangle.Width * props.Width,
                    media.EditState.Rectangle.Height * props.Height);

                var rectangle = conversion.CropRectangle;
                rectangle.Width  = Math.Min(conversion.CropRectangle.Width, conversion.CropRectangle.Height);
                rectangle.Height = rectangle.Width;

                conversion.CropRectangle = rectangle;

                var generated = await media.File.ToGeneratedAsync(ConversionType.Transcode, JsonConvert.SerializeObject(conversion));

                var response = await ProtoService.SendAsync(new SetChatPhoto(chat.Id, new InputChatPhotoAnimation(generated, 0)));
            }
            else if (_photo is StoragePhoto photo)
            {
                var response = await ProtoService.SendAsync(new SetChatPhoto(chat.Id, new InputChatPhotoStatic(await photo.File.ToGeneratedAsync())));
            }
            else if (_deletePhoto)
            {
                var response = await ProtoService.SendAsync(new SetChatPhoto(chat.Id, null));

                if (response is Error)
                {
                    // TODO:
                }
            }

            if (_isAllHistoryAvailable && chat.Type is ChatTypeBasicGroup)
            {
                var response = await ProtoService.SendAsync(new UpgradeBasicGroupChatToSupergroupChat(chat.Id));

                if (response is Chat result && result.Type is ChatTypeSupergroup super)
                {
                    chat     = result;
                    fullInfo = await ProtoService.SendAsync(new GetSupergroupFullInfo(super.SupergroupId)) as SupergroupFullInfo;
                }
                else if (response is Error)
                {
                    // TODO:
                }
            }
 public void UpdateSupergroupFullInfo(Chat chat, Supergroup group, SupergroupFullInfo fullInfo)
 {
     Blacklist.Badge = fullInfo.BannedCount;
 }