コード例 #1
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);
             }
         }
     });
 }
コード例 #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
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
 public Task AddPartyParticipant(BubbleGroup group, DisaParticipant participant, Action <AddPartyResult> result)
 {
     return(Task.Factory.StartNew(() =>
     {
         AddPartyParticipant(group, participant)
         .ContinueWith((task) => result(_addPartyResult));
     }));
 }
コード例 #5
0
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
 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
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
 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
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
        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
ファイル: Telegram.cs プロジェクト: harper10/DisaOpenSource
 public override Task GetBubbleGroupPartyParticipantPhoto(DisaParticipant participant, Action<DisaThumbnail> result)
 {
     return Task.Factory.StartNew(() =>
     {
         result(GetThumbnail(participant.Address, false, true));
     });
 }
コード例 #14
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);
                        }
                    }
                }

            });
        }
コード例 #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
ファイル: Telegram.cs プロジェクト: akonsand/DisaOpenSource
 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
ファイル: PartyOptions.cs プロジェクト: mjsir911/Disa-XMPP
        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;
                        }
                    }
                }
            }));
        }