private Participants GetPartyParticipants(MessagesChatFull fullChat) { if (_participants != null) { return(_participants); } lock (_participantsLock) { if (_participants != null) { return(_participants); } var iChatFull = fullChat.FullChat; var chatFull = iChatFull as ChatFull; var channelFull = iChatFull as ChannelFull; if (chatFull != null) { var chatParticipants = chatFull.Participants as ChatParticipants; if (chatParticipants != null) { DebugPrint("###### Party participants " + ObjectDumper.Dump(chatParticipants)); _participants = new Participants { Type = ParticipantsType.Chat, ChatParticipants = chatParticipants.Participants }; return(_participants); } } if (channelFull != null) { if (channelFull.CanViewParticipants == null) { return(new Participants { Type = ParticipantsType.Channel, ChannelParticipants = new List <IChannelParticipant>() }); } var channelParticipants = GetChannelParticipants(channelFull, new ChannelParticipantsRecent()); var channelAdmins = GetChannelParticipants(channelFull, new ChannelParticipantsAdmins()); var mergedList = channelAdmins.Union(channelParticipants, new ChannelParticipantComparer()).ToList(); DebugPrint("###### Party participants " + ObjectDumper.Dump(channelAdmins)); _participants = new Participants { Type = ParticipantsType.Channel, ChannelParticipants = mergedList }; return(_participants); } } return(null); }
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); } } }
private void DisposeFullChat() { lock (_fullChatLock) { _fullChat = null; GC.Collect(); } lock (_participantsLock) { _participants = null; GC.Collect(); } }
// TODO: Move to TelegramUtils for both // Separate implementation for Mentions - PartyOptions has its own as well private Participants MentionsGetPartyParticipants(MessagesChatFull fullChat) { Participants participants = null; var iChatFull = fullChat.FullChat; var chatFull = iChatFull as ChatFull; var channelFull = iChatFull as ChannelFull; if (chatFull != null) { var chatParticipants = chatFull.Participants as ChatParticipants; if (chatParticipants != null) { participants = new Participants { Type = ParticipantsType.Chat, ChatParticipants = chatParticipants.Participants }; return(participants); } } if (channelFull != null) { if (channelFull.CanViewParticipants == null) { return(new Participants { Type = ParticipantsType.Channel, ChannelParticipants = new List <IChannelParticipant>() }); } var channelParticipants = GetChannelParticipants(channelFull, new ChannelParticipantsRecent()); var channelAdmins = GetChannelParticipants(channelFull, new ChannelParticipantsAdmins()); var mergedList = channelAdmins.Union(channelParticipants, new ChannelParticipantComparer()).ToList(); participants = new Participants { Type = ParticipantsType.Channel, ChannelParticipants = mergedList }; return(participants); } return(null); }
// 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); } }