From c2e7acf0e3294e8a9924f11ecf8d2523845343ea Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 3 Sep 2024 15:57:58 -0400 Subject: [PATCH] updates --- protocol/messenger.go | 76 +++++++++++++---------- protocol/messenger_pairing_and_syncing.go | 17 +---- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/protocol/messenger.go b/protocol/messenger.go index 35a5ecce4..f4ebfd116 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -3639,6 +3639,30 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte return m.saveDataAndPrepareResponse(messageState) } +func (m *Messenger) deleteNotification(response *MessengerResponse, installationID string) error { + notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(installationID)) + if err != nil { + return err + } + + if notification != nil { + updatedAt := m.GetCurrentTimeInMillis() + notification.UpdatedAt = updatedAt + notification.Deleted = true + // we shouldn't sync deleted notification here, + // as the same user on different devices will receive the same message(CommunityCancelRequestToJoin) ? + err = m.persistence.DeleteActivityCenterNotificationByID(types.FromHex(installationID), updatedAt) + if err != nil { + m.logger.Error("failed to delete notification from Activity Center", zap.Error(err)) + return err + } + + // sending signal to client to remove the activity center notification from UI + response.AddActivityCenterNotification(notification) + } + return nil +} + func (m *Messenger) saveDataAndPrepareResponse(messageState *ReceivedMessageState) (*MessengerResponse, error) { var err error var contactsToSave []*Contact @@ -3677,46 +3701,32 @@ func (m *Messenger) saveDataAndPrepareResponse(messageState *ReceivedMessageStat return false } } + fmt.Println("MODIFIED INSTALLATION") if installation.Enabled { - // // Delete AC notif since the installation is now enabled - notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(id)) + fmt.Println("NOW ENABLED INSTALLATION") + // Delete AC notif since the installation is now enabled + err = m.deleteNotification(messageState.Response, id) if err != nil { + m.logger.Error("error deleting notification", zap.Error(err)) return false } - - if notification != nil { - updatedAt := m.GetCurrentTimeInMillis() - notification.UpdatedAt = updatedAt - notification.Deleted = true - // we shouldn't sync deleted notification here, - // as the same user on different devices will receive the same message(CommunityCancelRequestToJoin) ? - err = m.persistence.DeleteActivityCenterNotificationByID(types.FromHex(id), updatedAt) - if err != nil { - m.logger.Error("failed to delete notification from Activity Center", zap.Error(err)) - return false - } - - // sending signal to client to remove the activity center notification from UI - messageState.Response.AddActivityCenterNotification(notification) - } - } else { + } else if id != m.installationID { + fmt.Println("ADD NOTIFICATION") // Add activity center notification when we receive a new installation - if id != m.installationID { - notification := &ActivityCenterNotification{ - ID: types.FromHex(id), - Type: ActivityCenterNotificationTypeNewInstallationReceived, - InstallationID: id, - Timestamp: m.getTimesource().GetCurrentTime(), - Read: false, - Deleted: false, - UpdatedAt: m.GetCurrentTimeInMillis(), - } + notification := &ActivityCenterNotification{ + ID: types.FromHex(id), + Type: ActivityCenterNotificationTypeNewInstallationReceived, + InstallationID: id, + Timestamp: m.getTimesource().GetCurrentTime(), + Read: false, + Deleted: false, + UpdatedAt: m.GetCurrentTimeInMillis(), + } - err = m.addActivityCenterNotification(messageState.Response, notification, nil) - if err != nil { - return false - } + err = m.addActivityCenterNotification(messageState.Response, notification, nil) + if err != nil { + return false } } diff --git a/protocol/messenger_pairing_and_syncing.go b/protocol/messenger_pairing_and_syncing.go index 2602bbca6..702e4593b 100644 --- a/protocol/messenger_pairing_and_syncing.go +++ b/protocol/messenger_pairing_and_syncing.go @@ -35,26 +35,11 @@ func (m *Messenger) EnableInstallationAndSync(request *requests.EnableInstallati } // Delete AC notif - notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(request.InstallationID)) + err = m.deleteNotification(response, request.InstallationID) if err != nil { return nil, err } - if notification != nil { - updatedAt := m.GetCurrentTimeInMillis() - notification.UpdatedAt = updatedAt - notification.Deleted = true - // we shouldn't sync deleted notification here, - // as the same user on different devices will receive the same message(CommunityCancelRequestToJoin) ? - err = m.persistence.DeleteActivityCenterNotificationByID(types.FromHex(request.InstallationID), updatedAt) - if err != nil { - m.logger.Error("failed to delete notification from Activity Center", zap.Error(err)) - return nil, err - } - - // sending signal to client to remove the activity center notification from UI - response.AddActivityCenterNotification(notification) - } return response, nil }