Skip to content
Snippets Groups Projects
Commit bca5eb5e authored by Diego Sampaio's avatar Diego Sampaio
Browse files

option to configure routes by room type

parent da492076
No related merge requests found
Meteor.startup ->
RocketChat.roomTypes.add('starredRooms', 'user');
RocketChat.roomTypes.add('channels', 'user');
RocketChat.roomTypes.add('directMessages', 'user');
RocketChat.roomTypes.add('privateGroups', 'user');
RocketChat.roomTypes.addType('starredRooms', 'user');
RocketChat.roomTypes.addType('channels', 'user');
RocketChat.roomTypes.addType('directMessages', 'user');
RocketChat.roomTypes.addType('privateGroups', 'user');
RocketChat.roomTypes.setRoute 'c', 'channel', (sub) ->
return { name: sub.name }
RocketChat.roomTypes.setRoute 'd', 'direct', (sub) ->
return { username: sub.name }
RocketChat.roomTypes.setRoute 'p', 'group', (sub) ->
return { name: sub.name }
......@@ -39,13 +39,7 @@ Template.chatRoomItem.helpers
return true
route: ->
return switch this.t
when 'd'
FlowRouter.path('direct', {username: this.name})
when 'p'
FlowRouter.path('group', {name: this.name})
when 'c'
FlowRouter.path('channel', {name: this.name})
FlowRouter.path RocketChat.roomTypes.getRoute @t, @
Template.chatRoomItem.rendered = ->
if not (FlowRouter.getParam('_id')? and FlowRouter.getParam('_id') is this.data.rid) and not this.data.ls
......
......@@ -95,6 +95,6 @@ Template.sideNav.onRendered ->
wrapper = $('.rooms-list .wrapper').get(0)
lastLink = $('.rooms-list h3').get(0)
RocketChat.roomTypes.get().forEach (roomType) ->
RocketChat.roomTypes.getTypes().forEach (roomType) ->
if RocketChat.authz.hasRole(Meteor.userId(), roomType.roles) && Template[roomType.template]?
Blaze.render Template[roomType.template], wrapper, lastLink
RocketChat.roomTypes = new class
rooms = []
routes = {}
add = (template, roles = []) ->
### Sets a route for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
@param routeName: route's name for given type
@param dataCallback: callback for the route data. receives the whole subscription data as parameter
###
setRoute = (roomType, routeName, dataCallback) ->
if routes[roomType]?
throw new Meteor.Error 'route-callback-exists', 'Route callback for the given type already exists'
# dataCallback ?= -> return {}
routes[roomType] =
name: routeName
data: dataCallback or -> return {}
###
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
@param subData: the user's subscription data
###
getRoute = (roomType, subData) ->
unless routes[roomType]?
throw new Meteor.Error 'route-doesnt-exists', 'There is no route for the type: ' + roomType
return FlowRouter.path routes[roomType].name, routes[roomType].data(subData)
### add a type of room
@param template: the name of the template to render on sideNav
@param roles[]: a list of roles a user must have to see the template
###
addType = (template, roles = []) ->
rooms.push
template: template
roles: [].concat roles
getAll = ->
getAllTypes = ->
return rooms
add: add
get: getAll
addType: addType
getTypes: getAllTypes
setRoute: setRoute
getRoute: getRoute
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment