mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-05 03:51:26 +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([
|
await Promise.all([
|
||||||
db.setObject(`chat:room:${roomId}`, room),
|
db.setObject(`chat:room:${roomId}`, room),
|
||||||
db.sortedSetAdd('chat:rooms', now, roomId),
|
db.sortedSetAdd('chat:rooms', now, roomId),
|
||||||
db.sortedSetAdd(`chat:room:${roomId}:owners`, now, uid),
|
db.sortedSetAddBulk([
|
||||||
db.sortedSetsAdd([
|
[`chat:room:${roomId}:uids`, now, uid],
|
||||||
`chat:room:${roomId}:uids`,
|
[`chat:room:${roomId}:uids:online`, 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([
|
await Promise.all([
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const Messaging = require('../src/messaging');
|
|||||||
const api = require('../src/api');
|
const api = require('../src/api');
|
||||||
const helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
const request = require('../src/request');
|
const request = require('../src/request');
|
||||||
const utils = require('../src/utils');
|
|
||||||
const translator = require('../src/translator');
|
const translator = require('../src/translator');
|
||||||
|
|
||||||
describe('Messaging Library', () => {
|
describe('Messaging Library', () => {
|
||||||
@@ -47,18 +46,10 @@ describe('Messaging Library', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// Create 3 users: 1 admin, 2 regular
|
mocks.users.foo.uid = await User.create({ username: 'foo', password: 'barbar' }); // admin
|
||||||
({
|
mocks.users.bar.uid = await User.create({ username: 'bar', password: 'bazbaz' }); // admin
|
||||||
foo: mocks.users.foo.uid,
|
mocks.users.baz.uid = await User.create({ username: 'baz', password: 'quuxquux' }); // restricted user
|
||||||
bar: mocks.users.bar.uid,
|
mocks.users.herp.uid = await User.create({ username: 'herp', password: 'derpderp' }); // a regular user
|
||||||
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
|
|
||||||
}));
|
|
||||||
|
|
||||||
await Groups.join('administrators', mocks.users.foo.uid);
|
await Groups.join('administrators', mocks.users.foo.uid);
|
||||||
await User.setSetting(mocks.users.baz.uid, 'disableIncomingChats', '1');
|
await User.setSetting(mocks.users.baz.uid, 'disableIncomingChats', '1');
|
||||||
@@ -295,6 +286,16 @@ describe('Messaging Library', () => {
|
|||||||
assert.strictEqual(message.content, 'user-join');
|
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 () => {
|
it('should change owner when owner leaves room', async () => {
|
||||||
const { body } = await callv3API('post', '/chats', {
|
const { body } = await callv3API('post', '/chats', {
|
||||||
uids: [mocks.users.foo.uid],
|
uids: [mocks.users.foo.uid],
|
||||||
@@ -804,7 +805,7 @@ describe('Messaging Library', () => {
|
|||||||
|
|
||||||
assert.equal(response.statusCode, 200);
|
assert.equal(response.statusCode, 200);
|
||||||
assert(Array.isArray(body.rooms));
|
assert(Array.isArray(body.rooms));
|
||||||
assert.equal(body.rooms.length, 2);
|
assert.equal(body.rooms.length, 3);
|
||||||
assert.equal(body.title, '[[pages:chats]]');
|
assert.equal(body.title, '[[pages:chats]]');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user