private void RefreshMessages(ClientGuard client, RoomRefreshedEventArgs e) { var room = client.Chat.GetRoom(Name); if (e.RemovedMessages != null && e.RemovedMessages.Count > 0) { for (int i = Messages.Count - 1; i >= 0; i--) { var message = Messages[i]; if (e.RemovedMessages.Contains(message.MessageId)) { Messages.RemoveAt(i); } message.Dispose(); } } if (e.AddedMessages != null && e.AddedMessages.Count > 0) { foreach (var messageId in e.AddedMessages) { var message = room.GetMessage(messageId); AddMessage(message.Id, message.Time, message.Owner, message.Text); } } }
protected override void OnRun(MessageContent content, CommandArgs args) { if (content.Room == null) { throw new ArgumentNullException("content.Room"); } UpdateMessagesResult messagesResult; using (var client = ClientModel.Get()) { var chat = client.Chat; var room = chat.GetRoom(content.Room.Name); AddUsers(chat, content.Users); UpdateRoomFiles(room, content.Room); messagesResult = UpdateRoomMessages(room, content.Room); var removedUsers = UpdateRoomUsers(room, content.Room); if (room.Name == ServerChat.MainRoomName) { RemoveUsers(chat, removedUsers); } } var roomArgs = new RoomRefreshedEventArgs(content.Room.Name, messagesResult.Added, messagesResult.Removed); ClientModel.Notifier.RoomRefreshed(roomArgs); }
private void ClientRoomRefreshed(RoomRefreshedEventArgs e) { using (var client = ClientModel.Get()) { if (e.RoomName == Name) { RefreshUsers(client); RefreshMessages(client, e); } if (e.RoomName == ServerChat.MainRoomName) { RefreshReceivers(client); } } }