Fix notification origin id references

This commit is contained in:
Nassim Jahnke 2022-12-29 16:49:11 +01:00
parent 0382de1b77
commit aca6c4a606
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 18 additions and 12 deletions

View File

@ -46,6 +46,11 @@ public class NotificationTable extends Table {
return this.read;
}
/**
* Returns the user id of the user that initiated the notification, if present.
*
* @return user id of the user that initiated the notification
*/
public Long getOriginId() {
return this.originId;
}

View File

@ -95,7 +95,7 @@ public abstract class MemberService<
final RT roleTable = this.handleEditOrRemoval(member, joinable.getId());
this.membersDao.delete(roleTable.getPrincipalId(), roleTable.getUserId());
this.roleService.deleteRole(roleTable);
this.joinableNotificationService.removedFrom(roleTable, joinable);
this.joinableNotificationService.removedFrom(roleTable, joinable, this.getHangarUserId());
this.logMemberRemoval(joinable, "Removed: " + member.getName() + " (" + member.getRole().getTitle() + ")");
}
@ -114,7 +114,7 @@ public abstract class MemberService<
roleTable.setRole(member.getRole());
this.roleService.updateRole(roleTable);
this.joinableNotificationService.roleChanged(roleTable, joinable);
this.joinableNotificationService.roleChanged(roleTable, joinable, this.getHangarUserId());
this.logMemberUpdate(joinable,
"Old Roles: " + member.getName() + " (" + oldTitle + ")",
"New Roles: " + member.getName() + " (" + roleTable.getRole().getTitle() + ")");

View File

@ -73,11 +73,11 @@ public class NotificationService extends HangarComponent {
this.notifyProjectMembers(projectTable.getProjectId(), this.getHangarUserId(), projectTable.getOwnerName(), projectTable.getSlug(), notificationType, message);
}
public NotificationTable notify(final long userId, final @Nullable String action, final @Nullable Long originId, final NotificationType notificationType, final String[] message) {
return this.notificationsDAO.insert(new NotificationTable(userId, action, originId, message, notificationType));
public NotificationTable notify(final long userId, final @Nullable String action, final @Nullable Long originUserId, final NotificationType notificationType, final String[] message) {
return this.notificationsDAO.insert(new NotificationTable(userId, action, originUserId, message, notificationType));
}
public List<NotificationTable> notifyProjectMembers(final long projectId, final @Nullable Long originId,
public List<NotificationTable> notifyProjectMembers(final long projectId, final @Nullable Long originUserId,
final String owner, final String slug, final NotificationType notificationType, final String[] message) {
final List<NotificationTable> notifications = new ArrayList<>();
final List<JoinableMember<ProjectRoleTable>> members = this.hangarProjectsDAO.getProjectMembers(projectId, null, false);
@ -85,7 +85,7 @@ public class NotificationService extends HangarComponent {
notifications.add(new NotificationTable(
member.getUser().getUserId(),
owner + "/" + slug,
originId,
originUserId,
message, notificationType)
);
}
@ -98,7 +98,7 @@ public class NotificationService extends HangarComponent {
notificationTables.add(new NotificationTable(
projectWatcher.getId(),
projectTable.getOwnerName() + "/" + projectTable.getSlug() + "/versions/" + projectVersionTable.getVersionString(),
projectTable.getId(),
this.getHangarUserId(),
new String[]{"notifications.project.newVersion", projectTable.getName(), projectVersionTable.getVersionString()}, NotificationType.NEUTRAL)
);
}
@ -113,7 +113,7 @@ public class NotificationService extends HangarComponent {
notificationTables.add(new NotificationTable(
user.getId(),
projectTable.getOwnerName() + "/" + projectTable.getSlug() + "/versions/" + projectVersionTable.getVersionString(),
projectTable.getId(),
this.getHangarUserId(),
new String[]{partial ? "notifications.project.reviewedPartial" : "notifications.project.reviewed", projectTable.getSlug(), projectVersionTable.getVersionString()},
NotificationType.SUCCESS)
);

View File

@ -13,6 +13,7 @@ import io.papermc.hangar.model.db.roles.ProjectRoleTable;
import io.papermc.hangar.model.internal.user.notifications.NotificationType;
import java.util.Collection;
import java.util.HashSet;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -39,14 +40,14 @@ public abstract class JoinableNotificationService<RT extends ExtendedRoleTable<?
this.notificationsDAO.insert(new NotificationTable(inviteeRoleTable.getUserId(), "notifications", inviterId, new String[]{this.msgPrefix + "transfer", inviterName, joinable.getName()}, NotificationType.INFO));
}
public void removedFrom(final RT removedFromRoleTable, final J joinable) {
public void removedFrom(final RT removedFromRoleTable, final J joinable, final @Nullable Long byUserId) {
final String msgKey = this.msgPrefix + (removedFromRoleTable.isAccepted() ? "removed" : "inviteRescinded");
this.notificationsDAO.insert(new NotificationTable(removedFromRoleTable.getUserId(), null, joinable.getId(),
this.notificationsDAO.insert(new NotificationTable(removedFromRoleTable.getUserId(), null, byUserId,
new String[]{msgKey, removedFromRoleTable.getRole().getTitle(), joinable.getName()}, NotificationType.WARNING));
}
public void roleChanged(final RT changedRoleTable, final J joinable) {
this.notificationsDAO.insert(new NotificationTable(changedRoleTable.getUserId(), null, joinable.getId(),
public void roleChanged(final RT changedRoleTable, final J joinable, final @Nullable Long byUserId) {
this.notificationsDAO.insert(new NotificationTable(changedRoleTable.getUserId(), null, byUserId,
new String[]{this.msgPrefix + "roleChanged", changedRoleTable.getRole().getTitle(), joinable.getName()}, NotificationType.INFO));
}