Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ const methodCall = () => ({
const result = Meteor.call(method, ...params);
return API.v1.success(mountResult({ id, result }));
} catch (error) {
Meteor._debug(`Exception while invoking method ${ method }`, error.stack);

return API.v1.success(mountResult({ id, error }));
}
},
Expand Down
6 changes: 6 additions & 0 deletions app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,12 @@ settings.addGroup('Layout', function() {
type: 'boolean',
public: true,
});

this.add('Number_of_users_autocomplete_suggestions', 5, {
type: 'int',
public: true,
});

this.add('UI_Unread_Counter_Style', 'Different_Style_For_User_Mentions', {
type: 'select',
values: [
Expand Down
1 change: 1 addition & 0 deletions app/migrations/server/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ Migrations._migrateTo = function(version, rerun) {
`Branch: ${ Info.commit.branch }`,
`Tag: ${ Info.commit.tag }`,
]));
console.log(e.stack);
process.exit(1);
}
}
Expand Down
16 changes: 15 additions & 1 deletion app/models/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,10 @@ export class Subscriptions extends Base {

Rooms.incUsersCountById(room._id);

if (!['d', 'l'].includes(room.t)) {
Users.addRoomByUserId(user._id, room._id);
}

return result;
}

Expand All @@ -1326,6 +1330,8 @@ export class Subscriptions extends Base {
Rooms.incUsersCountNotDMsByIds(roomIds, -1);
}

Users.removeAllRoomsByUserId(userId);

return result;
}

Expand All @@ -1340,6 +1346,8 @@ export class Subscriptions extends Base {
Rooms.incUsersCountById(roomId, - result);
}

Users.removeRoomByRoomId(roomId);

return result;
}

Expand All @@ -1355,11 +1363,17 @@ export class Subscriptions extends Base {
Rooms.incUsersCountById(roomId, - result);
}

Users.removeRoomByUserId(userId, roomId);

return result;
}

removeByRoomIds(rids) {
return this.remove({ rid: { $in: rids } });
const result = this.remove({ rid: { $in: rids } });

Users.removeRoomByRoomIds(rids);

return result;
}

// //////////////////////////////////////////////////////////////////
Expand Down
65 changes: 63 additions & 2 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export class Users extends Base {
constructor(...args) {
super(...args);

this.defaultFields = {
__rooms: 0,
};

this.tryEnsureIndex({ __rooms: 1 }, { sparse: 1 });

this.tryEnsureIndex({ roles: 1 }, { sparse: 1 });
this.tryEnsureIndex({ name: 1 });
this.tryEnsureIndex({ bio: 1 }, { sparse: 1 });
Expand Down Expand Up @@ -388,6 +394,48 @@ export class Users extends Base {
});
}

addRoomByUserId(_id, rid) {
return this.update({
_id,
__rooms: { $ne: rid },
}, {
$addToSet: { __rooms: rid },
});
}

removeRoomByUserId(_id, rid) {
return this.update({
_id,
__rooms: rid,
}, {
$pull: { __rooms: rid },
});
}

removeAllRoomsByUserId(_id) {
return this.update({
_id,
}, {
$set: { __rooms: [] },
});
}

removeRoomByRoomId(rid) {
return this.update({
__rooms: rid,
}, {
$pull: { __rooms: rid },
}, { multi: true });
}

removeRoomByRoomIds(rids) {
return this.update({
__rooms: { $in: rids },
}, {
$pullAll: { __rooms: rids },
}, { multi: true });
}

