fix(ActivityCenterNotification)_: update pending state of request to join ActivityCenterNotification when member was joined (#5242)

This commit is contained in:
Mykhailo Prakhov 2024-05-28 17:02:30 +02:00 committed by GitHub
parent dd7b3d1af8
commit 3cae2e06f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 23 deletions

View File

@ -1049,6 +1049,26 @@ func (m *Messenger) joinCommunity(ctx context.Context, communityID types.HexByte
Image: "",
}
response.AddNotification(joinedNotification)
// Activity Center notification
requestID := communities.CalculateRequestID(common.PubkeyToHex(&m.identity.PublicKey), communityID)
notification, err := m.persistence.GetActivityCenterNotificationByID(requestID)
if err != nil {
return nil, err
}
if notification != nil && notification.MembershipStatus != ActivityCenterMembershipStatusAccepted {
notification.MembershipStatus = ActivityCenterMembershipStatusAccepted
notification.Read = false
notification.Deleted = false
notification.UpdatedAt = m.GetCurrentTimeInMillis()
err = m.addActivityCenterNotification(response, notification, nil)
if err != nil {
m.logger.Error("failed to update request to join accepted notification", zap.Error(err))
return nil, err
}
}
}
return response, nil

View File

@ -1730,29 +1730,6 @@ func (m *Messenger) HandleCommunityRequestToJoinResponse(state *ReceivedMessageS
}
}
// Activity Center notification
requestID := communities.CalculateRequestID(common.PubkeyToHex(&m.identity.PublicKey), requestToJoinResponseProto.CommunityId)
notification, err := m.persistence.GetActivityCenterNotificationByID(requestID)
if err != nil {
return err
}
if notification != nil {
if requestToJoinResponseProto.Accepted {
notification.MembershipStatus = ActivityCenterMembershipStatusAccepted
notification.Read = false
notification.Deleted = false
} else {
notification.MembershipStatus = ActivityCenterMembershipStatusDeclined
}
notification.UpdatedAt = m.GetCurrentTimeInMillis()
err = m.addActivityCenterNotification(state.Response, notification, nil)
if err != nil {
m.logger.Error("failed to update notification", zap.Error(err))
return err
}
}
return nil
}