[IMPROVE] Typing indicators now use Real Names (#11164)

Part of an attempt to improve #11145

If the admin has "Use Real Name" on, typing indicators now show the real name, making life a lot easier for those who auto-generate usernames or otherwise have usernames that don't correlate with the user.

**Before, or with "Use Real Name" off**
![2018-06-15_21-52-59](https://user-images.githubusercontent.com/39674991/41487087-7cb40974-70e7-11e8-89c5-0336cb9e8592.png)

**After, with "Use Real Name" on**
![2018-06-15_21-53-15](https://user-images.githubusercontent.com/39674991/41487094-8540e01c-70e7-11e8-89f8-acefa1e9ae1a.png)

Enjoy!
pull/11046/merge
フィンメーラ 7 years ago committed by Guilherme Gazzo
parent 146837ba17
commit 76f5bfee86
  1. 12
      packages/rocketchat-lib/server/functions/Notifications.js
  2. 18
      packages/rocketchat-ui/client/lib/msgTyping.js

@ -115,11 +115,12 @@ RocketChat.Notifications = new class {
RocketChat.Notifications.streamRoom.allowWrite(function(eventName, username, typing, extraData) {
const [roomId, e] = eventName.split('/');
if (e === 'webrtc') {
return true;
}
if (e === 'typing') {
const key = RocketChat.settings.get('UI_Use_Real_Name') ? 'name' : 'username';
// typing from livechat widget
if (extraData && extraData.token) {
const room = RocketChat.models.Rooms.findOneById(roomId);
@ -130,12 +131,15 @@ RocketChat.Notifications.streamRoom.allowWrite(function(eventName, username, typ
const user = Meteor.users.findOne(this.userId, {
fields: {
username: 1
[key]: 1
}
});
if (user != null && user.username === username) {
return true;
if (!user) {
return false;
}
return user[key] === username;
}
return false;
});

@ -9,14 +9,24 @@ export const MsgTyping = (function() {
const usersTyping = {};
const dep = new Tracker.Dependency;
const shownName = function(user) {
if (!user) {
return;
}
if (RocketChat.settings.get('UI_Use_Real_Name')) {
return user.name;
}
return user.username;
};
const addStream = function(room) {
if (!_.isEmpty(usersTyping[room] && usersTyping[room].users)) {
return;
}
usersTyping[room] = { users: {} };
return RocketChat.Notifications.onRoom(room, 'typing', function(username, typing) {
const user = Meteor.user();
if (username === (user && user.username)) {
const user = Meteor.users.findOne(Meteor.userId(), { fields: { name: 1, username: 1 } });
if (username === shownName(user)) {
return;
}
const { users } = usersTyping[room];
@ -43,7 +53,7 @@ export const MsgTyping = (function() {
timeouts[room] = null;
}
const user = Meteor.user();
return RocketChat.Notifications.notifyRoom(room, 'typing', user && user.username, false);
return RocketChat.Notifications.notifyRoom(room, 'typing', shownName(user), false);
};
const start = function(room) {
if (!renew) { return; }
@ -53,7 +63,7 @@ export const MsgTyping = (function() {
renew = false;
selfTyping.set(true);
const user = Meteor.user();
RocketChat.Notifications.notifyRoom(room, 'typing', user && user.username, true);
RocketChat.Notifications.notifyRoom(room, 'typing', shownName(user), true);
clearTimeout(timeouts[room]);
return timeouts[room] = Meteor.setTimeout(() => stop(room), timeout);
};

Loading…
Cancel
Save