public Task UnblockPartyParticipant(BubbleGroup group, DisaParticipant participant, Action<bool> result)
 {
     return Task.Factory.StartNew(() =>
     {
         using (var client = new FullClientDisposable(this))
         {
             try
             {
                 var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsKickFromChannelAsync(new ChannelsKickFromChannelArgs
                 {
                     Channel = new InputChannel
                     {
                         ChannelId = uint.Parse(group.Address),
                         AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                     },
                     Kicked = false,
                     UserId = new InputUser
                     {
                         UserId = uint.Parse(participant.Address),
                         AccessHash = GetUserAccessHashIfForeign(participant.Address)
                     }
                 }));
                 result(true);
             }
             catch (Exception e)
             {
                 DebugPrint("#### Exception " + e);
                 result(false);
             }
         }
     });
 }
예제 #2
0
 public Task UnblockPartyParticipant(BubbleGroup group, DisaParticipant participant, Action <bool> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         using (var client = new FullClientDisposable(this))
         {
             try
             {
                 var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsKickFromChannelAsync(new ChannelsKickFromChannelArgs
                 {
                     Channel = new InputChannel
                     {
                         ChannelId = uint.Parse(group.Address),
                         AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                     },
                     Kicked = false,
                     UserId = new InputUser
                     {
                         UserId = uint.Parse(participant.Address),
                         AccessHash = GetUserAccessHashIfForeign(participant.Address)
                     }
                 }));
                 result(true);
             }
             catch (Exception e)
             {
                 DebugPrint("#### Exception " + e);
                 result(false);
             }
         }
     }));
 }
예제 #3
0
        public Task DemotePartyParticipantsFromLeader(BubbleGroup group, DisaParticipant participant, Action <DemotePartyParticipantsResult> result)
        {
            return(Task.Factory.StartNew(() =>
            {
                var inputUser = new InputUser
                {
                    UserId = uint.Parse(participant.Address),
                    AccessHash = GetUserAccessHashIfForeign(participant.Address)
                };

                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        if (!ChatAdminsEnabled(group.Address))
                        {
                            result(DemotePartyParticipantsResult.AllMembersAreAdministratorsEnabled);
                            return;
                        }
                        try
                        {
                            TelegramUtils.RunSynchronously(client.Client.Methods.MessagesEditChatAdminAsync(new MessagesEditChatAdminArgs
                            {
                                ChatId = uint.Parse(group.Address),
                                IsAdmin = false,
                                UserId = inputUser,
                            }));
                            result(DemotePartyParticipantsResult.Success);
                        }
                        catch (Exception e)
                        {
                            result(DemotePartyParticipantsResult.Failure);
                        }
                    }
                    else
                    {
                        try
                        {
                            var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsEditAdminAsync(new ChannelsEditAdminArgs
                            {
                                Channel = new InputChannel
                                {
                                    ChannelId = uint.Parse(group.Address),
                                    AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                                },
                                Role = new ChannelRoleEmpty(),
                                UserId = inputUser
                            }));
                            SendToResponseDispatcher(response, client.Client);
                            result(DemotePartyParticipantsResult.Success);
                        }
                        catch (Exception e)
                        {
                            result(DemotePartyParticipantsResult.Failure);
                        }
                    }
                }
            }));
        }
예제 #4
0
 public Task AddPartyParticipant(BubbleGroup group, DisaParticipant participant, Action <AddPartyResult> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         AddPartyParticipant(group, participant)
         .ContinueWith((task) => result(_addPartyResult));
     }));
 }
예제 #5
0
 public Task GetPartyPhoto(BubbleGroup group, DisaParticipant participant, bool preview, Action <DisaThumbnail> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         DisaThumbnail thumbnail;
         if (participant == null)
         {
             thumbnail = GetThumbnail(group.Address, group.IsParty, preview);
         }
         else
         {
             thumbnail = GetThumbnail(participant.Address, false, preview);
         }
         result(thumbnail);
     }));
 }
