mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: #8204, separate notification type for group chats
This commit is contained in:
@@ -86,6 +86,7 @@
|
||||
"notificationType_post-edit": "notification",
|
||||
"notificationType_follow": "notification",
|
||||
"notificationType_new-chat": "notification",
|
||||
"notificationType_new-group-chat": "notification",
|
||||
"notificationType_group-invite": "notification",
|
||||
"notificationType_group-request-membership": "notification",
|
||||
"notificationType_mention": "notification",
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
"notificationType_post-edit": "When a post is edited in a topic you are watching",
|
||||
"notificationType_follow": "When someone starts following you",
|
||||
"notificationType_new-chat": "When you receive a chat message",
|
||||
"notificationType_new-group-chat": "When you receive a group chat message",
|
||||
"notificationType_group-invite": "When you receive a group invite",
|
||||
"notificationType_group-request-membership": "When someone requests to join a group you own",
|
||||
"notificationType_new-register": "When someone gets added to registration queue",
|
||||
|
||||
@@ -58,6 +58,9 @@ Settings:
|
||||
notificationType_new-chat:
|
||||
type: string
|
||||
description: Notification type for new chat messages
|
||||
notificationType_new-group-chat:
|
||||
type: string
|
||||
description: Notification type for new group chat messages
|
||||
notificationType_new-reply:
|
||||
type: string
|
||||
description: Notification type for new topic replies
|
||||
|
||||
@@ -57,8 +57,9 @@ module.exports = function (Messaging) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isGroupChat = await Messaging.isGroupChat(roomId);
|
||||
const notification = await notifications.create({
|
||||
type: 'new-chat',
|
||||
type: isGroupChat ? 'new-group-chat' : 'new-chat',
|
||||
subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
|
||||
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
|
||||
bodyLong: messageObj.content,
|
||||
|
||||
@@ -83,15 +83,7 @@ module.exports = function (Messaging) {
|
||||
}
|
||||
|
||||
await db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamps, uids);
|
||||
const [userCount, roomData] = await Promise.all([
|
||||
db.sortedSetCard('chat:room:' + roomId + ':uids'),
|
||||
db.getObject('chat:room:' + roomId),
|
||||
]);
|
||||
|
||||
if (!roomData.hasOwnProperty('groupChat') && userCount > 2) {
|
||||
await db.setObjectField('chat:room:' + roomId, 'groupChat', 1);
|
||||
}
|
||||
|
||||
await updateGroupChatField([roomId]);
|
||||
await Promise.all(uids.map(uid => Messaging.addSystemMessage('user-join', uid, roomId)));
|
||||
};
|
||||
|
||||
@@ -111,6 +103,20 @@ module.exports = function (Messaging) {
|
||||
await Messaging.leaveRoom(uids, roomId);
|
||||
};
|
||||
|
||||
Messaging.isGroupChat = async function (roomId) {
|
||||
return (await Messaging.getRoomData(roomId)).groupChat;
|
||||
};
|
||||
|
||||
async function updateGroupChatField(roomIds) {
|
||||
const userCounts = await db.sortedSetsCard(roomIds.map(roomId => 'chat:room:' + roomId + ':uids'));
|
||||
const groupChats = roomIds.filter((roomId, index) => userCounts[index] > 2);
|
||||
const privateChats = roomIds.filter((roomId, index) => userCounts[index] <= 2);
|
||||
await Promise.all([
|
||||
db.setObjectField(groupChats.map(id => 'chat:room:' + id, 'groupChat', 1)),
|
||||
db.setObjectField(privateChats.map(id => 'chat:room:' + id, 'groupChat', 0)),
|
||||
]);
|
||||
}
|
||||
|
||||
Messaging.leaveRoom = async (uids, roomId) => {
|
||||
const isInRoom = await Promise.all(uids.map(uid => Messaging.isUserInRoom(uid, roomId)));
|
||||
uids = uids.filter((uid, index) => isInRoom[index]);
|
||||
@@ -126,6 +132,7 @@ module.exports = function (Messaging) {
|
||||
|
||||
await Promise.all(uids.map(uid => Messaging.addSystemMessage('user-leave', uid, roomId)));
|
||||
await updateOwner(roomId);
|
||||
await updateGroupChatField([roomId]);
|
||||
};
|
||||
|
||||
Messaging.leaveRooms = async (uid, roomIds) => {
|
||||
@@ -145,6 +152,7 @@ module.exports = function (Messaging) {
|
||||
roomIds.map(roomId => updateOwner(roomId))
|
||||
.concat(roomIds.map(roomId => Messaging.addSystemMessage('user-leave', uid, roomId)))
|
||||
);
|
||||
await updateGroupChatField(roomIds);
|
||||
};
|
||||
|
||||
async function updateOwner(roomId) {
|
||||
|
||||
@@ -25,6 +25,7 @@ Notifications.baseTypes = [
|
||||
'notificationType_post-edit',
|
||||
'notificationType_follow',
|
||||
'notificationType_new-chat',
|
||||
'notificationType_new-group-chat',
|
||||
'notificationType_group-invite',
|
||||
'notificationType_group-request-membership',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user