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/saveRoomName.coffee

46 lines
844 B

Meteor.methods
11 years ago
saveRoomName: (rid, name) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user")
11 years ago
room = ChatRoom.findOne rid
11 years ago
if room.u._id isnt Meteor.userId() or room.t not in ['c', 'p']
throw new Meteor.Error 403, 'Not allowed'
if not /^[0-9a-z-_]+$/.test name
throw new Meteor.Error 'name-invalid'
11 years ago
name = _.slugify name
11 years ago
if name is room.name
return
# avoid duplicate names
if ChatRoom.findOne({name:name})
throw new Meteor.Error 'duplicate-name'
11 years ago
ChatRoom.update rid,
$set:
11 years ago
name: name
11 years ago
ChatSubscription.update
rid: rid
,
$set:
11 years ago
name: name
alert: true
,
multi: true
ChatMessage.insert
11 years ago
rid: rid
ts: (new Date)
t: 'r'
11 years ago
msg: name
u:
_id: Meteor.userId()
username: Meteor.user().username
return name