mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
@@ -48,6 +48,7 @@
|
|||||||
"chat.add-user": "Add User",
|
"chat.add-user": "Add User",
|
||||||
"chat.notification-settings": "Notification Settings",
|
"chat.notification-settings": "Notification Settings",
|
||||||
"chat.default-notification-setting": "Default Notification Setting",
|
"chat.default-notification-setting": "Default Notification Setting",
|
||||||
|
"chat.join-leave-messages": "Join/Leave Messages",
|
||||||
"chat.notification-setting-room-default": "Room Default",
|
"chat.notification-setting-room-default": "Room Default",
|
||||||
"chat.notification-setting-none": "No notifications",
|
"chat.notification-setting-none": "No notifications",
|
||||||
"chat.notification-setting-at-mention-only": "@mention only",
|
"chat.notification-setting-at-mention-only": "@mention only",
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ RoomObject:
|
|||||||
description: Timestamp of when room was created
|
description: Timestamp of when room was created
|
||||||
notificationSetting:
|
notificationSetting:
|
||||||
type: number
|
type: number
|
||||||
|
description: The notification setting for the room, 0 = no notifications, 1 = only mentions, 2 = all messages
|
||||||
|
joinLeaveMessages:
|
||||||
|
type: number
|
||||||
|
description: Whether join/leave messages are enabled in the room
|
||||||
MessageObject:
|
MessageObject:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ get:
|
|||||||
type: array
|
type: array
|
||||||
notificationOptionsIcon:
|
notificationOptionsIcon:
|
||||||
type: string
|
type: string
|
||||||
|
joinLeaveMessages:
|
||||||
|
type: number
|
||||||
messages:
|
messages:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
@@ -360,6 +362,8 @@ get:
|
|||||||
type: string
|
type: string
|
||||||
notificationSetting:
|
notificationSetting:
|
||||||
type: number
|
type: number
|
||||||
|
joinLeaveMessages:
|
||||||
|
type: number
|
||||||
publicRooms:
|
publicRooms:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ put:
|
|||||||
type: number
|
type: number
|
||||||
required: true
|
required: true
|
||||||
description: a valid message id
|
description: a valid message id
|
||||||
example: 5
|
example: 3
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
@@ -92,7 +92,7 @@ delete:
|
|||||||
type: number
|
type: number
|
||||||
required: true
|
required: true
|
||||||
description: a valid message id
|
description: a valid message id
|
||||||
example: 5
|
example: 3
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Message successfully deleted
|
description: Message successfully deleted
|
||||||
@@ -125,7 +125,7 @@ post:
|
|||||||
type: number
|
type: number
|
||||||
required: true
|
required: true
|
||||||
description: a valid message id
|
description: a valid message id
|
||||||
example: 5
|
example: 3
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: message successfully restored
|
description: message successfully restored
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ get:
|
|||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
description: a valid chat message id
|
description: a valid chat message id
|
||||||
example: 5
|
example: 3
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Chat message ip address retrieved
|
description: Chat message ip address retrieved
|
||||||
|
|||||||
@@ -75,12 +75,16 @@ define('forum/chats/manage', [
|
|||||||
|
|
||||||
modal.find('[component="chat/manage/save"]').on('click', () => {
|
modal.find('[component="chat/manage/save"]').on('click', () => {
|
||||||
const notifSettingEl = modal.find('[component="chat/room/notification/setting"]');
|
const notifSettingEl = modal.find('[component="chat/room/notification/setting"]');
|
||||||
|
const joinLeaveMessagesEl = modal.find('[component="chat/room/join-leave-messages"]');
|
||||||
|
|
||||||
api.put(`/chats/${roomId}`, {
|
api.put(`/chats/${roomId}`, {
|
||||||
groups: modal.find('[component="chat/room/groups"]').val(),
|
groups: modal.find('[component="chat/room/groups"]').val(),
|
||||||
notificationSetting: notifSettingEl.val(),
|
notificationSetting: notifSettingEl.val(),
|
||||||
|
joinLeaveMessages: joinLeaveMessagesEl.is(':checked') ? 1 : 0,
|
||||||
}).then((payload) => {
|
}).then((payload) => {
|
||||||
ajaxify.data.groups = payload.groups;
|
ajaxify.data.groups = payload.groups;
|
||||||
ajaxify.data.notificationSetting = payload.notificationSetting;
|
ajaxify.data.notificationSetting = payload.notificationSetting;
|
||||||
|
ajaxify.data.joinLeaveMessages = payload.joinLeaveMessages;
|
||||||
const roomDefaultOption = payload.notificationOptions[0];
|
const roomDefaultOption = payload.notificationOptions[0];
|
||||||
$('[component="chat/notification/setting"] [data-icon]').first().attr(
|
$('[component="chat/notification/setting"] [data-icon]').first().attr(
|
||||||
'data-icon', roomDefaultOption.icon
|
'data-icon', roomDefaultOption.icon
|
||||||
|
|||||||
@@ -162,9 +162,17 @@ chatsAPI.update = async (caller, data) => {
|
|||||||
await db.setObjectField(`chat:room:${data.roomId}`, 'groups', JSON.stringify(data.groups));
|
await db.setObjectField(`chat:room:${data.roomId}`, 'groups', JSON.stringify(data.groups));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.hasOwnProperty('notificationSetting') && isAdmin) {
|
if (isAdmin) {
|
||||||
await db.setObjectField(`chat:room:${data.roomId}`, 'notificationSetting', data.notificationSetting);
|
const updateData = {};
|
||||||
|
if (data.hasOwnProperty('notificationSetting')) {
|
||||||
|
updateData.notificationSetting = data.notificationSetting;
|
||||||
|
}
|
||||||
|
if (data.hasOwnProperty('joinLeaveMessages')) {
|
||||||
|
updateData.joinLeaveMessages = data.joinLeaveMessages;
|
||||||
|
}
|
||||||
|
await db.setObject(`chat:room:${data.roomId}`, updateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadedRoom = await messaging.loadRoom(caller.uid, {
|
const loadedRoom = await messaging.loadRoom(caller.uid, {
|
||||||
roomId: data.roomId,
|
roomId: data.roomId,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const roomUidCache = cacheCreate({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
'roomId', 'timestamp', 'userCount', 'messageCount',
|
'roomId', 'timestamp', 'userCount', 'messageCount', 'joinLeaveMessages',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = function (Messaging) {
|
module.exports = function (Messaging) {
|
||||||
@@ -88,6 +88,7 @@ module.exports = function (Messaging) {
|
|||||||
timestamp: now,
|
timestamp: now,
|
||||||
notificationSetting: data.notificationSetting,
|
notificationSetting: data.notificationSetting,
|
||||||
messageCount: 0,
|
messageCount: 0,
|
||||||
|
joinLeaveMessages: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.hasOwnProperty('roomName') && data.roomName) {
|
if (data.hasOwnProperty('roomName') && data.roomName) {
|
||||||
@@ -280,12 +281,22 @@ module.exports = function (Messaging) {
|
|||||||
async function addUidsToRoom(uids, roomId) {
|
async function addUidsToRoom(uids, roomId) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const timestamps = uids.map(() => now);
|
const timestamps = uids.map(() => now);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetAdd(`chat:room:${roomId}:uids`, timestamps, uids),
|
db.sortedSetAdd(`chat:room:${roomId}:uids`, timestamps, uids),
|
||||||
db.sortedSetAdd(`chat:room:${roomId}:uids:online`, timestamps, uids),
|
db.sortedSetAdd(`chat:room:${roomId}:uids:online`, timestamps, uids),
|
||||||
]);
|
]);
|
||||||
await updateUserCount([roomId]);
|
await updateUserCount([roomId]);
|
||||||
await Promise.all(uids.map(uid => Messaging.addSystemMessage('user-join', uid, roomId)));
|
if (await joinLeaveMessagesEnabled(roomId)) {
|
||||||
|
await Promise.all(
|
||||||
|
uids.map(uid => Messaging.addSystemMessage('user-join', uid, roomId))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function joinLeaveMessagesEnabled(roomId) {
|
||||||
|
const roomData = await Messaging.getRoomData(roomId, ['joinLeaveMessages']);
|
||||||
|
return roomData && roomData.joinLeaveMessages === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Messaging.removeUsersFromRoom = async (uid, uids, roomId) => {
|
Messaging.removeUsersFromRoom = async (uid, uids, roomId) => {
|
||||||
@@ -319,7 +330,9 @@ module.exports = function (Messaging) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Messaging.leaveRoom = async (uids, roomId) => {
|
Messaging.leaveRoom = async (uids, roomId) => {
|
||||||
const isInRoom = await Promise.all(uids.map(uid => Messaging.isUserInRoom(uid, roomId)));
|
const isInRoom = await Promise.all(
|
||||||
|
uids.map(uid => Messaging.isUserInRoom(uid, roomId))
|
||||||
|
);
|
||||||
uids = uids.filter((uid, index) => isInRoom[index]);
|
uids = uids.filter((uid, index) => isInRoom[index]);
|
||||||
|
|
||||||
const keys = uids
|
const keys = uids
|
||||||
@@ -334,8 +347,11 @@ module.exports = function (Messaging) {
|
|||||||
], uids),
|
], uids),
|
||||||
db.sortedSetsRemove(keys, roomId),
|
db.sortedSetsRemove(keys, roomId),
|
||||||
]);
|
]);
|
||||||
|
if (await joinLeaveMessagesEnabled(roomId)) {
|
||||||
await Promise.all(uids.map(uid => Messaging.addSystemMessage('user-leave', uid, roomId)));
|
await Promise.all(
|
||||||
|
uids.map(uid => Messaging.addSystemMessage('user-leave', uid, roomId))
|
||||||
|
);
|
||||||
|
}
|
||||||
await updateOwner(roomId);
|
await updateOwner(roomId);
|
||||||
await updateUserCount([roomId]);
|
await updateUserCount([roomId]);
|
||||||
};
|
};
|
||||||
@@ -357,10 +373,13 @@ module.exports = function (Messaging) {
|
|||||||
], roomIds),
|
], roomIds),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(roomIds.map(async (roomId) => {
|
||||||
roomIds.map(roomId => updateOwner(roomId))
|
await updateOwner(roomId);
|
||||||
.concat(roomIds.map(roomId => Messaging.addSystemMessage('user-leave', uid, roomId)))
|
if (await joinLeaveMessagesEnabled(roomId)) {
|
||||||
);
|
await Messaging.addSystemMessage('user-leave', uid, roomId);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
await updateUserCount(roomIds);
|
await updateUserCount(roomIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="">
|
<div class="">
|
||||||
{{{ if user.isAdmin }}}
|
{{{ if user.isAdmin }}}
|
||||||
<div class="d-flex gap-2 mb-3 align-items-center justify-content-between">
|
<div class="d-flex gap-2 mb-3 align-items-center gap-2">
|
||||||
<label class="form-label text-nowrap mb-0">[[modules:chat.default-notification-setting]]</label>
|
<label class="form-label text-nowrap mb-0">[[modules:chat.default-notification-setting]]</label>
|
||||||
<select component="chat/room/notification/setting" class="form-select" style="width: 200px;">
|
<select component="chat/room/notification/setting" class="form-select" style="width: 200px;">
|
||||||
<option value="1" {{{ if (room.notificationSetting == "1") }}}selected{{{ end }}}>[[modules:chat.notification-setting-none]]</option>
|
<option value="1" {{{ if (room.notificationSetting == "1") }}}selected{{{ end }}}>[[modules:chat.notification-setting-none]]</option>
|
||||||
@@ -8,6 +8,12 @@
|
|||||||
<option value="3" {{{ if (room.notificationSetting == "3") }}}selected{{{ end }}}>[[modules:chat.notification-setting-all-messages]]</option>
|
<option value="3" {{{ if (room.notificationSetting == "3") }}}selected{{{ end }}}>[[modules:chat.notification-setting-all-messages]]</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3 d-flex gap-2 align-items-center">
|
||||||
|
<label class="form-label">[[modules:chat.join-leave-messages]]</label>
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input component="chat/room/join-leave-messages" class="form-check-input" type="checkbox" {{{ if room.joinLeaveMessages }}}checked{{{ end }}} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
{{{ end }}}
|
{{{ end }}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user