Merge branch 'develop' into activitypub

This commit is contained in:
Barış Soner Uşaklı
2024-04-25 11:16:42 -04:00
270 changed files with 2429 additions and 1668 deletions

View File

@@ -18,8 +18,11 @@ module.exports = function (Groups) {
Groups.validateGroupName(data.name);
const exists = await meta.slugTaken(data.name);
if (exists) {
const [exists, privGroupExists] = await Promise.all([
meta.slugTaken(data.name),
privilegeGroupExists(data.name),
]);
if (exists || privGroupExists) {
throw new Error('[[error:group-already-exists]]');
}
@@ -58,7 +61,9 @@ module.exports = function (Groups) {
]);
}
await db.setObjectField('groupslug:groupname', groupData.slug, groupData.name);
if (!Groups.isPrivilegeGroup(groupData.name)) {
await db.setObjectField('groupslug:groupname', groupData.slug, groupData.name);
}
groupData = await Groups.getGroupData(groupData.name);
plugins.hooks.fire('action:group.create', { group: groupData });
@@ -71,6 +76,10 @@ module.exports = function (Groups) {
Groups.isPrivilegeGroup(data.name);
}
async function privilegeGroupExists(name) {
return Groups.isPrivilegeGroup(name) && await db.isSortedSetMember('groups:createtime', name);
}
Groups.validateGroupName = function (name) {
if (!name) {
throw new Error('[[error:group-name-too-short]]');

View File

@@ -28,7 +28,9 @@ module.exports = function (Groups) {
);
});
const sets = groupNames.map(groupName => `${groupName.toLowerCase()}:${groupName}`);
const fields = groupNames.map(groupName => slugify(groupName));
const groupSlugs = groupNames
.filter(groupName => !Groups.isPrivilegeGroup(groupName))
.map(groupName => slugify(groupName));
await Promise.all([
db.deleteAll(keys),
@@ -38,7 +40,7 @@ module.exports = function (Groups) {
'groups:visible:memberCount',
], groupNames),
db.sortedSetRemove('groups:visible:name', sets),
db.deleteObjectFields('groupslug:groupname', fields),
db.deleteObjectFields('groupslug:groupname', groupSlugs),
removeGroupsFromPrivilegeGroups(groupNames),
]);
Groups.cache.reset();

View File

@@ -9,13 +9,13 @@ module.exports = function (Groups) {
return [];
}
query = String(query).toLowerCase();
let groupNames = await db.getSortedSetRange('groups:createtime', 0, -1);
let groupNames = Object.values(await db.getObject('groupslug:groupname'));
if (!options.hideEphemeralGroups) {
groupNames = Groups.ephemeralGroups.concat(groupNames);
}
groupNames = groupNames.filter(name => name.toLowerCase().includes(query) &&
name !== Groups.BANNED_USERS && // hide banned-users in searches
!Groups.isPrivilegeGroup(name));
groupNames = groupNames.filter(
name => name.toLowerCase().includes(query) && name !== Groups.BANNED_USERS // hide banned-users in searches
);
groupNames = groupNames.slice(0, 100);
let groupsData;

View File

@@ -191,8 +191,10 @@ module.exports = function (Groups) {
await updateConfig(oldName, newName);
await updateChatRooms(oldName, newName);
await db.setObject(`group:${oldName}`, { name: newName, slug: slugify(newName) });
await db.deleteObjectField('groupslug:groupname', group.slug);
await db.setObjectField('groupslug:groupname', slugify(newName), newName);
if (!Groups.isPrivilegeGroup(oldName) && !Groups.isPrivilegeGroup(newName)) {
await db.deleteObjectField('groupslug:groupname', group.slug);
await db.setObjectField('groupslug:groupname', slugify(newName), newName);
}
const allGroups = await db.getSortedSetRange('groups:createtime', 0, -1);
const keys = allGroups.map(group => `group:${group}:members`);