add findOrCreateRoom function

pull/1130/head
pauking 10 years ago
parent 3c82804983
commit 8b6085df51
  1. 13
      server/methods/findOrCreateRoom.coffee
  2. 8
      server/restapi/restapi.coffee

@ -0,0 +1,13 @@
Meteor.methods
findOrCreateClientRoomThenJoin: (clientId, usernames) ->
m = clientId.match(/^(?:CLT){0,1}([0-9]+)/i);
roomName = m[0];
if not roomName?
throw new Meteor.Error 403, '[methods] findOrCreateClientRoom -> Mal-format'
room = RocketChat.models.Rooms.findOneByName(roomName);
console.log '[methods] findOrCreateClientRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
if not room?
room = Meteor.call('createPrivateGroup', roomName, Meteor.userId(), usernames)
Meteor.call 'joinRoom', room._id

@ -21,6 +21,14 @@ Api.addRoute 'rooms/:id/join', authRequired: true,
Meteor.call('joinRoom', @urlParams.id)
status: 'success' # need to handle error
# find or create a room
Api.addRoute 'rooms/findorcreatethenjoin/:clientId', authRequired: true,
post: ->
Meteor.runAsUser this.userId, () =>
Meteor.call('findOrCreateClientRoomThenJoin', @urlParams.clientId)
status: 'success' # need to handle error
# leave a room
Api.addRoute 'rooms/:id/leave', authRequired: true,
post: ->

Loading…
Cancel
Save