public int ProcessDialogs(messages_Dialogs dialogsObject) { List <Dialog> dialogsList; List <Message> messagesList; List <Chat> chatsList; List <User> usersList; switch (dialogsObject.Constructor) { case Constructor.messages_dialogs: dialogsList = ((Messages_dialogsConstructor)dialogsObject).dialogs; messagesList = ((Messages_dialogsConstructor)dialogsObject).messages; chatsList = ((Messages_dialogsConstructor)dialogsObject).chats; usersList = ((Messages_dialogsConstructor)dialogsObject).users; break; case Constructor.messages_dialogsSlice: dialogsList = ((Messages_dialogsSliceConstructor)dialogsObject).dialogs; messagesList = ((Messages_dialogsSliceConstructor)dialogsObject).messages; chatsList = ((Messages_dialogsSliceConstructor)dialogsObject).chats; usersList = ((Messages_dialogsSliceConstructor)dialogsObject).users; break; default: return(0); } logger.info("process dialogs: {0} dialogs, {1} messages, {2} chats, {3} users", dialogsList.Count, messagesList.Count, chatsList.Count, usersList.Count); foreach (var user in usersList) { session.SaveUser(user); } foreach (var chat in chatsList) { session.SaveChat(chat); } Dictionary <int, MessageModel> messagesMap = new Dictionary <int, MessageModel>(); foreach (var message in messagesList) { // FIXME: review var messageModel = new MessageModelDelivered(message); messagesMap.Add(messageModel.Id, messageModel); } foreach (Dialog dialog in dialogsList) { dialogs.Add(new DialogModelPlain(dialog, session, messagesMap)); } return(dialogsList.Count); }
public void ProcessNewMessage(MessageModel messageModel) { logger.info("processing message and adding to observable collection"); if (messageModel is MessageModelDelivered) { MessageModelDelivered newMessage = (MessageModelDelivered)messageModel; var selectedMessages = from message in messages where message is MessageModelDelivered && ((MessageModelDelivered)message).Id == messageModel.Id select message; if (selectedMessages.Any()) { logger.info("message with this ID already in list"); return; } } messages.Add(messageModel); Peer peer = Peer; if (peer.Constructor == Constructor.peerUser) { if (userTyping != null) { userTyping = null; } } else if (peer.Constructor == Constructor.peerChat) { if (chatTyping.Count != 0) { chatTyping.Clear(); } } OnPropertyChanged("PreviewOrAction"); OnPropertyChanged("StatusOrAction"); OnPropertyChanged("MessageDeliveryStateProperty"); }