예제 #6
0
 public Task DeletePartyParticipant(BubbleGroup group, DisaParticipant participant)
 {
     return(Task.Factory.StartNew(() =>
     {
         var inputUser = new InputUser
         {
             UserId = uint.Parse(participant.Address),
             AccessHash = GetUserAccessHashIfForeign(participant.Address)
         };
         using (var client = new FullClientDisposable(this))
         {
             if (!group.IsExtendedParty)
             {
                 var update = TelegramUtils.RunSynchronously(client.Client.Methods.MessagesDeleteChatUserAsync(new MessagesDeleteChatUserArgs
                 {
                     ChatId = uint.Parse(group.Address),
                     UserId = inputUser,
                 }));
                 SendToResponseDispatcher(update, client.Client);
             }
             else
             {
                 try
                 {
                     var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsKickFromChannelAsync(new ChannelsKickFromChannelArgs
                     {
                         Channel = new InputChannel
                         {
                             ChannelId = uint.Parse(group.Address),
                             AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                         },
                         Kicked = true,
                         UserId = inputUser
                     }));
                     SendToResponseDispatcher(update, client.Client);
                 }
                 catch (Exception e)
                 {
                     DebugPrint("Exception " + e);
                 }
             }
         }
     }));
 }
예제 #7
0
        public Task PromotePartyParticipantToLeader(BubbleGroup group, DisaParticipant participant)
        {
            return(Task.Factory.StartNew(() =>
            {
                var inputUser = new InputUser
                {
                    UserId = uint.Parse(participant.Address),
                    AccessHash = GetUserAccessHashIfForeign(participant.Address)
                };

                using (var client = new FullClientDisposable(this))
                {
                    if (!ChatAdminsEnabled(group.Address))
                    {
                        //this condition should ideally never be hit
                        // if chat admins are disabled, everyone is an admin and hence the ui never allows anyone to be promoted to an admin
                    }

                    if (!group.IsExtendedParty)
                    {
                        TelegramUtils.RunSynchronously(client.Client.Methods.MessagesEditChatAdminAsync(new MessagesEditChatAdminArgs
                        {
                            ChatId = uint.Parse(group.Address),
                            IsAdmin = true,
                            UserId = inputUser,
                        }));
                    }
                    else
                    {
                        TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsEditAdminAsync(new ChannelsEditAdminArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Role = new ChannelRoleModerator(),
                            UserId = inputUser
                        }));
                    }
                }
            }));
        }
예제 #8
0
        public Task AddPartyParticipant(BubbleGroup group, DisaParticipant participant)
        {
            var inputUser = new InputUser
            {
                UserId     = uint.Parse(participant.Address),
                AccessHash = GetUserAccessHashIfForeign(participant.Address)
            };

            return(Task.Factory.StartNew(() =>
            {
                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        var update = TelegramUtils.RunSynchronously(client.Client.Methods.MessagesAddChatUserAsync(new MessagesAddChatUserArgs
                        {
                            UserId = inputUser,
                            ChatId = uint.Parse(group.Address),
                            FwdLimit = 0
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                    else
                    {
                        var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsInviteToChannelAsync(new ChannelsInviteToChannelArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Users = new List <IInputUser>
                            {
                                inputUser
                            }
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                }
            }));
        }
예제 #9
0
        public Task AddPartyParticipant(BubbleGroup group, DisaParticipant participant)
        {
            var inputUser = new InputUser { UserId = uint.Parse(participant.Address) };
            return Task.Factory.StartNew(() =>
            {
                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        var update = TelegramUtils.RunSynchronously(client.Client.Methods.MessagesAddChatUserAsync(new MessagesAddChatUserArgs
                        {
                            UserId = inputUser,
                            ChatId = uint.Parse(group.Address),
                            FwdLimit = 0
                        }));
                        SendToResponseDispatcher(update, client.Client);
                    }
                    else
                    {
                        var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsInviteToChannelAsync(new ChannelsInviteToChannelArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Users = new List<IInputUser>
                            {
                                inputUser
                            }
                        }));
                        SendToResponseDispatcher(update, client.Client);

                    }
                }
            });
        }
