private void SyncCompletedCallback(MatrixSyncResult matrixSyncResult, bool initSync) { if (matrixSyncResult != null) { if (!initSync) { // raise notifications for messages closed room-windows foreach (KeyValuePair <string, MatrixSyncResultTimelineWrapper> messagesForRoomID in matrixSyncResult.rooms.join) { Console.WriteLine("syncCompletedCallback()"); string roomID = messagesForRoomID.Key; bool skip = false; foreach (Form form in Application.OpenForms) { if (form is Chat) { Chat chat = (Chat)form; if (chat.MatrixRoom.roomID == messagesForRoomID.Key) { // skip notifcation because window is open skip = true; break; } } } if (skip) { continue; } MatrixSyncResultTimelineWrapper wrapper = messagesForRoomID.Value; foreach (MatrixSyncResultEvents events in wrapper.timeline.events) { string sender = String.Format("{0}", Businesslogic.MatrixUsernameToShortUsername(events.sender)); int timeout = 3000; string message = ""; if (events.content.msgtype == "m.text") { if (events.content.format == "org.matrix.custom.html") { } else { timeout = calcTimeoutFromWords(events.content.body); message = events.content.body; } } if (events.content.msgtype == "m.image") { message = "new image received"; } Notification n = new Notification(timeout, sender, message); // todo: loop through matrixrooms in businesslogic and resolve there. note: Businesslogic.Instance.roomCache does not contain MatrixRooms foreach (MatrixRoom m in matrixRooms) { if (m.roomID == roomID) { //found n.Tag = m; break; } } n.NotificationClickedEvent += NotificationClickedCallback; // todo: howto/when unsubscribe? n.Show(); } } } // show messages (in chat history) in openend room-windows foreach (Form form in Application.OpenForms) { if (form is Chat) { Chat chat = (Chat)form; Console.WriteLine(chat.MatrixRoom.roomID); foreach (ChatMessage chatMessage in Businesslogic.Instance.chatMessages) { if (chat.MatrixRoom.roomID == chatMessage.RoomID && !chatMessage.Displayed) { chatMessage.Displayed = true; Console.WriteLine(String.Format("displaying message from {0} for room {1}: {2}", chatMessage.Sender, chat.MatrixRoom.roomID, chatMessage.Message)); //unencrypted chat.processIncomingChatMessage(chatMessage.Sender, chatMessage.Message); } } } } } Businesslogic.Instance.sync(); }
private void SyncCompletedCallback(MatrixSyncResult matrixSyncResult) { //Thread.Sleep(3000); Businesslogic.Instance.messagesAsync(MatrixRoom.roomID, matrixSyncResult.next_batch); }