Skip to content

Commit

Permalink
fix: [bug] [BUG] Host space user accepting a single user request to j…
Browse files Browse the repository at this point in the history
…oin a space injects wrong notifications of - EXO-74363 - Meeds-io/meeds#2467 (#4092) (#4103)

Prior to this change, If two users request to join a space, and the
administrator accept only one user, the notifications of both users are
aptaded whith the joined notification. The commit fix this bug by only
insure to update the notification related to the user that was accepted.

(cherry picked from commit 327fdde)
  • Loading branch information
mkrout authored Oct 17, 2024
1 parent 910cd25 commit 2f4f1f5
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public void removePendingUser(SpaceLifeCycleEvent event) {
public void joined(SpaceLifeCycleEvent event) {
Space space = event.getSpace();
String userId = event.getTarget();
updateNotificationsStatus(space, userId, SpaceInvitationPlugin.ID);
updateNotificationsStatus(space, userId, userId, SpaceInvitationPlugin.ID);
String[] managers = space.getManagers();
if (managers != null && managers.length > 0) {
for (String manager : managers) {
updateNotificationsStatus(space, manager, RequestJoinSpacePlugin.ID);
updateNotificationsStatus(space, userId, manager, RequestJoinSpacePlugin.ID);
}
}
}
Expand Down Expand Up @@ -120,19 +120,17 @@ private void removeNotifications(String spaceId, String userId, String pluginId)
}
}

private void updateNotificationsStatus(Space space, String userId, String pluginId) {
WebNotificationFilter webNotificationFilter = new WebNotificationFilter(userId);
private void updateNotificationsStatus(Space space, String from, String to, String pluginId) {
WebNotificationFilter webNotificationFilter = new WebNotificationFilter(to);
webNotificationFilter.setParameter("spaceId", space.getId());
webNotificationFilter.setPluginKey(new PluginKey(pluginId));
List<NotificationInfo> webNotifs = getWebNotificationService().getNotificationInfos(webNotificationFilter, 0, -1);
for (NotificationInfo info : webNotifs) {
if (!info.getTo().equals(userId) ||
!info.isRead() ||
!"accepted".equals(info.getOwnerParameter().get("status"))) {
if (info.getTo().equals(to) && info.getFrom().equals(from) && !"accepted".equals(info.getOwnerParameter().get("status"))) {
//one element has changed, we need to update
info.setTo(userId);

info.setRead(true);
info.setTo(to);
info.setFrom(from);
info.setRead(false);
info.setOwnerParameter(new HashMap<>(info.getOwnerParameter()));
info.getOwnerParameter().put("status", "accepted");
updateNotification(info);
Expand Down

0 comments on commit 2f4f1f5

Please sign in to comment.