The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/methods/createDirectRoom.coffee

47 lines
953 B

Meteor.methods
createDirectRoom: (toUserId) ->
fromId = Meteor.userId()
# console.log '[methods] createDirectRoom -> '.green, 'fromId:', fromId, 'toUserId:', toUserId
if Meteor.userId() is toUserId
return
roomId = [Meteor.userId(), toUserId].sort().join('')
userTo = Meteor.users.findOne { _id: toUserId }
me = Meteor.user()
now = new Date()
# create new room
ChatRoom.upsert { _id: roomId },
$set:
uids: [Meteor.userId(),toUserId]
$setOnInsert:
t: 'd'
name: "#{me.name}|#{userTo.name}"
msgs: 0
ts: now
ChatSubscription.upsert { $and: [{'u._id': Meteor.userId()}], rid: roomId },
$set:
ts: now
ls: now
rn: userTo.name
$setOnInsert:
t: 'd'
unread: 0
'u._id': userTo._id
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
}