예제 #10
0
 public Task DeletePartyParticipant(BubbleGroup group, DisaParticipant participant)
 {
     return Task.Factory.StartNew(() =>
     {
         var inputUser = new InputUser {UserId = uint.Parse(participant.Address)};
         using (var client = new FullClientDisposable(this))
         {
             if (!group.IsExtendedParty)
             {
                 var update = TelegramUtils.RunSynchronously(client.Client.Methods.MessagesDeleteChatUserAsync(new MessagesDeleteChatUserArgs
                 {
                     ChatId = uint.Parse(group.Address),
                     UserId = inputUser,
                 }));
                 SendToResponseDispatcher(update, client.Client);
             }
             else
             {
                 var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsKickFromChannelAsync(new ChannelsKickFromChannelArgs
                 {
                     Channel = new InputChannel
                     {
                         ChannelId = uint.Parse(group.Address),
                         AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                     },
                     Kicked = true,
                     UserId = inputUser
                 }));
                 SendToResponseDispatcher(update, client.Client);
             }
         }
     });
 }
예제 #11
0
 public Task GetPartyPhoto(BubbleGroup group, DisaParticipant participant, bool preview, Action<DisaThumbnail> result)
 {
     return Task.Factory.StartNew(() =>
     {
         DisaThumbnail thumbnail;
         if (participant == null)
         {
             thumbnail = GetThumbnail(group.Address, group.IsParty, preview);
         }
         else
         {
             thumbnail = GetThumbnail(participant.Address, false, preview);
         }
         result(thumbnail);
     });
 }
예제 #12
0
 public override Task GetBubbleGroupPartyParticipantPhoto(DisaParticipant participant, Action<DisaThumbnail> result)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 public override Task GetBubbleGroupPartyParticipantPhoto(DisaParticipant participant, Action<DisaThumbnail> result)
 {
     return Task.Factory.StartNew(() =>
     {
         result(GetThumbnail(participant.Address, false, true));
     });
 }
        public Task DemotePartyParticipantsFromLeader(BubbleGroup group, DisaParticipant participant, Action<DemotePartyParticipantsResult> result)
        {
            return Task.Factory.StartNew(() =>
            {
                var inputUser = new InputUser
                {
                    UserId = uint.Parse(participant.Address),
                    AccessHash = GetUserAccessHashIfForeign(participant.Address)
                };

                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        if (!ChatAdminsEnabled(group.Address))
                        {
                            result(DemotePartyParticipantsResult.AllMembersAreAdministratorsEnabled);
                            return;
                        }
                        try
                        {
                            TelegramUtils.RunSynchronously(client.Client.Methods.MessagesEditChatAdminAsync(new MessagesEditChatAdminArgs
                            {
                                ChatId = uint.Parse(group.Address),
                                IsAdmin = false,
                                UserId = inputUser,
                            }));
                            result(DemotePartyParticipantsResult.Success);
                        }
                        catch (Exception e)
                        {
                            result(DemotePartyParticipantsResult.Failure);
                        }
                    }
                    else
                    {
                        try
                        {
                            var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsEditAdminAsync(new ChannelsEditAdminArgs
                            {
                                Channel = new InputChannel
                                {
                                    ChannelId = uint.Parse(group.Address),
                                    AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                                },
                                Role = new ChannelRoleEmpty(),
                                UserId = inputUser
                            }));
                            SendToResponseDispatcher(response, client.Client);
                            result(DemotePartyParticipantsResult.Success);
                        }
                        catch (Exception e)
                        {
                            result(DemotePartyParticipantsResult.Failure);
                        }
                    }
                }

            });
        }
