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 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); }