[FIX] Real Name on Direct Messages (#12154)

pull/12175/head
Guilherme Gazzo 7 years ago committed by Diego Sampaio
parent db7207d138
commit b2f18254fb
  1. 5
      server/methods/createDirectMessage.js
  2. 36
      server/startup/migrations/v133.js

@ -66,7 +66,6 @@ Meteor.methods({
// Make user I have a subcription to this room
const upsertSubscription = {
$set: {
ts: now,
ls: now,
open: true,
},
@ -83,6 +82,7 @@ Meteor.methods({
_id: me._id,
username: me.username,
},
ts: now,
...myNotificationPref,
},
};
@ -103,7 +103,7 @@ Meteor.methods({
$and: [{ 'u._id': to._id }], // work around to solve problems with upsert and dot
}, {
$setOnInsert: {
fname: me.username,
fname: me.name,
name: me.username,
t: 'd',
open: false,
@ -116,6 +116,7 @@ Meteor.methods({
_id: to._id,
username: to.username,
},
ts: now,
...toNotificationPref,
},
});

@ -0,0 +1,36 @@
RocketChat.Migrations.add({
version: 133,
up() {
const subscriptions = RocketChat.models.Subscriptions.find({
t: 'd',
$or: [{
ts: { $gte: new Date('2018-07-09T00:00:00Z') },
}, {
ts: null,
}],
});
subscriptions.forEach((subscription) => {
if (subscription.name !== subscription.fname) {
return;
}
const user = RocketChat.models.Users.findOne({
username: subscription.name,
}, {
fields: {
name: 1,
},
});
if (!user) {
return;
}
RocketChat.models.Subscriptions.update({
_id: subscription._id,
}, {
$set: {
fname: user.name,
},
});
});
},
});
Loading…
Cancel
Save