Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into regr…
Browse files Browse the repository at this point in the history
…ession/fuselage

* 'develop' of github.com:RocketChat/Rocket.Chat:
  Regression: fix fuselage import, remove directory css (#17116)
  [IMPROVE] Apps Engine: Reduce some stream calls and remove a find user from the app's status changes (#17115)
  Regression: Remove old and closed Omnichannel inquiries (#17113)
  [FIX] Member's list only filtering users already on screen (#17110)
  • Loading branch information
ggazzo committed Apr 1, 2020
2 parents 8ce3921 + aa79e0f commit d8eb826
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 34 deletions.
18 changes: 3 additions & 15 deletions app/apps/server/bridges/activation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { STATUS_MAP } from '../../../../imports/users-presence/server/activeUsers';
import { Users } from '../../../models/server';
import { Notifications } from '../../../notifications/server';
import { Users } from '../../../models/server/raw';

export class AppActivationBridge {
constructor(orch) {
Expand All @@ -20,19 +18,9 @@ export class AppActivationBridge {
}

async appStatusChanged(app, status) {
const user = Users.findOneByAppId(app.getID(), { fields: { username: 1 } });
const userStatus = ['auto_enabled', 'manually_enabled'].includes(status) ? 'online' : 'offline';

if (user) {
const { _id, username } = user;
const userStatus = ['auto_enabled', 'manually_enabled'].includes(status) ? 'online' : 'offline';

Users.updateStatusById(_id, userStatus);
Notifications.notifyLogged('user-status', [
_id,
username,
STATUS_MAP[userStatus],
]);
}
await Users.updateStatusByAppId(app.getID(), userStatus);

await this.orch.getNotifier().appStatusUpdated(app.getID(), status);
}
Expand Down
38 changes: 19 additions & 19 deletions app/apps/server/communication/websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class AppServerListener {

async onAppAdded(appId) {
await this.orch.getManager().loadOne(appId);
this.clientStreamer.emit(AppEvents.APP_ADDED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_ADDED, appId);
}


Expand All @@ -49,17 +49,17 @@ export class AppServerListener {

if (AppStatusUtils.isEnabled(status)) {
await this.orch.getManager().enable(appId).catch(console.error);
this.clientStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_STATUS_CHANGE, { appId, status });
} else if (AppStatusUtils.isDisabled(status)) {
await this.orch.getManager().disable(appId, status, true).catch(console.error);
this.clientStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_STATUS_CHANGE, { appId, status });
}
}

async onAppSettingUpdated({ appId, setting }) {
this.received.set(`${ AppEvents.APP_SETTING_UPDATED }_${ appId }_${ setting.id }`, { appId, setting, when: new Date() });
await this.orch.getManager().getSettingsManager().updateAppSetting(appId, setting);
this.clientStreamer.emit(AppEvents.APP_SETTING_UPDATED, { appId });
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_SETTING_UPDATED, { appId });
}

async onAppUpdated(appId) {
Expand All @@ -68,7 +68,7 @@ export class AppServerListener {
const storageItem = await this.orch.getStorage().retrieveOne(appId);

await this.orch.getManager().update(storageItem.zip);
this.clientStreamer.emit(AppEvents.APP_UPDATED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_UPDATED, appId);
}

async onAppRemoved(appId) {
Expand All @@ -79,23 +79,23 @@ export class AppServerListener {
}

await this.orch.getManager().remove(appId);
this.clientStreamer.emit(AppEvents.APP_REMOVED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_REMOVED, appId);
}

async onCommandAdded(command) {
this.clientStreamer.emit(AppEvents.COMMAND_ADDED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_ADDED, command);
}

async onCommandDisabled(command) {
this.clientStreamer.emit(AppEvents.COMMAND_DISABLED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_DISABLED, command);
}

async onCommandUpdated(command) {
this.clientStreamer.emit(AppEvents.COMMAND_UPDATED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_UPDATED, command);
}

async onCommandRemoved(command) {
this.clientStreamer.emit(AppEvents.COMMAND_REMOVED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_REMOVED, command);
}
}

Expand All @@ -120,12 +120,12 @@ export class AppServerNotifier {

async appAdded(appId) {
this.engineStreamer.emit(AppEvents.APP_ADDED, appId);
this.clientStreamer.emit(AppEvents.APP_ADDED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_ADDED, appId);
}

async appRemoved(appId) {
this.engineStreamer.emit(AppEvents.APP_REMOVED, appId);
this.clientStreamer.emit(AppEvents.APP_REMOVED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_REMOVED, appId);
}

async appUpdated(appId) {
Expand All @@ -135,7 +135,7 @@ export class AppServerNotifier {
}

this.engineStreamer.emit(AppEvents.APP_UPDATED, appId);
this.clientStreamer.emit(AppEvents.APP_UPDATED, appId);
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_UPDATED, appId);
}

async appStatusUpdated(appId, status) {
Expand All @@ -148,7 +148,7 @@ export class AppServerNotifier {
}

this.engineStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
this.clientStreamer.emit(AppEvents.APP_STATUS_CHANGE, { appId, status });
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_STATUS_CHANGE, { appId, status });
}

async appSettingsChange(appId, setting) {
Expand All @@ -158,26 +158,26 @@ export class AppServerNotifier {
}

this.engineStreamer.emit(AppEvents.APP_SETTING_UPDATED, { appId, setting });
this.clientStreamer.emit(AppEvents.APP_SETTING_UPDATED, { appId });
this.clientStreamer.emitWithoutBroadcast(AppEvents.APP_SETTING_UPDATED, { appId });
}

async commandAdded(command) {
this.engineStreamer.emit(AppEvents.COMMAND_ADDED, command);
this.clientStreamer.emit(AppEvents.COMMAND_ADDED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_ADDED, command);
}

async commandDisabled(command) {
this.engineStreamer.emit(AppEvents.COMMAND_DISABLED, command);
this.clientStreamer.emit(AppEvents.COMMAND_DISABLED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_DISABLED, command);
}

async commandUpdated(command) {
this.engineStreamer.emit(AppEvents.COMMAND_UPDATED, command);
this.clientStreamer.emit(AppEvents.COMMAND_UPDATED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_UPDATED, command);
}

async commandRemoved(command) {
this.engineStreamer.emit(AppEvents.COMMAND_REMOVED, command);
this.clientStreamer.emit(AppEvents.COMMAND_REMOVED, command);
this.clientStreamer.emitWithoutBroadcast(AppEvents.COMMAND_REMOVED, command);
}
}
15 changes: 15 additions & 0 deletions app/models/server/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,19 @@ export class UsersRaw extends BaseRaw {

return this.update({ _id }, update);
}

updateStatusByAppId(appId, status) {
const query = {
appId,
status: { $ne: status },
};

const update = {
$set: {
status,
},
};

return this.update(query, update, { multi: true });
}
}
1 change: 1 addition & 0 deletions server/startup/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@ import './v176';
import './v177';
import './v178';
import './v179';
import './v180';
import './xrun';
20 changes: 20 additions & 0 deletions server/startup/migrations/v180.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Migrations } from '../../../app/migrations/server';
import { LivechatRooms, LivechatInquiry } from '../../../app/models/server';

Migrations.add({
version: 180,
up() {
// Remove Old Omnichannel Inquiries related to rooms already closed
LivechatInquiry.find().forEach((inquiry) => {
const { rid, status } = inquiry;
if (status === 'closed') {
return LivechatInquiry.removeByRoomId(rid);
}

const room = LivechatRooms.findOneById(rid, { closedAt: 1 });
if (!room || room.closedAt) {
LivechatInquiry.removeByRoomId(rid);
}
});
},
});

0 comments on commit d8eb826

Please sign in to comment.