mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 19:21:04 +01:00
Chat notifs (#11832)
* first part of chat notifs * moved default notif to manage page * spec * notifs * delete settings on room delete
This commit is contained in:
committed by
GitHub
parent
f377650161
commit
61f036ce1d
@@ -40,11 +40,13 @@ chatsAPI.create = async function (caller, data) {
|
||||
if (!data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
const isPublic = data.type === 'public';
|
||||
const isAdmin = await user.isAdministrator(caller.uid);
|
||||
if (isPublic && !isAdmin) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
if (!data.uids || !Array.isArray(data.uids)) {
|
||||
throw new Error(`[[error:wrong-parameter-type, uids, ${typeof data.uids}, Array]]`);
|
||||
}
|
||||
@@ -55,6 +57,11 @@ chatsAPI.create = async function (caller, data) {
|
||||
if (isPublic && (!Array.isArray(data.groups) || !data.groups.length)) {
|
||||
throw new Error('[[error:no-groups-selected]]');
|
||||
}
|
||||
|
||||
data.notificationSetting = isPublic ?
|
||||
messaging.notificationSettings.ATMENTION :
|
||||
messaging.notificationSettings.ALLMESSAGES;
|
||||
|
||||
await Promise.all(data.uids.map(async uid => messaging.canMessageUser(caller.uid, uid)));
|
||||
const roomId = await messaging.newRoom(caller.uid, data);
|
||||
|
||||
@@ -108,18 +115,21 @@ chatsAPI.update = async (caller, data) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
const [roomData, isAdmin] = await Promise.all([
|
||||
messaging.getRoomData(data.roomId),
|
||||
user.isAdministrator(caller.uid),
|
||||
]);
|
||||
if (!roomData) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
if (data.hasOwnProperty('groups')) {
|
||||
const [roomData, isAdmin] = await Promise.all([
|
||||
messaging.getRoomData(data.roomId),
|
||||
user.isAdministrator(caller.uid),
|
||||
]);
|
||||
if (!roomData) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
if (roomData.public && isAdmin) {
|
||||
await db.setObjectField(`chat:room:${data.roomId}`, 'groups', JSON.stringify(data.groups));
|
||||
}
|
||||
}
|
||||
if (data.hasOwnProperty('notificationSetting') && isAdmin) {
|
||||
await db.setObjectField(`chat:room:${data.roomId}`, 'notificationSetting', data.notificationSetting);
|
||||
}
|
||||
return messaging.loadRoom(caller.uid, {
|
||||
roomId: data.roomId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user