private List <IChannelParticipant> GetChannelParticipants(ChannelFull channelFull, IChannelParticipantsFilter filter) { var participantsList = new List <IChannelParticipant>(); using (var client = new FullClientDisposable(this)) { uint count = 100; uint offset = 0; var result = (ChannelsChannelParticipants)TelegramUtils.RunSynchronously( client.Client.Methods.ChannelsGetParticipantsAsync(new ChannelsGetParticipantsArgs { Channel = new InputChannel { ChannelId = channelFull.Id, AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(channelFull.Id)) }, Filter = filter, Limit = 100, Offset = offset })); participantsList.AddRange(result.Participants); _dialogs.AddUsers(result.Users); } return(participantsList); }
public Task SignMessages(BubbleGroup group, bool sign, Action <bool> result) { return(Task.Factory.StartNew(() => { using (var client = new FullClientDisposable(this)) { try { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsToggleSignaturesAsync(new ChannelsToggleSignaturesArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Enabled = sign })); SendToResponseDispatcher(response, client.Client); result(true); } catch (Exception e) { DebugPrint("## exception while migrating the chat " + e); result(false); } } })); }
public Task SetPartyDescription(BubbleGroup group, string description, Action <bool> result) { return(Task.Factory.StartNew(() => { if (description != null) { using (var client = new FullClientDisposable(this)) { var edited = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsEditAboutAsync(new ChannelsEditAboutArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, About = description })); if (edited) { result(true); } else { result(false); } } } })); }
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))) } })); SendToResponseDispatcher(update, client.Client); } } })); }
public Task SetPartyName(BubbleGroup group, string name) { return(Task.Factory.StartNew(() => { using (var client = new FullClientDisposable(this)) { if (!group.IsExtendedParty) { var update = TelegramUtils.RunSynchronously( client.Client.Methods.MessagesEditChatTitleAsync(new MessagesEditChatTitleArgs { ChatId = uint.Parse(group.Address), Title = name, })); SendToResponseDispatcher(update, client.Client); } else { var update = TelegramUtils.RunSynchronously( client.Client.Methods.ChannelsEditTitleAsync(new ChannelsEditTitleArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Title = name })); SendToResponseDispatcher(update, client.Client); } } })); }
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); } } })); }
public Task SetPartyAddNewMembersRestriction(BubbleGroup group, PartyOptionsSettingsAddNewMembersRestriction restriction, Action <bool> result) { return(Task.Factory.StartNew(() => { using (var client = new FullClientDisposable(this)) { try { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsToggleInvitesAsync(new ChannelsToggleInvitesArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Enabled = restriction == PartyOptionsSettingsAddNewMembersRestriction.Everyone })); SendToResponseDispatcher(response, client.Client); result(true); } catch (Exception e) { DebugPrint("##### Exeption while setting all members are admins type " + e); result(false); } } })); }
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); } } } })); }
private MessagesChatFull FetchFullChat(string address, bool superGroup) { //Classic check lock check pattern for concurrent access from all the methods if (_fullChat != null) { return(_fullChat); } lock (_fullChatLock) { if (_fullChat != null) { return(_fullChat); } using (var client = new FullClientDisposable(this)) { if (!superGroup) { _fullChat = (MessagesChatFull) TelegramUtils.RunSynchronously( client.Client.Methods.MessagesGetFullChatAsync(new MessagesGetFullChatArgs { ChatId = uint.Parse(address) })); } else { try { _fullChat = (MessagesChatFull) TelegramUtils.RunSynchronously( client.Client.Methods.ChannelsGetFullChannelAsync(new ChannelsGetFullChannelArgs { Channel = new InputChannel { ChannelId = uint.Parse(address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(address))) } })); } catch (Exception e) { DebugPrint(">>>> get full channel exception " + e); } } //DebugPrint("#### fullchat " + ObjectDumper.Dump(_fullChat)); _dialogs.AddUsers(_fullChat.Users); _dialogs.AddChats(_fullChat.Chats); return(_fullChat); } } }
public Task SetPartyPhoto(BubbleGroup group, byte[] bytes, Action <DisaThumbnail> result) { return(Task.Factory.StartNew(() => { //MessagesEditChatPhotoAsync byte[] resizedImage = Platform.GenerateJpegBytes(bytes, 640, 640); var inputFile = UploadPartyImage(resizedImage); using (var client = new FullClientDisposable(this)) { if (!group.IsExtendedParty) { var update = TelegramUtils.RunSynchronously( client.Client.Methods.MessagesEditChatPhotoAsync(new MessagesEditChatPhotoArgs { ChatId = uint.Parse(group.Address), Photo = new InputChatUploadedPhoto { Crop = new InputPhotoCropAuto(), File = inputFile } })); SendToResponseDispatcher(update, client.Client); } else { //ChannelsEditPhoto var update = TelegramUtils.RunSynchronously( client.Client.Methods.ChannelsEditPhotoAsync(new ChannelsEditPhotoArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Photo = new InputChatUploadedPhoto { Crop = new InputPhotoCropAuto(), File = inputFile } })); SendToResponseDispatcher(update, client.Client); } } byte[] disaImage = Platform.GenerateJpegBytes(bytes, 96, 96); var thumbnail = new DisaThumbnail(this, disaImage, GenerateRandomId().ToString()); result(thumbnail); })); }
private IExportedChatInvite ExportChatInvite(BubbleGroup group) { using (var client = new FullClientDisposable(this)) { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsExportInviteAsync(new ChannelsExportInviteArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) } })); return(response); } }
public Task SetPartyType(BubbleGroup group, PartyOptionsSettingsPartyType type, Action <bool> result) { return(Task.Factory.StartNew(() => { try { if (type == PartyOptionsSettingsPartyType.Public) { var randomUserName = RandomString(32); DebugPrint("The random username is " + randomUserName); using (var client = new FullClientDisposable(this)) { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsUpdateUsernameAsync(new SharpTelegram.Schema.ChannelsUpdateUsernameArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Username = randomUserName })); result(response); } } else { using (var client = new FullClientDisposable(this)) { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsUpdateUsernameAsync(new SharpTelegram.Schema.ChannelsUpdateUsernameArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Username = "" })); result(response); } } } catch (Exception e) { DebugPrint("##### Exeption while setting group type " + e); result(false); } })); }
private bool SetChannelUserName(BubbleGroup group, string name) { using (var client = new FullClientDisposable(this)) { var response = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsUpdateUsernameAsync(new ChannelsUpdateUsernameArgs { Channel = new InputChannel { ChannelId = uint.Parse(group.Address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(group.Address))) }, Username = name })); return(response); } }
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); } } } })); }
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 })); } } })); }
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); } } })); }
private void JoinChannelIfLeft(string id) { var channel = _dialogs.GetChat(uint.Parse(id)) as Channel; if (channel != null) { if (channel.Left != null) { using (var client = new FullClientDisposable(this)) { var updates = TelegramUtils.RunSynchronously(client.Client.Methods.ChannelsJoinChannelAsync(new ChannelsJoinChannelArgs { Channel = new InputChannel { ChannelId = uint.Parse(id), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(id))) } })); SendToResponseDispatcher(updates, client.Client); } } } }
// TODO: Move to TelegramUtils for both // Separate implementation for Mentions - PartyOptions has its own as well private MessagesChatFull MentionsFetchFullChat(string address, bool superGroup, TelegramClient optionalClient = null) { using (var client = new OptionalClientDisposable(this, optionalClient)) { MessagesChatFull fullChat = null; if (!superGroup) { fullChat = (MessagesChatFull) TelegramUtils.RunSynchronously( client.Client.Methods.MessagesGetFullChatAsync(new MessagesGetFullChatArgs { ChatId = uint.Parse(address) })); } else { fullChat = (MessagesChatFull) TelegramUtils.RunSynchronously( client.Client.Methods.ChannelsGetFullChannelAsync(new ChannelsGetFullChannelArgs { Channel = new InputChannel { ChannelId = uint.Parse(address), AccessHash = TelegramUtils.GetChannelAccessHash(_dialogs.GetChat(uint.Parse(address))) } })); } _dialogs.AddUsers(fullChat.Users); _dialogs.AddChats(fullChat.Chats); return(fullChat); } }
public Task InviteToChannel(BubbleGroup group, Tuple <Contact, Contact.ID>[] contacts, Action <bool> result) { var addPartyResult = AddPartyResult.Success; return(Task.Factory.StartNew(() => { if (contacts.Length > 0) { var inputUsers = new List <IInputUser>(); var names = new List <string>(); foreach (var contact in contacts) { names.Add(contact.Item1.FullName); IUser user = null; if (contact.Item1 is TelegramContact) { user = (contact.Item1 as TelegramContact).User; } else if (contact.Item1 is TelegramBotContact) { user = (contact.Item1 as TelegramBotContact).User; } var inputUser = TelegramUtils.CastUserToInputUser(user); if (inputUser != null) { inputUsers.Add(inputUser); } } if (inputUsers.Any()) { using (var client = new FullClientDisposable(this)) { 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 = inputUsers })); SendToResponseDispatcher(update, client.Client); } catch (Exception ex) { Utils.DebugPrint("Failed Telegram ChannelsInviteToChannelAsync: " + ex); if (ex.Message.Contains("PEER_FLOOD")) { _addPartyResult = AddPartyResult.Flood; } else { _addPartyResult = AddPartyResult.Error; } return; } } } } })); }
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; } } } })); }