mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-03 13:19:51 +01:00
feat: closes #13203, make users room owners on private chats
This commit is contained in:
@@ -105,11 +105,15 @@ module.exports = function (Messaging) {
|
||||
await Promise.all([
|
||||
db.setObject(`chat:room:${roomId}`, room),
|
||||
db.sortedSetAdd('chat:rooms', now, roomId),
|
||||
db.sortedSetAdd(`chat:room:${roomId}:owners`, now, uid),
|
||||
db.sortedSetsAdd([
|
||||
`chat:room:${roomId}:uids`,
|
||||
`chat:room:${roomId}:uids:online`,
|
||||
], now, uid),
|
||||
db.sortedSetAddBulk([
|
||||
[`chat:room:${roomId}:uids`, now, uid],
|
||||
[`chat:room:${roomId}:uids:online`, now, uid],
|
||||
...(
|
||||
isPublic ?
|
||||
[`chat:room:${roomId}:owners`, now, uid] :
|
||||
[uid].concat(data.uids).map(uid => ([`chat:room:${roomId}:owners`, now, uid]))
|
||||
),
|
||||
]),
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
|
||||
@@ -15,7 +15,6 @@ const Messaging = require('../src/messaging');
|
||||
const api = require('../src/api');
|
||||
const helpers = require('./helpers');
|
||||
const request = require('../src/request');
|
||||
const utils = require('../src/utils');
|
||||
const translator = require('../src/translator');
|
||||
|
||||
describe('Messaging Library', () => {
|
||||
@@ -47,18 +46,10 @@ describe('Messaging Library', () => {
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
// Create 3 users: 1 admin, 2 regular
|
||||
({
|
||||
foo: mocks.users.foo.uid,
|
||||
bar: mocks.users.bar.uid,
|
||||
baz: mocks.users.baz.uid,
|
||||
herp: mocks.users.herp.uid,
|
||||
} = await utils.promiseParallel({
|
||||
foo: User.create({ username: 'foo', password: 'barbar' }), // admin
|
||||
bar: User.create({ username: 'bar', password: 'bazbaz' }), // admin
|
||||
baz: User.create({ username: 'baz', password: 'quuxquux' }), // restricted user
|
||||
herp: User.create({ username: 'herp', password: 'derpderp' }), // a regular user
|
||||
}));
|
||||
mocks.users.foo.uid = await User.create({ username: 'foo', password: 'barbar' }); // admin
|
||||
mocks.users.bar.uid = await User.create({ username: 'bar', password: 'bazbaz' }); // admin
|
||||
mocks.users.baz.uid = await User.create({ username: 'baz', password: 'quuxquux' }); // restricted user
|
||||
mocks.users.herp.uid = await User.create({ username: 'herp', password: 'derpderp' }); // a regular user
|
||||
|
||||
await Groups.join('administrators', mocks.users.foo.uid);
|
||||
await User.setSetting(mocks.users.baz.uid, 'disableIncomingChats', '1');
|
||||
@@ -295,6 +286,16 @@ describe('Messaging Library', () => {
|
||||
assert.strictEqual(message.content, 'user-join');
|
||||
});
|
||||
|
||||
it('should make both users owners on room creation', async () => {
|
||||
const { body } = await callv3API('post', '/chats', {
|
||||
uids: [mocks.users.foo.uid],
|
||||
}, 'herp');
|
||||
const { roomId } = body.response;
|
||||
assert.deepStrictEqual(
|
||||
await Messaging.isRoomOwner([mocks.users.herp.uid, mocks.users.foo.uid], roomId), [true, true]
|
||||
);
|
||||
});
|
||||
|
||||
it('should change owner when owner leaves room', async () => {
|
||||
const { body } = await callv3API('post', '/chats', {
|
||||
uids: [mocks.users.foo.uid],
|
||||
@@ -804,7 +805,7 @@ describe('Messaging Library', () => {
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert(Array.isArray(body.rooms));
|
||||
assert.equal(body.rooms.length, 2);
|
||||
assert.equal(body.rooms.length, 3);
|
||||
assert.equal(body.title, '[[pages:chats]]');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user