0.12.19 : better notifications
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 7m2s
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 7m2s
This commit is contained in:
@@ -75,10 +75,74 @@ export default factories.createCoreController(
|
||||
}
|
||||
const message = await strapi
|
||||
.service("api::chat-message.chat-message")
|
||||
.createMessageInConversation(finalConversationId, userId, content, mediaId);
|
||||
.createMessageInConversation(
|
||||
finalConversationId,
|
||||
userId,
|
||||
content,
|
||||
mediaId
|
||||
);
|
||||
|
||||
const currentUser = await strapi.entityService.findOne(
|
||||
"plugin::users-permissions.user",
|
||||
userId,
|
||||
{ populate: { avatar: true } }
|
||||
);
|
||||
|
||||
const conversation = await strapi.entityService.findOne(
|
||||
"api::chat-conversation.chat-conversation",
|
||||
finalConversationId,
|
||||
{ populate: { users: true } }
|
||||
);
|
||||
|
||||
const conversationMembers = (conversation as any)?.users || [];
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
for (const member of conversationMembers) {
|
||||
if (member.id === userId) continue;
|
||||
|
||||
const existingNotifications = await strapi.entityService.findMany(
|
||||
"api::notification.notification",
|
||||
{
|
||||
filters: {
|
||||
$and: [
|
||||
{ type: "messageSent" },
|
||||
{ target_user: member.id },
|
||||
{ floodId: finalConversationId },
|
||||
],
|
||||
},
|
||||
sort: { createdAt: "desc" },
|
||||
}
|
||||
);
|
||||
|
||||
const hasNotificationToday = existingNotifications?.some(
|
||||
(notification: any) => {
|
||||
const notificationDate = new Date(notification.createdAt);
|
||||
notificationDate.setHours(0, 0, 0, 0);
|
||||
return notificationDate.getTime() === today.getTime();
|
||||
}
|
||||
);
|
||||
|
||||
if (!hasNotificationToday) {
|
||||
await strapi
|
||||
.service("api::notification.notification")
|
||||
?.createNotification({
|
||||
message: `Tu as reçu un message de ${currentUser?.name}`,
|
||||
type: "messageSent",
|
||||
target_user: member.id,
|
||||
source: "user",
|
||||
floodId: finalConversationId,
|
||||
payload: {
|
||||
avatar: (currentUser as any)?.avatar?.url,
|
||||
url: `/app/chat/${finalConversationId}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: message,
|
||||
conversationId: finalConversationId,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return ctx.badRequest(`Failed to create message: ${error.message}`);
|
||||
|
||||
@@ -4,26 +4,24 @@
|
||||
"info": {
|
||||
"singularName": "notification",
|
||||
"pluralName": "notifications",
|
||||
"displayName": "Notification"
|
||||
"displayName": "Notification",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": false
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "enumeration",
|
||||
"enum": [
|
||||
"info",
|
||||
"success",
|
||||
"warning",
|
||||
"error"
|
||||
"accountCreation",
|
||||
"friendRequest",
|
||||
"messageSent",
|
||||
"postCreated"
|
||||
]
|
||||
},
|
||||
"target_user": {
|
||||
@@ -35,11 +33,20 @@
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"payload": {
|
||||
"type": "json"
|
||||
},
|
||||
"source": {
|
||||
"type": "enumeration",
|
||||
"enum": [
|
||||
"system",
|
||||
"user",
|
||||
"group",
|
||||
"choral"
|
||||
]
|
||||
},
|
||||
"floodId": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ interface NotificationPayload {
|
||||
type?: "info" | "success" | "warning" | "error";
|
||||
target_user?: number;
|
||||
source?: string;
|
||||
floodId?: number;
|
||||
payload?: Record<string, any>;
|
||||
}
|
||||
|
||||
@@ -14,6 +15,7 @@ interface NotificationEntity {
|
||||
type: string;
|
||||
target_user?: number;
|
||||
source?: string;
|
||||
floodId?: number;
|
||||
payload?: Record<string, any>;
|
||||
read: boolean;
|
||||
createdAt: string;
|
||||
@@ -38,21 +40,21 @@ export default factories.createCoreService(
|
||||
({ strapi }: { strapi }) => ({
|
||||
//Custom service for add notification.
|
||||
async createNotification({
|
||||
title,
|
||||
message,
|
||||
type = "info",
|
||||
target_user,
|
||||
source,
|
||||
floodId,
|
||||
payload,
|
||||
}: NotificationPayload): Promise<NotificationEntity> {
|
||||
const data = { title, message, type, target_user, source, payload };
|
||||
const data = { message, type, target_user, source, floodId, payload };
|
||||
|
||||
const notification = await strapi.entityService.create(
|
||||
"api::notification.notification",
|
||||
{ data }
|
||||
);
|
||||
|
||||
strapi.log.info(`🔔 Notification créée: ${title}`);
|
||||
strapi.log.info(`🔔 Notification créée: ${message}`);
|
||||
return notification;
|
||||
},
|
||||
async addActivity({
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"x-generation-date": "2026-01-16T10:01:51.447Z"
|
||||
"x-generation-date": "2026-01-18T23:07:12.280Z"
|
||||
},
|
||||
"x-strapi-config": {
|
||||
"plugins": [
|
||||
@@ -108357,19 +108357,16 @@
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"info",
|
||||
"success",
|
||||
"warning",
|
||||
"error"
|
||||
"accountCreation",
|
||||
"friendRequest",
|
||||
"messageSent",
|
||||
"postCreated"
|
||||
]
|
||||
},
|
||||
"target_user": {
|
||||
@@ -108386,10 +108383,19 @@
|
||||
"read": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"payload": {},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"system",
|
||||
"user",
|
||||
"group",
|
||||
"choral"
|
||||
]
|
||||
},
|
||||
"floodId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"locale": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -108455,19 +108461,16 @@
|
||||
"documentId": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"info",
|
||||
"success",
|
||||
"warning",
|
||||
"error"
|
||||
"accountCreation",
|
||||
"friendRequest",
|
||||
"messageSent",
|
||||
"postCreated"
|
||||
]
|
||||
},
|
||||
"target_user": {
|
||||
@@ -112116,10 +112119,19 @@
|
||||
"read": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"payload": {},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"system",
|
||||
"user",
|
||||
"group",
|
||||
"choral"
|
||||
]
|
||||
},
|
||||
"floodId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
@@ -112168,19 +112180,16 @@
|
||||
"documentId": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"info",
|
||||
"success",
|
||||
"warning",
|
||||
"error"
|
||||
"accountCreation",
|
||||
"friendRequest",
|
||||
"messageSent",
|
||||
"postCreated"
|
||||
]
|
||||
},
|
||||
"target_user": {
|
||||
@@ -112197,10 +112206,19 @@
|
||||
"read": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"payload": {},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"system",
|
||||
"user",
|
||||
"group",
|
||||
"choral"
|
||||
]
|
||||
},
|
||||
"floodId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
|
||||
Reference in New Issue
Block a user