public Task GetPartyBlockedParticipants(BubbleGroup group, Action <DisaParticipant[]> result) { return(Task.Factory.StartNew(() => { var returnList = new List <DisaParticipant>(); var fullChat = FetchFullChat(group.Address, group.IsExtendedParty); var iChatFull = fullChat.FullChat; var channelFull = iChatFull as ChannelFull; if (channelFull != null) { var kickedParticipants = GetChannelParticipants(channelFull, new ChannelParticipantsKicked()); foreach (var participant in kickedParticipants) { if (participant is ChannelParticipantKicked) { var id = TelegramUtils.GetUserIdFromChannelParticipant(participant); if (id != null) { var user = _dialogs.GetUser(uint.Parse(id)); var name = TelegramUtils.GetUserName(user); returnList.Add(new DisaParticipant(name, id)); } } } } result(returnList.ToArray()); })); }
public Task GetPartyParticipants(BubbleGroup group, Action <DisaParticipant[]> result) { return(Task.Factory.StartNew(() => { var fullChat = FetchFullChat(group.Address, group.IsExtendedParty); var partyParticipants = GetPartyParticipants(fullChat); var resultList = new List <DisaParticipant>(); if (!group.IsExtendedParty) { foreach (var partyParticipant in partyParticipants.ChatParticipants) { var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (id != null) { var name = TelegramUtils.GetUserName(_dialogs.GetUser(uint.Parse(id))); resultList.Add(new DisaParticipant(name, id)); } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); if (id != null) { var name = TelegramUtils.GetUserName(_dialogs.GetUser(uint.Parse(id))); resultList.Add(new DisaParticipant(name, id)); } } } result(resultList.ToArray()); })); }
public Task GetAddressTitle(string address, Action <string> result) { return(Task.Factory.StartNew(() => { result(TelegramUtils.GetUserName(_dialogs.GetUser(uint.Parse(address)))); })); }
private List <Mention> MentionsGetMentions(string token, string address, bool isChannel, TelegramClient optionalClient = null) { // Only handling usernames now if (token != "@") { return(new List <Mention>()); } var fullChat = MentionsFetchFullChat(address, isChannel, optionalClient); var partyParticipants = MentionsGetPartyParticipants(fullChat); var resultList = new List <Mention>(); if (!isChannel) { foreach (var partyParticipant in partyParticipants.ChatParticipants) { var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (id != null) { var user = _dialogs.GetUser(uint.Parse(id)); var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var mention = new Mention { Type = MentionType.Username, Value = username, Name = name, Address = id }; resultList.Add(mention); } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); if (id != null) { var user = _dialogs.GetUser(uint.Parse(id)); var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var mention = new Mention { Type = MentionType.Username, Value = username, Name = name, Address = id }; resultList.Add(mention); } } } return(resultList); }
public Task GetContactsFavorites(Action <List <Contact> > result) { return(Task.Factory.StartNew(async() => { var count = 0; var inputUsers = new List <IInputUser>(); foreach (var bubbleGroup in BubbleGroupManager.SortByMostPopular(this, true)) { var address = bubbleGroup.Address; foreach (var user in _dialogs.Users) { var userId = TelegramUtils.GetUserId(user); if (userId == address) { var inputUser = TelegramUtils.CastUserToInputUser(user); if (inputUser != null) { inputUsers.Add(inputUser); break; } } } count++; if (count > 6) { break; } } if (!inputUsers.Any()) { result(null); } else { using (var client = new FullClientDisposable(this)) { var users = await GetUsers(inputUsers, client.Client); var contacts = users.Select(x => new TelegramContact { Available = TelegramUtils.GetAvailable(x), LastSeen = TelegramUtils.GetLastSeenTime(x), FirstName = TelegramUtils.GetUserName(x), Ids = new List <Contact.ID> { new Contact.ID { Service = this, Id = TelegramUtils.GetUserId(x).ToString(CultureInfo.InvariantCulture) } }, }).OfType <Contact>().OrderBy(x => x.FirstName).ToList(); result(contacts); } } })); }
public Task ConvertContactIdToParticipant(Contact contact, Contact.ID contactId, Action <DisaParticipant> result) { return(Task.Factory.StartNew(() => { var telegramContact = contact as TelegramContact; result(new DisaParticipant(TelegramUtils.GetUserName(telegramContact.User), telegramContact.User.Id.ToString(CultureInfo.InvariantCulture))); })); }
public Task GetContactFromAddress(string address, Action <Contact, Contact.ID> result) { return(Task.Factory.StartNew(async() => { Func <IUser, Tuple <TelegramContact, TelegramContact.ID> > buildContact = user => { var id = new TelegramContact.ID { Service = this, Id = address, }; var contact = new TelegramContact { FirstName = TelegramUtils.GetUserName(user), Ids = new List <Contact.ID> { id }, }; return Tuple.Create(contact, id); }; if (address == null) { return; } var userTuple = _dialogs.GetUser(uint.Parse(address)); if (userTuple != null) { var tuple = buildContact(userTuple); result(tuple.Item1, tuple.Item2); return; } var userContacts = await FetchContacts(); foreach (var userContact in userContacts) { var userId = TelegramUtils.GetUserId(userContact); if (userId == address) { var tuple = buildContact(userContact); result(tuple.Item1, tuple.Item2); return; } } result(null, null); })); }
public Task GetPartyLeaders(BubbleGroup group, Action <DisaParticipant[]> result) { return(Task.Factory.StartNew(() => { var fullChat = FetchFullChat(group.Address, group.IsExtendedParty); var partyParticipants = GetPartyParticipants(fullChat); List <DisaParticipant> resultList = new List <DisaParticipant>(); if (!group.IsExtendedParty) { if (!ChatAdminsEnabled(group.Address)) { foreach (var partyParticipant in partyParticipants.ChatParticipants) { var userId = TelegramUtils.GetUserIdFromParticipant(partyParticipant); var user = _dialogs.GetUser(uint.Parse(userId)); resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId)); } } else { foreach (var partyParticipant in partyParticipants.ChatParticipants) { var userId = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (partyParticipant is ChatParticipantAdmin || partyParticipant is ChatParticipantCreator) { var user = _dialogs.GetUser(uint.Parse(userId)); resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId)); } } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { if ((partyParticipant is ChannelParticipantCreator) || (partyParticipant is ChannelParticipantEditor) || (partyParticipant is ChannelParticipantModerator)) { var userId = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); var user = _dialogs.GetUser(uint.Parse(userId)); resultList.Add(new DisaParticipant(TelegramUtils.GetUserName(user), userId)); } } } result(resultList.ToArray()); })); }
public Task GetContactsFavorites(Action <List <Contact> > result) { return(Task.Factory.StartNew(() => { var count = 0; var users = new List <IUser>(); foreach (var bubbleGroup in BubbleGroupManager.SortByMostPopular(this, true)) { var address = bubbleGroup.Address; var user = _dialogs.GetUser(uint.Parse(address)); if (user != null) { users.Add(user); } count++; if (count > 6) { break; } } if (!users.Any()) { result(null); return; } var contacts = users.Select(x => new TelegramContact { Available = TelegramUtils.GetAvailable(x), LastSeen = TelegramUtils.GetLastSeenTime(x), FirstName = TelegramUtils.GetUserName(x), Ids = new List <Contact.ID> { new Contact.ID { Service = this, Id = TelegramUtils.GetUserId(x).ToString(CultureInfo.InvariantCulture) } }, User = x as User }).OfType <Contact>().OrderBy(x => x.FirstName).ToList(); result(contacts); })); }
public Task ConvertContactIdToParticipant(Contact contact, Contact.ID contactId, Action <DisaParticipant> result) { return(Task.Factory.StartNew(() => { User user = null; if (contact is TelegramContact) { user = (contact as TelegramContact).User; } else if (contact is TelegramBotContact) { user = (contact as TelegramBotContact).User; } result(new DisaParticipant(TelegramUtils.GetUserName(user), user.Id.ToString(CultureInfo.InvariantCulture))); })); }
public Task GetUserInformation(string address, Action <Disa.Framework.UserInformation> result) { return(Task.Factory.StartNew(async() => { foreach (var user in _dialogs.Users) { var userId = TelegramUtils.GetUserId(user); if (userId == address) { using (var client = new FullClientDisposable(this)) { var inputUser = TelegramUtils.CastUserToInputUser(user); var updatedUser = await GetUser(inputUser, client.Client); var name = TelegramUtils.GetUserName(updatedUser); var lastSeen = TelegramUtils.GetLastSeenTime(updatedUser); var presence = TelegramUtils.GetAvailable(updatedUser); var phoneNumber = TelegramUtils.GetUserPhoneNumber(updatedUser); if (string.IsNullOrWhiteSpace(name)) { result(null); //TODO: ensure this doesn't crash Disa return; } result(new UserInformation { Title = name, SubtitleType = string.IsNullOrWhiteSpace(phoneNumber) ? UserInformation.TypeSubtitle.Other : UserInformation.TypeSubtitle.PhoneNumber, Subtitle = string.IsNullOrWhiteSpace(phoneNumber) ? address : TelegramUtils.ConvertTelegramPhoneNumberIntoInternational(phoneNumber), LastSeen = lastSeen, Presence = presence, }); return; } } } result(null); //TODO: ensure this doesn't crash Disa })); }
public Task GetUserInformation(string address, Action <Disa.Framework.UserInformation> result) { return(Task.Factory.StartNew(() => { if (address == null) { return; } var user = _dialogs.GetUser(uint.Parse(address)); using (var client = new FullClientDisposable(this)) { var name = TelegramUtils.GetUserName(user); var lastSeen = TelegramUtils.GetLastSeenTime(user); var presence = TelegramUtils.GetAvailable(user); var phoneNumber = TelegramUtils.GetUserPhoneNumber(user); if (string.IsNullOrWhiteSpace(name)) { result(null); //TODO: ensure this doesn't crash Disa return; } result(new UserInformation { Title = name, SubtitleType = string.IsNullOrWhiteSpace(phoneNumber) ? UserInformation.TypeSubtitle.Other : UserInformation.TypeSubtitle.PhoneNumber, Subtitle = string.IsNullOrWhiteSpace(phoneNumber) ? TelegramUtils.GetUserHandle(user) : TelegramUtils.ConvertTelegramPhoneNumberIntoInternational(phoneNumber), LastSeen = lastSeen, Presence = presence, UserHandle = TelegramUtils.GetUserHandle(user), }); } })); }
private void GetSoloMentions(BubbleGroup group, Action <List <Mention> > result) { using (var client = new FullClientDisposable(this)) { var resultList = new List <Mention>(); var user = _dialogs.GetUser(uint.Parse(group.Address)); var inputUser = TelegramUtils.CastUserToInputUser(user); UserFull userFull = (UserFull) TelegramUtils.RunSynchronously( client.Client.Methods.UsersGetFullUserAsync(new UsersGetFullUserArgs { Id = inputUser })); if (userFull == null) { result(resultList); } var telegramBotInfo = userFull.BotInfo as SharpTelegram.Schema.BotInfo; if (telegramBotInfo != null) { var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var botCommandMention = new Mention { Type = MentionType.BotCommand, BubbleGroupId = group.ID, Value = username, Name = name, Address = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture) }; var disaBotInfo = new Disa.Framework.Bots.BotInfo { Address = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture), Description = telegramBotInfo.Description, Commands = new List <Disa.Framework.Bots.BotCommand>() }; foreach (var c in telegramBotInfo.Commands) { var telegramBotCommand = c as SharpTelegram.Schema.BotCommand; if (telegramBotCommand != null) { disaBotInfo.Commands.Add(new Disa.Framework.Bots.BotCommand { Command = telegramBotCommand.Command, Description = telegramBotCommand.Description }); } } botCommandMention.BotInfo = disaBotInfo; resultList.Add(botCommandMention); } result(resultList); } }
private void GetPartyMentions(BubbleGroup group, Action <List <Mention> > result) { var fullChat = MentionsFetchFullChat(group.Address, group.IsExtendedParty); var partyParticipants = MentionsGetPartyParticipants(fullChat); var resultList = new List <Mention>(); if (!group.IsExtendedParty) { foreach (var partyParticipant in partyParticipants.ChatParticipants) { var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (id != null) { var user = _dialogs.GetUser(uint.Parse(id)); var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var groupUsernameMention = new Mention { Type = MentionType.Username, BubbleGroupId = group.ID, Value = username, Name = name, Address = id }; resultList.Add(groupUsernameMention); } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); if (id != null) { var user = _dialogs.GetUser(uint.Parse(id)); var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var channelUsernameMention = new Mention { Type = MentionType.Username, BubbleGroupId = group.ID, Value = username, Name = name, Address = id }; resultList.Add(channelUsernameMention); } } } var chatFull = fullChat.FullChat as ChatFull; if (chatFull != null) { foreach (var chatFullBotInfo in chatFull.BotInfo) { var telegramBotInfo = chatFullBotInfo as SharpTelegram.Schema.BotInfo; if (telegramBotInfo != null) { var user = _dialogs.GetUser(telegramBotInfo.UserId); var username = TelegramUtils.GetUserHandle(user); var name = TelegramUtils.GetUserName(user); var botCommandMention = new Mention { Type = MentionType.BotCommand, BubbleGroupId = group.ID, Value = username, Name = name, Address = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture) }; var disaBotInfo = new Disa.Framework.Bots.BotInfo { Address = telegramBotInfo.UserId.ToString(CultureInfo.InvariantCulture), Description = telegramBotInfo.Description, Commands = new List <Disa.Framework.Bots.BotCommand>() }; foreach (var c in telegramBotInfo.Commands) { var telegramBotCommand = c as SharpTelegram.Schema.BotCommand; if (telegramBotCommand != null) { disaBotInfo.Commands.Add(new Disa.Framework.Bots.BotCommand { Command = telegramBotCommand.Command, Description = telegramBotCommand.Description }); } } botCommandMention.BotInfo = disaBotInfo; resultList.Add(botCommandMention); } } } result(resultList); }