public static Task ChangeChannel(this ServerEventsClient client, string channel, ChatCommandHandler cmdReceiver) { if (cmdReceiver.FullHistory.ContainsKey(channel) && client.Channels.Contains(channel)) { cmdReceiver.ChangeChannel(channel); cmdReceiver.SyncAdapter(); return(Task.CompletedTask); } return(client.SubscribeToChannelsAsync(channel) .Then(t => { cmdReceiver.CurrentChannel = channel; return client.UpdateChatHistory(cmdReceiver); })); }
public static Task UpdateChatHistory(this ServerEventsClient client, ChatCommandHandler cmdReceiver) { return(client.ServiceClient.GetAsync(new GetChatHistory { Channels = client.Channels }).Success(chatHistory => { cmdReceiver.FullHistory = new Dictionary <string, List <ChatMessage> >(); foreach (var channel in client.Channels) { var currentChannel = channel; cmdReceiver.FullHistory.Add(channel, chatHistory.Results .Where(x => x.Channel == currentChannel) .Select(x => x).ToList()); } cmdReceiver.SyncAdapter(); })); }