mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
feat: #7842, make isInvited, isPending work with uids
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const db = require('../database');
|
||||
const user = require('../user');
|
||||
const utils = require('../utils');
|
||||
@@ -90,20 +92,23 @@ module.exports = function (Groups) {
|
||||
});
|
||||
}
|
||||
|
||||
Groups.isInvited = async function (uid, groupName) {
|
||||
if (!(parseInt(uid, 10) > 0)) {
|
||||
return false;
|
||||
}
|
||||
return await db.isSetMember('group:' + groupName + ':invited', uid);
|
||||
Groups.isInvited = async function (uids, groupName) {
|
||||
return await checkInvitePending(uids, 'group:' + groupName + ':invited');
|
||||
};
|
||||
|
||||
Groups.isPending = async function (uid, groupName) {
|
||||
if (!(parseInt(uid, 10) > 0)) {
|
||||
return false;
|
||||
}
|
||||
return await db.isSetMember('group:' + groupName + ':pending', uid);
|
||||
Groups.isPending = async function (uids, groupName) {
|
||||
return await checkInvitePending(uids, 'group:' + groupName + ':pending');
|
||||
};
|
||||
|
||||
async function checkInvitePending(uids, set) {
|
||||
const isArray = Array.isArray(uids);
|
||||
uids = isArray ? uids : [uids];
|
||||
const checkUids = uids.filter(uid => parseInt(uid, 10) > 0);
|
||||
const isMembers = await db.isSetMembers(set, checkUids);
|
||||
const map = _.zipObject(checkUids, isMembers);
|
||||
return isArray ? uids.map(uid => !!map[uid]) : !!map[uids[0]];
|
||||
}
|
||||
|
||||
Groups.getPending = async function (groupName) {
|
||||
if (!groupName) {
|
||||
return [];
|
||||
|
||||
@@ -870,9 +870,9 @@ describe('Groups', function () {
|
||||
assert.ifError(err);
|
||||
socketGroups.issueMassInvite({ uid: adminUid }, { groupName: 'PrivateCanJoin', usernames: 'invite1, invite2' }, function (err) {
|
||||
assert.ifError(err);
|
||||
Groups.isInvited(uid, 'PrivateCanJoin', function (err, isInvited) {
|
||||
Groups.isInvited([adminUid, uid], 'PrivateCanJoin', function (err, isInvited) {
|
||||
assert.ifError(err);
|
||||
assert(isInvited);
|
||||
assert.deepStrictEqual(isInvited, [false, true]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user