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); } } }); }
private IUser GetUser(string id) { lock (_quickUserLock) { try { using (var client = new FullClientDisposable(this)) { var inputUser = new InputUser(); inputUser.UserId = uint.Parse(id); var inputList = new List<IInputUser>(); inputList.Add(inputUser); DebugPrint(">>>> inputlist " + ObjectDumper.Dump(inputList)); var users = TelegramUtils.RunSynchronously( client.Client.Methods.UsersGetUsersAsync(new UsersGetUsersArgs { Id = inputList, })); DebugPrint(">>>> get users response " + ObjectDumper.Dump(users)); var user = users.FirstOrDefault(); return user; } } catch (Exception e) { DebugPrint(">>>>>> exception " + e); return null; } } }
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); } } } }); }
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 })); } } }); }
public Task LeaveParty(BubbleGroup group) { return Task.Factory.StartNew(() => { var inputUser = new InputUser { UserId = Settings.AccountId }; 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.ChannelsLeaveChannelAsync(new ChannelsLeaveChannelArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) } })); } } }); }
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); } } }); }