Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Apps and Livechats not getting along well with each other #10598

Merged
merged 1 commit into from
Apr 27, 2018
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: 1 addition & 1 deletion packages/rocketchat-apps/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ Package.onUse(function(api) {
Npm.depends({
'busboy': '0.2.13',
'@rocket.chat/apps-engine': '0.5.11',
'@rocket.chat/apps-ts-definition': '0.9.6'
'@rocket.chat/apps-ts-definition': '0.9.8'
});
22 changes: 18 additions & 4 deletions packages/rocketchat-apps/server/converters/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class AppMessagesConverter {
let sender;
if (msgObj.u && msgObj.u._id) {
sender = this.orch.getConverters().get('users').convertById(msgObj.u._id);

if (!sender) {
sender = this.orch.getConverters().get('users').convertToApp(msgObj.u);
}
}

let editor;
Expand Down Expand Up @@ -59,10 +63,20 @@ export class AppMessagesConverter {
let u;
if (message.sender && message.sender.id) {
const user = RocketChat.models.Users.findOneById(message.sender.id);
u = {
_id: user._id,
username: user.username
};

if (user) {
u = {
_id: user._id,
username: user.username,
name: user.name
};
} else {
u = {
_id: message.sender.id,
username: message.sender.username,
name: message.sender.name
};
}
}

let editedBy;
Expand Down
15 changes: 10 additions & 5 deletions packages/rocketchat-apps/server/converters/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ export class AppUsersConverter {
convertById(userId) {
const user = RocketChat.models.Users.findOneById(userId);

return this._convertToApp(user);
return this.convertToApp(user);
}

convertByUsername(username) {
const user = RocketChat.models.Users.findOneByUsername(username);

return this._convertToApp(user);
return this.convertToApp(user);
}

_convertToApp(user) {
convertToApp(user) {
if (!user) {
return undefined;
}

const type = this._convertUserTypeToEnum(user.type);
const status = this._convertStatusConnectionToEnum(user.username, user._id, user.status);
const statusConnection = this._convertStatusConnectionToEnum(user.username, user._id, user.statusConnection);

return {
Expand All @@ -34,7 +33,7 @@ export class AppUsersConverter {
isEnabled: user.active,
name: user.name,
roles: user.roles,
status,
status: user.status,
statusConnection,
utcOffset: user.utcOffset,
createdAt: user.createdAt,
Expand All @@ -49,6 +48,9 @@ export class AppUsersConverter {
return UserType.USER;
case 'bot':
return UserType.BOT;
case '':
case undefined:
return UserType.UNKNOWN;
default:
console.warn(`A new user type has been added that the Apps don't know about? "${ type }"`);
return type.toUpperCase();
Expand All @@ -65,6 +67,9 @@ export class AppUsersConverter {
return UserStatusConnection.AWAY;
case 'busy':
return UserStatusConnection.BUSY;
case undefined:
// This is needed for Livechat guests and Rocket.Cat user.
return UserStatusConnection.UNDEFINED;
default:
console.warn(`The user ${ username } (${ userId }) does not have a valid status (offline, online, away, or busy). It is currently: "${ status }"`);
return !status ? UserStatusConnection.OFFLINE : status.toUpperCase();
Expand Down