private async Task <bool> RefreshChannelHelper(int channelId, long accessHash) { // get channel info TLInterfacePackage tl = GetAvailableTLInterface(); Channel channel = await tl.Interface.GetChannelAsync(channelId, accessHash); tl.LastCallTime = DateTime.Now; tl.IsAvailable = true; if (channel != null) { tl = GetAvailableTLInterface(); ChannelFull channelFull = await tl.Interface.GetFullChannelAsync(channel.ChannelId, channel.AccessHash.Value); tl.LastCallTime = DateTime.Now; tl.IsAvailable = true; // update channel db.UpdateChannel(channelId, new MongoChannel { Title = channel.Title, Username = channel.Username, About = channelFull.About, ParticipantsCounts = new List <CountTime>() { new CountTime(channelFull.ParticipantsCount, DateTime.Now) } }); Log(string.Format("Channel '{0}' (@{1}) with {2} members has been refreshed.", channel.Title, channel.Username, channelFull.ParticipantsCount)); return(true); } return(false); }
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); }
private async Task <bool> AddChannelHelper(string username, bool active) { // get channel info TLInterfacePackage tl = GetAvailableTLInterface(); Channel channel = await tl.Interface.GetChannelAsync(username); tl.LastCallTime = DateTime.Now; tl.IsAvailable = true; if (channel != null) { tl = GetAvailableTLInterface(); ChannelFull channelFull = await tl.Interface.GetFullChannelAsync(channel.ChannelId, channel.AccessHash.Value); tl.LastCallTime = DateTime.Now; tl.IsAvailable = true; if (!db.IsChannelAdded(channel.ChannelId)) { // refresh channel on duplicate username if (db.IsChannelAdded(username)) { MongoChannel channelToRefresh = db.GetChannel(username); await RefreshChannelHelper(channelToRefresh.ChannelId, channelToRefresh.AccessHash.Value); } // add channel db.AddChannel(new MongoChannel { ChannelId = channel.ChannelId, AccessHash = channel.AccessHash, Title = channel.Title, Username = channel.Username, About = channelFull.About, ParticipantsCounts = new List <CountTime>() { new CountTime(channelFull.ParticipantsCount, DateTime.Now) }, IsActive = active }); Log(string.Format("Channel '{0}' (@{1}) with {2} members has been added.", channel.Title, channel.Username, channelFull.ParticipantsCount)); return(true); } else { // refresh channel if it already exists await RefreshChannelHelper(channel.ChannelId, channel.AccessHash.Value); } } return(false); }
private void DoChannelFull(string channelName) { ChannelFull?.Invoke(this, new ChannelEventArgs(channelName)); int gameIndex = hostedGames.FindIndex(c => c.ChannelName == channelName); string gameName = null; if (gameIndex > -1) { gameName = hostedGames[gameIndex].ChannelName; } string message; message = string.IsNullOrEmpty(gameName) ? "The selected game is full! " + channelName : string.Format("Cannot join game {0}; it is full!", gameName); MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, message)); }
public void OnChannelFull() { ChannelFull?.Invoke(this, EventArgs.Empty); }