Skip to content
Snippets Groups Projects
Commit f03e8844 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Improve urls to use room names

parent a481333b
No related branches found
No related tags found
No related merge requests found
......@@ -92,8 +92,8 @@ Meteor.startup ->
return openedRooms[rid].ready
}
getDomOfRoom = (rid) ->
room = openedRooms[rid]
getDomOfRoom = (id, rid) ->
room = openedRooms[id]
if not room?
return
......
FlowRouter.route '/room/:_id',
name: 'room'
openRoom = (type, name) ->
Session.set 'openedRoom', null
BlazeLayout.render 'main', {center: 'loading'}
Meteor.defer ->
Tracker.autorun (c) ->
if RoomManager.open(type + name).ready() isnt true
return
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?
FlowRouter.go 'home'
return
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
mainNode.removeChild child if child?
room = RoomManager.getDomOfRoom(type + name, room._id)
mainNode.appendChild room
if room.classList.contains('room-container')
room.querySelector('.messages-box > .wrapper').scrollTop = room.oldScrollTop
Session.set 'openedRoom', room._id
Session.set 'editRoomTitle', false
Meteor.call 'readMessages', room._id if Meteor.userId()?
# KonchatNotification.removeRoomNotification(params._id)
if Meteor.Device.isDesktop()
setTimeout ->
$('.message-form .input-message').focus()
, 100
roomExit = ->
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
if child?
if child.classList.contains('room-container')
child.oldScrollTop = child.querySelector('.messages-box > .wrapper').scrollTop
mainNode.removeChild child
FlowRouter.route '/channel/:name',
name: 'channel'
action: (params, queryParams) ->
Session.set 'openedRoom', null
openRoom 'c', params.name
BlazeLayout.render 'main', {center: 'loading'}
triggersExit: [roomExit]
Meteor.defer ->
Tracker.autorun (c) ->
if RoomManager.open(params._id).ready() isnt true
return
c.stop()
FlowRouter.route '/group/:name',
name: 'group'
if not ChatRoom.find(params._id).count()
FlowRouter.go 'home'
return
action: (params, queryParams) ->
openRoom 'p', params.name
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
mainNode.removeChild child if child?
room = RoomManager.getDomOfRoom(params._id)
mainNode.appendChild room
if room.classList.contains('room-container')
room.querySelector('.messages-box > .wrapper').scrollTop = room.oldScrollTop
triggersExit: [roomExit]
Session.set 'openedRoom', params._id
Session.set 'editRoomTitle', false
Meteor.call 'readMessages', params._id if Meteor.userId()?
# KonchatNotification.removeRoomNotification(params._id)
FlowRouter.route '/direct/:username',
name: 'direct'
if Meteor.Device.isDesktop()
setTimeout ->
$('.message-form .input-message').focus()
, 100
action: (params, queryParams) ->
openRoom 'd', params.username
triggersExit: [
->
mainNode = document.querySelector('.main-content')
if mainNode?
for child in mainNode.children
if child?
if child.classList.contains('room-container')
child.oldScrollTop = child.querySelector('.messages-box > .wrapper').scrollTop
mainNode.removeChild child
]
triggersExit: [roomExit]
Meteor.publish 'room', (rid) ->
Meteor.publish 'room', (typeName) ->
unless this.userId
return this.ready()
console.log '[publish] room ->'.green, 'arguments:', arguments
if typeof rid isnt 'string'
if typeof typeName isnt 'string'
return this.ready()
if not Meteor.call 'canAccessRoom', rid, this.userId
return this.ready()
type = typeName.substr(0, 1)
name = typeName.substr(1)
query = {}
if type in ['c', 'p']
query =
t: type
name: name
if type is 'p'
user = Meteor.users.findOne this.userId, fields: username: 1
query.usernames = user.username
else if type is 'd'
user = Meteor.users.findOne this.userId, fields: username: 1
query =
t: 'd'
usernames:
$all: [user.username, name]
# Change to validate access manualy
# if not Meteor.call 'canAccessRoom', rid, this.userId
# return this.ready()
ChatRoom.find
_id: rid
,
console.log query
ChatRoom.find query,
fields:
name: 1
t: 1
......
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