private bool IsPartOfParty(Participants partyParticipants) { if (partyParticipants.Type == ParticipantsType.Chat) { foreach (var partyParticipant in partyParticipants.ChatParticipants) { string participantAddress = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (participantAddress == Settings.AccountId.ToString(CultureInfo.InvariantCulture)) { return(true); } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { string participantAddress = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); if (participantAddress == Settings.AccountId.ToString(CultureInfo.InvariantCulture)) { return(true); } } } return(false); }
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 bool Equals(IChannelParticipant x, IChannelParticipant y) { var userIdX = TelegramUtils.GetUserIdFromChannelParticipant(x); var userIdY = TelegramUtils.GetUserIdFromChannelParticipant(y); return(userIdX == userIdY); }
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 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()); })); }
private bool IsAdmin(string address, bool isSuperGroup) { var fullChat = FetchFullChat(address, isSuperGroup); var partyParticipants = GetPartyParticipants(fullChat); if (!isSuperGroup) { if (!ChatAdminsEnabled(address)) { return(true); } foreach (var partyParticipant in partyParticipants.ChatParticipants) { var id = TelegramUtils.GetUserIdFromParticipant(partyParticipant); if (id == Settings.AccountId.ToString(CultureInfo.InvariantCulture)) { if ((partyParticipant is ChatParticipantAdmin) || (partyParticipant is ChatParticipantCreator)) { return(true); } } } } else { foreach (var partyParticipant in partyParticipants.ChannelParticipants) { var id = TelegramUtils.GetUserIdFromChannelParticipant(partyParticipant); if (id == Settings.AccountId.ToString(CultureInfo.InvariantCulture)) { if ((partyParticipant is ChannelParticipantCreator) || (partyParticipant is ChannelParticipantEditor) || (partyParticipant is ChannelParticipantModerator)) { return(true); } } } } return(false); }
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); }
public int GetHashCode(IChannelParticipant obj) { return(int.Parse(TelegramUtils.GetUserIdFromChannelParticipant(obj))); }