예제 #15
0
        public Task PromotePartyParticipantToLeader(BubbleGroup group, DisaParticipant participant)
        {
            return Task.Factory.StartNew(() =>
            {
                var inputUser = new InputUser {UserId = uint.Parse(participant.Address)};

                using (var client = new FullClientDisposable(this))
                {
                    if (!ChatAdminsEnabled(group.Address))
                    {
                        //this condition should ideally never be hit
                        // if chat admins are disabled, everyone is an admin and hence the ui never allows anyone to be promoted to an admin
                    }

                    if (!group.IsExtendedParty)
                    {
                        TelegramUtils.RunSynchronously(client.Client.Methods.MessagesEditChatAdminAsync(new MessagesEditChatAdminArgs
                        {
                            ChatId = uint.Parse(group.Address),
                            IsAdmin = true,
                            UserId = inputUser,
                        }));
                    }
                    else
                    {
                        TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsEditAdminAsync(new ChannelsEditAdminArgs
                        {
                            Channel = new InputChannel
                            {
                                ChannelId = uint.Parse(group.Address),
                                AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                            },
                            Role = new ChannelRoleModerator(),
                            UserId = inputUser
                        }));

                    }
                }

            });
        }
예제 #16
0
 public override Task GetBubbleGroupPartyParticipantPhoto(DisaParticipant participant, Action<DisaThumbnail> result)
 {
     return Task.Factory.StartNew(() =>
     {
         //TODO: results from partyparticipants need to be cached
         // GetThumbnails should then search those as well,
         // because _dialog.Users does not contain all users in participant list
         result(GetThumbnail(participant.Address, false, true));
     });
 }
예제 #17
0
 public override Task GetBubbleGroupPartyParticipantPhoto(DisaParticipant participant, Action <DisaThumbnail> result)
 {
     throw new NotImplementedException();
 }
예제 #18
0
        public Task AddPartyParticipant(BubbleGroup group, DisaParticipant participant)
        {
            _addPartyResult = AddPartyResult.Success;

            var inputUser = new InputUser
            {
                UserId     = uint.Parse(participant.Address),
                AccessHash = GetUserAccessHashIfForeign(participant.Address)
            };

            return(Task.Factory.StartNew(() =>
            {
                var user = _dialogs.GetUser(uint.Parse(participant.Address)) as User;
                if (user.BotNochats != null)
                {
                    _addPartyResult = AddPartyResult.BotNoChat;
                    return;
                }

                using (var client = new FullClientDisposable(this))
                {
                    if (!group.IsExtendedParty)
                    {
                        try
                        {
                            var update = TelegramUtils.RunSynchronously(client.Client.Methods.MessagesAddChatUserAsync(new MessagesAddChatUserArgs
                            {
                                UserId = inputUser,
                                ChatId = uint.Parse(group.Address),
                                FwdLimit = 0
                            }));
                            SendToResponseDispatcher(update, client.Client);
                        }
                        catch (Exception ex)
                        {
                            Utils.DebugPrint("Failed Telegram MessagesAddChatUserAsync: " + ex.Message);

                            if (ex.Message.Contains("PEER_FLOOD"))
                            {
                                _addPartyResult = AddPartyResult.Flood;
                            }
                            else
                            {
                                _addPartyResult = AddPartyResult.Error;
                            }
                            return;
                        }
                    }
                    else
                    {
                        try
                        {
                            var update = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsInviteToChannelAsync(new ChannelsInviteToChannelArgs
                            {
                                Channel = new InputChannel
                                {
                                    ChannelId = uint.Parse(group.Address),
                                    AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address)))
                                },
                                Users = new List <IInputUser>
                                {
                                    inputUser
                                }
                            }));
                            SendToResponseDispatcher(update, client.Client);
                        }
                        catch (Exception ex)
                        {
                            Utils.DebugPrint("Failed Telegram ChannelsInviteToChannelAsync: " + ex.Message);

                            if (ex.Message.Contains("PEER_FLOOD"))
                            {
                                _addPartyResult = AddPartyResult.Flood;
                            }
                            else
                            {
                                _addPartyResult = AddPartyResult.Error;
                            }
                            return;
                        }
                    }
                }
            }));
        }