update2FABackupCodesByUserId(userId, backupCodes) {
return this.update({
_id: userId,
Expand Down Expand Up @@ -509,6 +557,19 @@ export class Users extends Base {
return this.findOne(query, options);
}

findOneByUsernameAndRoomIgnoringCase(username, rid, options) {
if (typeof username === 'string') {
username = new RegExp(`^${ s.escapeRegExp(username) }$`, 'i');
}

const query = {
__rooms: rid,
username,
};

return this.findOne(query, options);
}

findOneByUsernameAndServiceNameIgnoringCase(username, userId, serviceName, options) {
if (typeof username === 'string') {
username = new RegExp(`^${ s.escapeRegExp(username) }$`, 'i');
Expand Down Expand Up @@ -661,7 +722,7 @@ export class Users extends Base {
return this.find(query, options);
}

findByActiveUsersExcept(searchTerm, exceptions, options, forcedSearchFields, extraQuery = []) {
findByActiveUsersExcept(searchTerm, exceptions, options, forcedSearchFields, extraQuery = [], { startsWith = false, endsWith = false } = {}) {
if (exceptions == null) { exceptions = []; }
if (options == null) { options = {}; }
if (!_.isArray(exceptions)) {
Expand All @@ -683,7 +744,7 @@ export class Users extends Base {
return this._db.find(query, options);
}

const termRegex = new RegExp(s.escapeRegExp(searchTerm), 'i');
const termRegex = new RegExp((startsWith ? '^' : '') + s.escapeRegExp(searchTerm) + (endsWith ? '$' : ''), 'i');

const searchFields = forcedSearchFields || settings.get('Accounts_SearchFields').trim().split(',');

Expand Down
20 changes: 14 additions & 6 deletions app/models/server/models/_BaseDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ export class BaseDb extends EventEmitter {
};
}

_ensureDefaultFields(options) {
if ((options?.fields == null || Object.keys(options?.fields).length === 0) && this.baseModel.defaultFields) {
options.fields = this.baseModel.defaultFields;
}
}

_doNotMixInclusionAndExclusionFields(options) {
this._ensureDefaultFields(options);

if (options && options.fields) {
const keys = Object.keys(options.fields);
const removeKeys = keys.filter((key) => options.fields[key] === 0);
Expand All @@ -134,18 +142,18 @@ export class BaseDb extends EventEmitter {
}
}

find(...args) {
this._doNotMixInclusionAndExclusionFields(args[1]);
return this.model.find(...args);
find(query = {}, options = {}) {
this._doNotMixInclusionAndExclusionFields(options);
return this.model.find(query, options);
}

findById(_id, options) {
return this.find({ _id }, options);
}

findOne(...args) {
this._doNotMixInclusionAndExclusionFields(args[1]);
return this.model.findOne(...args);
findOne(query = {}, options = {}) {
this._doNotMixInclusionAndExclusionFields(options);
return this.model.findOne(query, options);
}

findOneById(_id, options) {
Expand Down
16 changes: 12 additions & 4 deletions app/models/server/raw/BaseRaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ export class BaseRaw {
this.col = col;
}

_ensureDefaultFields(options) {
if ((options?.fields == null || Object.keys(options?.fields).length === 0) && this.defaultFields) {
options.fields = this.defaultFields;
}
}

findOneById(_id, options = {}) {
return this.findOne({ _id }, options);
}

findOne(...args) {
return this.col.findOne(...args);
findOne(query = {}, options = {}) {
this._ensureDefaultFields(options);
return this.col.findOne(query, options);
}

findUsersInRoles() {
throw new Error('overwrite-function', 'You must overwrite this function in the extended classes');
}

find(...args) {
return this.col.find(...args);
find(query = {}, options = {}) {
this._ensureDefaultFields(options);
return this.col.find(query, options);
}

update(...args) {
Expand Down
8 changes: 8 additions & 0 deletions app/models/server/raw/Users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { BaseRaw } from './BaseRaw';

export class UsersRaw extends BaseRaw {
constructor(...args) {
super(...args);

this.defaultFields = {
__rooms: 0,
};
}

findUsersInRoles(roles, scope, options) {
roles = [].concat(roles);

Expand Down
6 changes: 6 additions & 0 deletions app/theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,12 @@
background-size: contain;
}

.rc-old .popup-user-not_in_channel {
display: inline-block;

float: right;
}

.rc-old .popup-user-status {
display: inline-block;

Expand Down
Loading