Skip to content
Snippets Groups Projects
Commit 73fd2429 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

moving publications into single files

parent e2c345df
No related branches found
No related tags found
No related merge requests found
# publish do usuário logado
Meteor.publish 'userData', ->
unless this.userId
return this.ready()
# console.log '[publish] userData'.green
Meteor.users.find this.userId,
fields:
name: 1
username: 1
status: 1
statusDefault: 1
statusConnection: 1
avatarOrigin: 1
Meteor.publish 'myRoomActivity', ->
unless this.userId
return this.ready()
# console.log '[publish] myRoomActivity'.green
# @TODO está deixando lento fazer o relation com usuários
return Meteor.publishWithRelations
handle: this
collection: ChatSubscription
filter: { 'u._id': this.userId, $or: [ { ts: { $gte: moment().subtract(1, 'days').startOf('day').toDate() } }, { f: true } ] }
mappings: [
key: 'rid'
reverse: false
collection: ChatRoom
]
# return ChatSubscription.find { uid: this.userId, ts: { $gte: moment().subtract(2, 'days').startOf('day').toDate() } }
Meteor.publish 'dashboardRoom', (rid, start) ->
self = this
unless this.userId
return this.ready()
# console.log '[publish] dashboardRoom ->'.green, 'rid:', rid, 'start:', start
if typeof rid isnt 'string'
return this.ready()
return ChatMessage.find {rid: rid}, {sort: {ts: -1}, limit: 50}
# cursor = ChatMessage.find {rid: rid}, {sort: {ts: -1}, limit: 50}
# observer = cursor.observeChanges
# added: (id, record) ->
# self.added 'data.ChatMessage', id, record
# changed: (id, record) ->
# self.changed 'data.ChatMessage', id, record
# removed: (id) ->
# self.removed 'ChatMessage', id
# @ready()
# @onStop ->
# observer.stop()
Meteor.publish 'allUsers', ->
unless this.userId
return this.ready()
# console.log '[publish] allUsers'.green
return Meteor.users.find {username: {$exists: true}, status: {$in: ['online', 'away', 'busy']}}, { 'fields': {
username: 1
status: 1
}}
Meteor.publish 'selectiveUsers', (usernames) ->
unless @userId
return @ready()
# console.log '[publish] selectiveUsers -> '.green, 'userIds:', userIds
self = @
query =
username: $exists: true
options =
fields:
name: 1
username: 1
status: 1
cursor = Meteor.users.find query, options
observer = cursor.observeChanges
added: (id, record) ->
if usernames[record.username]?
self.added 'users', id, record
changed: (id, record) ->
if usernames[record.username]?
self.changed 'users', id, record
removed: (id) ->
if usernames[record.username]?
self.removed 'users', id
@ready()
@onStop ->
observer.stop()
Meteor.publish 'privateHistoryRooms', ->
unless this.userId
return this.ready()
# console.log '[publish] privateHistoryRooms'.green
return ChatRoom.find { usernames: Meteor.users.findOne(this.userId).username, t: { $in: ['d', 'c'] } }, { fields: { t: 1, name: 1, msgs: 1, ts: 1, lm: 1, cl: 1 } }
Meteor.publish 'roomSearch', (selector, options, collName) ->
unless this.userId
return this.ready()
# console.log '[publish] roomSearch -> '.green, 'selector:', selector, 'options:', options, 'collName:', collName
self = @
subHandleUsers = null
searchType = null
if selector.type
searchType = selector.type
delete selector.type
if not searchType? or searchType is 'u'
subHandleUsers = Meteor.users.find(selector, { limit: 10, fields: { name: 1, username: 1, status: 1 } }).observeChanges
added: (id, fields) ->
data = { type: 'u', uid: id, name: fields.name, username: fields.username, status: fields.status }
self.added("autocompleteRecords", id, data)
changed: (id, fields) ->
self.changed("autocompleteRecords", id, fields)
removed: (id) ->
self.removed("autocompleteRecords", id)
subHandleRooms = null
# @TODO buscar apenas salas de grupo permitidas
roomSelector = _.extend { t: { $in: ['c'] }, usernames: Meteor.users.findOne(this.userId).username }, selector
if not searchType? or searchType is 'r'
subHandleRooms = ChatRoom.find(roomSelector, { limit: 10, fields: { t: 1, name: 1 } }).observeChanges
added: (id, fields) ->
roomData = { type: 'r', t: fields.t, rid: id, name: fields.name }
self.added("autocompleteRecords", id, roomData)
changed: (id, fields) ->
self.changed("autocompleteRecords", id, fields)
removed: (id) ->
self.removed("autocompleteRecords", id)
self.ready()
self.onStop ->
subHandleUsers?.stop()
subHandleRooms?.stop()
Meteor.publish 'allUsers', ->
unless this.userId
return this.ready()
# console.log '[publish] allUsers'.green
Meteor.users.find
username:
$exists: 1
status:
$in: ['online', 'away', 'busy']
,
fields:
username: 1
status: 1
Meteor.publish 'dashboardRoom', (rid, start) ->
unless this.userId
return this.ready()
# console.log '[publish] dashboardRoom ->'.green, 'rid:', rid, 'start:', start
if typeof rid isnt 'string'
return this.ready()
ChatMessage.find
rid: rid
,
sort:
ts: -1
limit: 50
Meteor.publish 'myRoomActivity', ->
unless this.userId
return this.ready()
# console.log '[publish] myRoomActivity'.green
return Meteor.publishWithRelations
handle: this
collection: ChatSubscription
filter: { 'u._id': this.userId, $or: [ { ts: { $gte: moment().subtract(1, 'days').startOf('day').toDate() } }, { f: true } ] }
mappings: [
key: 'rid'
reverse: false
collection: ChatRoom
]
# return ChatSubscription.find { uid: this.userId, ts: { $gte: moment().subtract(2, 'days').startOf('day').toDate() } }
Meteor.publish 'privateHistoryRooms', ->
unless this.userId
return this.ready()
# console.log '[publish] privateHistoryRooms'.green
ChatRoom.find
usernames: Meteor.users.findOne(this.userId).username
,
fields:
t: 1
name: 1
msgs: 1
ts: 1
lm: 1
cl: 1
Meteor.publish 'roomSearch', (selector, options, collName) ->
unless this.userId
return this.ready()
# console.log '[publish] roomSearch -> '.green, 'selector:', selector, 'options:', options, 'collName:', collName
self = this
searchType = null
subHandleUsers = null
subHandleRooms = null
if selector.type
searchType = selector.type
delete selector.type
if not searchType? or searchType is 'u'
subHandleUsers = Meteor.users.find(selector, { limit: 10, fields: { name: 1, username: 1, status: 1 } }).observeChanges
added: (id, fields) ->
data = { type: 'u', uid: id, name: fields.name, username: fields.username, status: fields.status }
self.added("autocompleteRecords", id, data)
changed: (id, fields) ->
self.changed("autocompleteRecords", id, fields)
removed: (id) ->
self.removed("autocompleteRecords", id)
if not searchType? or searchType is 'r'
roomSelector = _.extend { t: { $in: ['c','p'] }, usernames: Meteor.users.findOne(this.userId).username }, selector
subHandleRooms = ChatRoom.find(roomSelector, { limit: 10, fields: { t: 1, name: 1 } }).observeChanges
added: (id, fields) ->
data = { type: 'r', rid: id, name: fields.name, t: fields.t }
self.added("autocompleteRecords", id, data)
changed: (id, fields) ->
self.changed("autocompleteRecords", id, fields)
removed: (id) ->
self.removed("autocompleteRecords", id)
this.ready()
this.onStop ->
subHandleUsers?.stop()
subHandleRooms?.stop()
Meteor.publish 'selectiveUsers', (usernames) ->
unless this.userId
return this.ready()
# console.log '[publish] selectiveUsers -> '.green, 'userIds:', userIds
self = this
query =
username: $exists: true
options =
fields:
name: 1
username: 1
status: 1
cursor = Meteor.users.find query, options
observer = cursor.observeChanges
added: (id, record) ->
if usernames[record.username]?
self.added 'users', id, record
changed: (id, record) ->
if usernames[record.username]?
self.changed 'users', id, record
removed: (id) ->
if usernames[record.username]?
self.removed 'users', id
this.ready()
this.onStop ->
observer.stop()
Meteor.publish 'userData', ->
unless this.userId
return this.ready()
# console.log '[publish] userData'.green
Meteor.users.find this.userId,
fields:
name: 1
username: 1
status: 1
statusDefault: 1
statusConnection: 1
avatarOrigin: 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