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

support for room's publish by type and api for routes

parent 16e1f1cc
No related branches found
No related tags found
No related merge requests found
currentTracker = undefined
openRoom = (type, name) ->
Session.set 'openedRoom', null
Meteor.defer ->
currentTracker = Tracker.autorun (c) ->
if RoomManager.open(type + name).ready() isnt true
BlazeLayout.render 'main', {center: 'loading'}
return
currentTracker = undefined
c.stop()
query =
t: type
name: name
if type is 'd'
delete query.name
query.usernames =
$all: [name, Meteor.user()?.username]
room = ChatRoom.findOne(query)
if not room?
Session.set 'roomNotFound', {type: type, name: name}
BlazeLayout.render 'main', {center: 'roomNotFound'}
return
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
mainNode.removeChild child if child?
roomDom = RoomManager.getDomOfRoom(type + name, room._id)
mainNode.appendChild roomDom
if roomDom.classList.contains('room-container')
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop
Session.set 'openedRoom', room._id
Session.set 'editRoomTitle', false
RoomManager.updateMentionsMarksOfRoom type + name
Meteor.setTimeout ->
readMessage.readNow()
, 2000
# KonchatNotification.removeRoomNotification(params._id)
if Meteor.Device.isDesktop()
setTimeout ->
$('.message-form .input-message').focus()
, 100
RocketChat.TabBar.resetButtons()
RocketChat.TabBar.addButton({ id: 'message-search', title: t('Search'), icon: 'octicon octicon-search', template: 'messageSearch', order: 1 })
if type is 'd'
RocketChat.TabBar.addButton({ id: 'members-list', title: t('User_Info'), icon: 'octicon octicon-person', template: 'membersList', order: 2 })
else
RocketChat.TabBar.addButton({ id: 'members-list', title: t('Members_List'), icon: 'octicon octicon-organization', template: 'membersList', order: 2 })
RocketChat.TabBar.addButton({ id: 'uploaded-files-list', title: t('Room_uploaded_file_list'), icon: 'octicon octicon-file-symlink-directory', template: 'uploadedFilesList', order: 3 })
# update user's room subscription
if ChatSubscription.findOne({rid: room._id})?.open is false
Meteor.call 'openRoom', room._id
RocketChat.callbacks.run 'enter-room'
roomExit = ->
BlazeLayout.render 'main', {center: 'none'}
if currentTracker?
currentTracker.stop()
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
if child?
if child.classList.contains('room-container')
wrapper = child.querySelector('.messages-box > .wrapper')
if wrapper.scrollTop >= wrapper.scrollHeight - wrapper.clientHeight
child.oldScrollTop = 10e10
else
child.oldScrollTop = wrapper.scrollTop
mainNode.removeChild child
FlowRouter.route '/channel/:name',
name: 'channel'
......
currentTracker = undefined
@openRoom = (type, name) ->
Session.set 'openedRoom', null
Meteor.defer ->
currentTracker = Tracker.autorun (c) ->
if RoomManager.open(type + name).ready() isnt true
BlazeLayout.render 'main', {center: 'loading'}
return
currentTracker = undefined
c.stop()
query =
t: type
name: name
if type is 'd'
delete query.name
query.usernames =
$all: [name, Meteor.user()?.username]
room = ChatRoom.findOne(query)
if not room?
Session.set 'roomNotFound', {type: type, name: name}
BlazeLayout.render 'main', {center: 'roomNotFound'}
return
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
mainNode.removeChild child if child?
roomDom = RoomManager.getDomOfRoom(type + name, room._id)
mainNode.appendChild roomDom
if roomDom.classList.contains('room-container')
roomDom.querySelector('.messages-box > .wrapper').scrollTop = roomDom.oldScrollTop
Session.set 'openedRoom', room._id
Session.set 'editRoomTitle', false
RoomManager.updateMentionsMarksOfRoom type + name
Meteor.setTimeout ->
readMessage.readNow()
, 2000
# KonchatNotification.removeRoomNotification(params._id)
if Meteor.Device.isDesktop()
setTimeout ->
$('.message-form .input-message').focus()
, 100
RocketChat.TabBar.resetButtons()
RocketChat.TabBar.addButton({ id: 'message-search', title: t('Search'), icon: 'octicon octicon-search', template: 'messageSearch', order: 1 })
if type is 'd'
RocketChat.TabBar.addButton({ id: 'members-list', title: t('User_Info'), icon: 'octicon octicon-person', template: 'membersList', order: 2 })
else
RocketChat.TabBar.addButton({ id: 'members-list', title: t('Members_List'), icon: 'octicon octicon-organization', template: 'membersList', order: 2 })
RocketChat.TabBar.addButton({ id: 'uploaded-files-list', title: t('Room_uploaded_file_list'), icon: 'octicon octicon-file-symlink-directory', template: 'uploadedFilesList', order: 3 })
# update user's room subscription
if ChatSubscription.findOne({rid: room._id})?.open is false
Meteor.call 'openRoom', room._id
RocketChat.callbacks.run 'enter-room'
@roomExit = ->
BlazeLayout.render 'main', {center: 'none'}
if currentTracker?
currentTracker.stop()
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
if child?
if child.classList.contains('room-container')
wrapper = child.querySelector('.messages-box > .wrapper')
if wrapper.scrollTop >= wrapper.scrollHeight - wrapper.clientHeight
child.oldScrollTop = 10e10
else
child.oldScrollTop = wrapper.scrollTop
mainNode.removeChild child
RocketChat.roomTypes = new class
rooms = []
routes = {}
publishes = {}
### Sets a route for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
......@@ -39,7 +40,29 @@ RocketChat.roomTypes = new class
getAllTypes = ->
return rooms
### add a publish for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
@param callback: function that will return the publish's data
###
addPublish = (roomType, callback) ->
if publishes[roomType]?
throw new Meteor.Error 'route-publish-exists', 'Publish for the given type already exists'
publishes[roomType] = callback
### run the publish for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
@param identifier: identifier of the room
###
runPublish = (roomType, identifier) ->
return unless publishes[roomType]?
return publishes[roomType].call this, identifier
addType: addType
getTypes: getAllTypes
setRoute: setRoute
getRoute: getRoute
addPublish: addPublish
publish: runPublish
......@@ -21,6 +21,7 @@ Package.onUse(function(api) {
// COMMON
api.addFiles('lib/core.coffee');
api.addFiles('lib/callbacks.coffee');
api.addFiles('lib/roomTypes.coffee');
api.addFiles('lib/slashCommand.coffee');
// MODELS SERVER
......@@ -45,7 +46,8 @@ Package.onUse(function(api) {
api.addFiles('settings/lib/settings.coffee');
// CLIENT
api.addFiles('client/lib/roomTypes.coffee', 'client');
api.addFiles('client/lib/openRoom.coffee', 'client');
api.addFiles('client/lib/roomExit.coffee', 'client');
api.addFiles('client/Notifications.coffee', 'client');
api.addFiles('client/TabBar.coffee', 'client');
api.addFiles('client/MessageAction.coffee', 'client');
......
......@@ -10,26 +10,4 @@ Meteor.publish 'room', (typeName) ->
type = typeName.substr(0, 1)
name = typeName.substr(1)
options =
fields:
name: 1
t: 1
cl: 1
u: 1
usernames: 1
switch type
when 'c'
return RocketChat.models.Rooms.findByTypeAndName 'c', name, options
when 'p'
user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
return RocketChat.models.Rooms.findByTypeAndNameContainigUsername 'p', name, user.username, options
when 'd'
user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
return RocketChat.models.Rooms.findByTypeContainigUsername 'd', user.username, options
# Change to validate access manualy
# if not Meteor.call 'canAccessRoom', rid, this.userId
# return this.ready()
return RocketChat.roomTypes.publish.call(this, type, name)
Meteor.startup ->
RocketChat.roomTypes.addPublish 'c', (identifier) ->
options =
fields:
name: 1
t: 1
cl: 1
u: 1
usernames: 1
return RocketChat.models.Rooms.findByTypeAndName 'c', identifier, options
RocketChat.roomTypes.addPublish 'p', (identifier) ->
options =
fields:
name: 1
t: 1
cl: 1
u: 1
usernames: 1
user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
return RocketChat.models.Rooms.findByTypeAndNameContainigUsername 'p', identifier, user.username, options
RocketChat.roomTypes.addPublish 'd', (identifier) ->
options =
fields:
name: 1
t: 1
cl: 1
u: 1
usernames: 1
user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
return RocketChat.models.Rooms.findByTypeContainigUsername 'd', user.username, options
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