diff --git a/client/methods/sendMessage.coffee b/client/methods/sendMessage.coffee
index 4cee976d5d0..958ffaf1655 100644
--- a/client/methods/sendMessage.coffee
+++ b/client/methods/sendMessage.coffee
@@ -3,10 +3,11 @@ Meteor.methods
Tracker.nonreactive ->
now = new Date(Date.now() + TimeSync.serverOffset())
- ChatMessage.upsert { rid: msg.rid, uid: Meteor.userId(), t: 't' },
+ ChatMessage.upsert { rid: msg.rid, t: 't' },
$set:
ts: now
msg: msg.message
+ 'u.username': Meteor.user().username
$unset:
t: 1
expireAt: 1
@@ -15,7 +16,7 @@ Meteor.methods
Tracker.nonreactive ->
now = new Date(Date.now() + TimeSync.serverOffset())
- ChatMessage.update { _id: msg.id, uid: Meteor.userId() },
+ ChatMessage.update { _id: msg.id, 'u._id': Meteor.userId() },
$set:
ets: now
msg: msg.message
diff --git a/client/methods/typingStatus.coffee b/client/methods/typingStatus.coffee
index 8d2536819f5..fdff0694957 100644
--- a/client/methods/typingStatus.coffee
+++ b/client/methods/typingStatus.coffee
@@ -6,7 +6,7 @@ Meteor.methods
filter =
t: 't'
rid: typingData.rid
- uid: Meteor.userId()
+ $and: [{'u._id': Meteor.userId()}]
if start
msgData =
@@ -14,6 +14,8 @@ Meteor.methods
expireAt: moment().add(30, 'seconds').toDate()
'$setOnInsert':
msg: '...'
+ 'u._id': Meteor.userId()
+ 'u.username': Meteor.user().username
ts: moment().add(1, 'years').toDate()
ChatMessage.upsert(filter, msgData)
diff --git a/client/startup/startup.coffee b/client/startup/startup.coffee
index 083a88a33d3..1ec645e9af3 100644
--- a/client/startup/startup.coffee
+++ b/client/startup/startup.coffee
@@ -28,24 +28,15 @@ Meteor.startup ->
Meteor.users.find({}, { fields: { name: 1, pictures: 1, status: 1, emails: 1, phone: 1, services: 1 } }).observe
added: (user) ->
- Session.set('user_' + user._id + '_name', user.name)
Session.set('user_' + user._id + '_status', user.status)
- Session.set('user_' + user._id + '_emails', user.emails)
- Session.set('user_' + user._id + '_phone', user.phone)
UserAndRoom.insert({ type: 'u', uid: user._id, name: user.name})
changed: (user) ->
- Session.set('user_' + user._id + '_name', user.name)
Session.set('user_' + user._id + '_status', user.status)
- Session.set('user_' + user._id + '_emails', user.emails)
- Session.set('user_' + user._id + '_phone', user.phone)
UserAndRoom.update({ uid: user._id }, { $set: { name: user.name } })
removed: (user) ->
- Session.set('user_' + user._id + '_name', null)
Session.set('user_' + user._id + '_status', null)
- Session.set('user_' + user._id + '_emails', null)
- Session.set('user_' + user._id + '_phone', null)
UserAndRoom.remove({ uid: user._id })
diff --git a/client/views/app/chatMessageDashboard.coffee b/client/views/app/chatMessageDashboard.coffee
index 698df19f780..bb0b66c397c 100644
--- a/client/views/app/chatMessageDashboard.coffee
+++ b/client/views/app/chatMessageDashboard.coffee
@@ -3,8 +3,7 @@ Template.chatMessageDashboard.helpers
return 'own' if this.data.uid is Meteor.userId()
username: ->
- if this.uid?
- return Session.get('user_' + this.uid + '_name')
+ return this.u.username
isSystemMessage: ->
return this.t in ['s', 'p', 'f', 'r', 'au', 'ru', 'ul', 'nu', 'wm']
diff --git a/client/views/app/chatWindowDashboard.coffee b/client/views/app/chatWindowDashboard.coffee
index 35765785cf3..3e54e90a5df 100644
--- a/client/views/app/chatWindowDashboard.coffee
+++ b/client/views/app/chatWindowDashboard.coffee
@@ -37,7 +37,7 @@ Template.chatWindowDashboard.helpers
typing: ->
console.log 'chatWindowDashboard.typing' if window.rocketDebug
- return this.uid isnt Meteor.userId()
+ return this.u._id isnt Meteor.userId()
usersTyping: ->
messages = ChatMessage.find { rid: this._id }, { sort: { ts: 1 } }
@@ -45,10 +45,10 @@ Template.chatWindowDashboard.helpers
selfTyping = false
messages.forEach (message) ->
if message.t is 't'
- if message.uid is Meteor.userId()
+ if message.u._id is Meteor.userId()
selfTyping = true
else
- username = Session.get('user_' + message.uid + '_name')
+ username = message.u.username
if username?
usernames.push username
@@ -142,14 +142,14 @@ Template.chatWindowDashboard.helpers
return {} unless roomData
if roomData.t is 'd'
- uid = _.without roomData.uids, Meteor.userId()
- UserManager.addUser uid
+ username = _.without roomData.usernames, Meteor.user().username
+ UserManager.addUser username
userData = {
- name: Session.get('user_' + uid + '_name')
- emails: Session.get('user_' + uid + '_emails') || []
- phone: Session.get('user_' + uid + '_phone')
- uid: String(uid)
+ name: Session.get('user_' + username + '_name')
+ emails: Session.get('user_' + username + '_emails') || []
+ phone: Session.get('user_' + username + '_phone')
+ username: String(username)
}
return userData
@@ -241,7 +241,7 @@ Template.chatWindowDashboard.helpers
room = ChatRoom.findOne(this._id, { reactive: false })
ret =
_id: this._id
- total: room?.uids.length
+ total: room?.usernames.length
totalOnline: 0
users: []
diff --git a/client/views/app/chatWindowDashboard.html b/client/views/app/chatWindowDashboard.html
index 86bf6735a2a..078170d698c 100644
--- a/client/views/app/chatWindowDashboard.html
+++ b/client/views/app/chatWindowDashboard.html
@@ -128,7 +128,7 @@
{{> avatar userId=uid}}
-
{{name}}
+
{{username}}
{{#if contactCode}}
{{_ "general.Contact"}} {{contactCode}}
{{/if}}
@@ -156,7 +156,7 @@
{{> avatar userId=uid}}
-
{{name}}
+
{{username}}
{{#if contactCode}}
{{_ "general.contact"}} {{contactCode}}
{{/if}}
diff --git a/client/views/app/sideNav/chatRoomItem.coffee b/client/views/app/sideNav/chatRoomItem.coffee
index f327b2ba53b..19931e99352 100644
--- a/client/views/app/sideNav/chatRoomItem.coffee
+++ b/client/views/app/sideNav/chatRoomItem.coffee
@@ -32,7 +32,7 @@ Template.chatRoomItem.helpers
return false unless roomData
- if (roomData.cl? and not roomData.cl) or roomData.t is 'd' or (roomData.uids.indexOf(Meteor.userId()) isnt -1 and roomData.uids.length is 1)
+ if (roomData.cl? and not roomData.cl) or roomData.t is 'd' or (roomData.usernames.indexOf(Meteor.user().username) isnt -1 and roomData.uids.length is 1)
return false
else
return true
diff --git a/client/views/app/sideNav/userStatus.coffee b/client/views/app/sideNav/userStatus.coffee
index 2d2649337eb..c5fcec5692f 100644
--- a/client/views/app/sideNav/userStatus.coffee
+++ b/client/views/app/sideNav/userStatus.coffee
@@ -13,6 +13,7 @@ Template.userStatus.helpers
status: Session.get('user_' + Meteor.userId() + '_status')
visualStatus: visualStatus
_id: Meteor.userId()
+ username: Meteor.user().username
}
Template.userStatus.events
diff --git a/client/views/app/sideNav/userStatus.html b/client/views/app/sideNav/userStatus.html
index 336a9866b92..436a8a2d8f3 100644
--- a/client/views/app/sideNav/userStatus.html
+++ b/client/views/app/sideNav/userStatus.html
@@ -2,13 +2,13 @@
{{#with myUserInfo}}
- {{#if name}}
+ {{#if username}}
{{> avatar userId=_id}}
-
{{name}}
+ {{username}}
diff --git a/server/methods/canAccessRoom.coffee b/server/methods/canAccessRoom.coffee
index 6a1e6f237d1..5a5bc867528 100644
--- a/server/methods/canAccessRoom.coffee
+++ b/server/methods/canAccessRoom.coffee
@@ -16,15 +16,16 @@ Meteor.methods
if room.t is 'c'
canAccess = true
- else if room.uids.indexOf(Meteor.userId()) isnt -1
+ else if room.usernames.indexOf(Meteor.user().username) isnt -1
canAccess = true
if canAccess isnt true
throw new Meteor.Error 'without-permission', "[methods] canAccessRoom -> User doesn't have enough permissions"
# create room subscription
- ChatSubscription.upsert { rid: roomId, 'u._id': Meteor.userId() },
+ ChatSubscription.upsert { rid: roomId, $and: [{'u._id': Meteor.userId()}] },
$setOnInsert:
+ 'u._id': Meteor.userId()
rn: room.name
t: room.t
unread: 0
diff --git a/server/methods/createDirectRoom.coffee b/server/methods/createDirectRoom.coffee
index 9e7d70e31d7..d9c0eba53ad 100644
--- a/server/methods/createDirectRoom.coffee
+++ b/server/methods/createDirectRoom.coffee
@@ -24,7 +24,7 @@ Meteor.methods
msgs: 0
ts: now
- ChatSubscription.upsert { 'u._id': Meteor.userId(), rid: roomId },
+ ChatSubscription.upsert { $and: [{'u._id': Meteor.userId()}], rid: roomId },
$set:
ts: now
ls: now
@@ -32,13 +32,15 @@ Meteor.methods
$setOnInsert:
t: 'd'
unread: 0
+ 'u._id': userTo._id
- ChatSubscription.upsert { 'u._id': userTo._id, rid: roomId },
+ ChatSubscription.upsert { $and: [{'u._id': userTo._id}], rid: roomId },
$set:
rn: me.name
$setOnInsert:
t: 'd'
unread: 0
+ 'u._id': userTo._id
return {
rid: roomId
diff --git a/server/methods/forwardRoom.coffee b/server/methods/forwardRoom.coffee
index c8a7c95b15b..01ac8448064 100644
--- a/server/methods/forwardRoom.coffee
+++ b/server/methods/forwardRoom.coffee
@@ -19,8 +19,9 @@ Meteor.methods
# $pull:
# uids: Meteor.userId()
- ChatSubscription.upsert { rid: forward.rid, 'u._id': forward.to },
+ ChatSubscription.upsert { rid: forward.rid, $and: [{'u._id': forward.to}] },
$setOnInsert:
+ 'u._id': forward.to
rn: room.name
t: 'v'
unread: 0
diff --git a/server/methods/sendMessage.coffee b/server/methods/sendMessage.coffee
index d1e6dec1144..fc19ffb626d 100644
--- a/server/methods/sendMessage.coffee
+++ b/server/methods/sendMessage.coffee
@@ -19,13 +19,13 @@ Meteor.methods
roomUpdate = { $set: { lm: now }, $inc: { msgs: 1 } }
- if Meteor.userId() and roomData.uids.indexOf(Meteor.userId()) is -1
- roomUpdate.$push = { uids: Meteor.userId() }
+ if Meteor.userId() and not Meteor.user().username in roomData.usernames
+ roomUpdate.$push = { usernames: Meteor.user().username }
ChatRoom.update rid, roomUpdate
if Meteor.userId()?
- messageFilter = { rid: rid, uid: Meteor.userId(), t: 't' }
+ messageFilter = { rid: rid, $and: [{ 'u._id': Meteor.userId() }], t: 't' }
activityFilter = { rid: rid, 'u._id': { $ne: Meteor.userId() } }
mentions = []
@@ -47,6 +47,8 @@ Meteor.methods
ChatMessage.upsert messageFilter,
$set:
+ 'u._id': Meteor.userId()
+ 'u.username': Meteor.user().username
ts: now
msg: msg.message
mentions: mentions
@@ -68,7 +70,7 @@ Meteor.methods
now = new Date()
- messageFilter = { _id: msg.id, uid: Meteor.userId() }
+ messageFilter = { _id: msg.id, 'u._id': Meteor.userId() }
ChatMessage.update messageFilter,
$set:
diff --git a/server/methods/setUsername.coffee b/server/methods/setUsername.coffee
index 6d695621c66..a896a4b34df 100644
--- a/server/methods/setUsername.coffee
+++ b/server/methods/setUsername.coffee
@@ -44,6 +44,9 @@ Meteor.methods
unread: 0
ChatMessage.insert
+ u:
+ _id: user._id
+ username: username
rid: '57om6EQCcFami9wuT'
ts: new Date()
t: 'wm'
diff --git a/server/methods/typingStatus.coffee b/server/methods/typingStatus.coffee
index c10c89d3e2a..472c03ecada 100644
--- a/server/methods/typingStatus.coffee
+++ b/server/methods/typingStatus.coffee
@@ -9,7 +9,7 @@ Meteor.methods
filter =
t: 't'
rid: typingData.rid
- uid: Meteor.userId()
+ $and: [{'u._id': Meteor.userId()}]
if start
msgData =
@@ -18,6 +18,8 @@ Meteor.methods
'$setOnInsert':
msg: '...'
ts: moment().add(1, 'years').toDate()
+ 'u._id': Meteor.userId()
+ 'u.username': Meteor.user().username
ChatMessage.upsert(filter, msgData)
else
diff --git a/server/startup/generalRoom.coffee b/server/startup/generalRoom.coffee
index cdd4247005c..d598d2ceb1d 100644
--- a/server/startup/generalRoom.coffee
+++ b/server/startup/generalRoom.coffee
@@ -3,7 +3,7 @@ Meteor.startup ->
if ChatRoom.find('57om6EQCcFami9wuT').count() is 0
ChatRoom.insert
_id: '57om6EQCcFami9wuT'
- uids: []
+ usernames: []
ts: new Date()
t: 'c'
name: 'general'