Add APIs to display room name and find the room object

pull/3100/head
Diego Sampaio 10 years ago
parent bd15484205
commit 21b3e15dfc
  1. 22
      client/startup/defaultRoomTypes.coffee
  2. 15
      packages/rocketchat-lib/client/lib/openRoom.coffee
  3. 9
      packages/rocketchat-lib/client/lib/roomTypes.coffee
  4. 9
      packages/rocketchat-livechat/client/ui.js
  5. 16
      packages/rocketchat-ui/lib/RoomManager.coffee
  6. 10
      packages/rocketchat-ui/views/app/room.coffee

@ -13,6 +13,13 @@ RocketChat.roomTypes.add 'c', 10,
RocketChat.TabBar.showGroup 'channel'
link: (sub) ->
return { name: sub.name }
findRoom: (identifier) ->
query =
t: 'c'
name: identifier
return ChatRoom.findOne(query)
roomName: (roomData) ->
return roomData.name
condition: ->
return RocketChat.authz.hasAllPermission 'view-c-room'
@ -27,6 +34,14 @@ RocketChat.roomTypes.add 'd', 20,
RocketChat.TabBar.showGroup 'directmessage'
link: (sub) ->
return { username: sub.name }
findRoom: (identifier, user) ->
query =
t: 'd'
usernames:
$all: [identifier, user.username]
return ChatRoom.findOne(query)
roomName: (roomData) ->
return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } })?.name
condition: ->
return RocketChat.authz.hasAllPermission 'view-d-room'
@ -41,5 +56,12 @@ RocketChat.roomTypes.add 'p', 30,
RocketChat.TabBar.showGroup 'privategroup'
link: (sub) ->
return { name: sub.name }
findRoom: (identifier) ->
query =
t: 'p'
name: identifier
return ChatRoom.findOne(query)
roomName: (roomData) ->
return roomData.name
condition: ->
return RocketChat.authz.hasAllPermission 'view-p-room'

@ -9,23 +9,14 @@ currentTracker = undefined
BlazeLayout.render 'main', {center: 'loading'}
return
username = Meteor.user()?.username
unless username
user = Meteor.user()
unless user?.username
return
currentTracker = undefined
c.stop()
query =
t: type
name: name
if type is 'd'
delete query.name
query.usernames =
$all: [name, username]
room = ChatRoom.findOne(query)
room = RocketChat.roomTypes.findRoom(type, name, user)
if not room?
if type is 'd'
Meteor.call 'createDirectMessage', name, (err) ->

@ -60,17 +60,26 @@ RocketChat.roomTypes = new class
getIcon = (roomType) ->
return roomTypes[roomType]?.icon
getRoomName = (roomType, roomData) ->
return roomTypes[roomType]?.roomName roomData
getIdentifiers = (except) ->
except = [].concat except
list = _.reject roomTypesOrder, (t) -> return except.indexOf(t.identifier) isnt -1
return _.map list, (t) -> return t.identifier
findRoom = (roomType, identifier, user) ->
return roomTypes[roomType]?.findRoom identifier, user
# addType: addType
getTypes: getAllTypes
getIdentifiers: getIdentifiers
findRoom: findRoom
# setIcon: setIcon
getIcon: getIcon
getRoomName: getRoomName
# setRoute: setRoute
getRouteLink: getRouteLink

@ -16,6 +16,15 @@ RocketChat.roomTypes.add('l', 5, {
};
}
},
findRoom(identifier) {
return ChatRoom.findOne({ code: parseInt(identifier) });
},
roomName(roomData) {
return roomData.name;
},
condition: () => {
return RocketChat.settings.get('Livechat_enabled') && RocketChat.authz.hasAllPermission('view-l-room');
}

@ -86,9 +86,8 @@ RocketChat.Notifications.onUser 'message', (msg) ->
for typeName, record of openedRooms when record.active is true
do (typeName, record) ->
username = Meteor.user()?.username
unless username
user = Meteor.user()
unless user?.username
return
record.sub = [
@ -104,15 +103,8 @@ RocketChat.Notifications.onUser 'message', (msg) ->
type = typeName.substr(0, 1)
name = typeName.substr(1)
query =
t: type
if type is 'd'
query.usernames = $all: [username, name]
else
query.name = name
room = ChatRoom.findOne query, { reactive: false }
room = Tracker.nonreactive =>
return RocketChat.roomTypes.findRoom(type, name, user)
if not room?
record.ready = true

@ -74,10 +74,7 @@ Template.room.helpers
roomData = Session.get('roomData' + this._id)
return '' unless roomData
if roomData.t is 'd'
return ChatSubscription.findOne({ rid: this._id }, { fields: { name: 1 } })?.name
else
return roomData.name
return RocketChat.roomTypes.getRoomName roomData?.t, roomData
roomTopic: ->
roomData = Session.get('roomData' + this._id)
@ -88,10 +85,7 @@ Template.room.helpers
roomData = Session.get('roomData' + this._id)
return '' unless roomData?.t
switch roomData.t
when 'd' then return 'icon-at'
when 'c' then return 'icon-hash'
when 'p' then return 'icon-lock'
return RocketChat.roomTypes.getIcon roomData?.t
userStatus: ->
roomData = Session.get('roomData' + this._id)

Loading…
Cancel
Save