2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
import { attr, fk, oneToOne } from 'redux-orm';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
import BaseModel from './BaseModel';
|
2019-08-31 04:07:25 +05:00
|
|
|
import ActionTypes from '../constants/ActionTypes';
|
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
export default class extends BaseModel {
|
2019-08-31 04:07:25 +05:00
|
|
|
static modelName = 'Notification';
|
|
|
|
|
|
|
|
|
|
static fields = {
|
|
|
|
|
id: attr(),
|
|
|
|
|
type: attr(),
|
|
|
|
|
data: attr(),
|
|
|
|
|
isRead: attr(),
|
|
|
|
|
userId: fk({
|
|
|
|
|
to: 'User',
|
|
|
|
|
as: 'user',
|
|
|
|
|
relatedName: 'notifications',
|
|
|
|
|
}),
|
2025-05-10 02:09:06 +02:00
|
|
|
creatorUserId: fk({
|
|
|
|
|
to: 'User',
|
|
|
|
|
as: 'creatorUser',
|
|
|
|
|
relatedName: 'createdNotifications',
|
|
|
|
|
}),
|
|
|
|
|
boardId: fk({
|
|
|
|
|
to: 'Board',
|
|
|
|
|
as: 'board',
|
|
|
|
|
relatedName: 'notifications',
|
|
|
|
|
}),
|
2019-08-31 04:07:25 +05:00
|
|
|
cardId: fk({
|
|
|
|
|
to: 'Card',
|
|
|
|
|
as: 'card',
|
|
|
|
|
relatedName: 'notifications',
|
|
|
|
|
}),
|
2025-05-10 02:09:06 +02:00
|
|
|
commentId: oneToOne({
|
|
|
|
|
to: 'Comment',
|
|
|
|
|
as: 'comment',
|
|
|
|
|
}),
|
2022-08-04 13:31:14 +02:00
|
|
|
activityId: oneToOne({
|
|
|
|
|
to: 'Activity',
|
|
|
|
|
as: 'activity',
|
2022-07-29 17:40:18 +02:00
|
|
|
}),
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static reducer({ type, payload }, Notification) {
|
|
|
|
|
switch (type) {
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.LOCATION_CHANGE_HANDLE:
|
2025-05-10 02:09:06 +02:00
|
|
|
case ActionTypes.USER_UPDATE_HANDLE:
|
|
|
|
|
case ActionTypes.PROJECT_UPDATE_HANDLE:
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.PROJECT_MANAGER_CREATE_HANDLE:
|
|
|
|
|
case ActionTypes.BOARD_MEMBERSHIP_CREATE_HANDLE:
|
2025-05-10 02:09:06 +02:00
|
|
|
if (payload.notificationsToDelete) {
|
|
|
|
|
payload.notificationsToDelete.forEach((notification) => {
|
|
|
|
|
Notification.withId(notification.id).delete();
|
2021-06-24 01:05:22 +05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ActionTypes.SOCKET_RECONNECT_HANDLE:
|
|
|
|
|
Notification.all().delete();
|
|
|
|
|
|
|
|
|
|
payload.notifications.forEach((notification) => {
|
|
|
|
|
Notification.upsert(notification);
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
break;
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.CORE_INITIALIZE:
|
2020-03-25 00:15:47 +05:00
|
|
|
payload.notifications.forEach((notification) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
Notification.upsert(notification);
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
break;
|
|
|
|
|
case ActionTypes.ALL_NOTIFICATIONS_DELETE:
|
|
|
|
|
Notification.all().delete();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ActionTypes.ALL_NOTIFICATIONS_DELETE__SUCCESS:
|
|
|
|
|
payload.notifications.forEach((notification) => {
|
|
|
|
|
const notificationModel = Notification.withId(notification.id);
|
|
|
|
|
|
|
|
|
|
if (notificationModel) {
|
|
|
|
|
notificationModel.delete();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
break;
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.NOTIFICATION_CREATE_HANDLE:
|
2019-08-31 04:07:25 +05:00
|
|
|
Notification.upsert(payload.notification);
|
|
|
|
|
|
|
|
|
|
break;
|
2021-06-24 01:05:22 +05:00
|
|
|
case ActionTypes.NOTIFICATION_DELETE:
|
2025-05-10 02:09:06 +02:00
|
|
|
Notification.withId(payload.id).delete();
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ActionTypes.NOTIFICATION_DELETE__SUCCESS:
|
|
|
|
|
case ActionTypes.NOTIFICATION_DELETE_HANDLE: {
|
2019-08-31 04:07:25 +05:00
|
|
|
const notificationModel = Notification.withId(payload.notification.id);
|
|
|
|
|
|
|
|
|
|
if (notificationModel) {
|
2025-05-10 02:09:06 +02:00
|
|
|
notificationModel.delete();
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|