diff --git a/server/publications.coffee b/server/publications.coffee deleted file mode 100644 index bb91e556c3e..00000000000 --- a/server/publications.coffee +++ /dev/null @@ -1,159 +0,0 @@ -# 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() diff --git a/server/publications/allUsers.coffee b/server/publications/allUsers.coffee new file mode 100644 index 00000000000..df0a8b10310 --- /dev/null +++ b/server/publications/allUsers.coffee @@ -0,0 +1,15 @@ +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 diff --git a/server/publications/dashboardRoom.coffee b/server/publications/dashboardRoom.coffee new file mode 100644 index 00000000000..146ccf20c3f --- /dev/null +++ b/server/publications/dashboardRoom.coffee @@ -0,0 +1,15 @@ +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 diff --git a/server/publications/myRoomActivity.coffee b/server/publications/myRoomActivity.coffee new file mode 100644 index 00000000000..1bab04dc9df --- /dev/null +++ b/server/publications/myRoomActivity.coffee @@ -0,0 +1,18 @@ +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() } } + diff --git a/server/publications/privateHistoryRooms.coffee b/server/publications/privateHistoryRooms.coffee new file mode 100644 index 00000000000..e895d3a2cae --- /dev/null +++ b/server/publications/privateHistoryRooms.coffee @@ -0,0 +1,17 @@ +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 + diff --git a/server/publications/roomSearch.coffee b/server/publications/roomSearch.coffee new file mode 100644 index 00000000000..39babd60298 --- /dev/null +++ b/server/publications/roomSearch.coffee @@ -0,0 +1,41 @@ +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() diff --git a/server/publications/selectiveUsers.coffee b/server/publications/selectiveUsers.coffee new file mode 100644 index 00000000000..cf9cfc8209d --- /dev/null +++ b/server/publications/selectiveUsers.coffee @@ -0,0 +1,34 @@ +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() + diff --git a/server/publications/userData.coffee b/server/publications/userData.coffee new file mode 100644 index 00000000000..960237d2077 --- /dev/null +++ b/server/publications/userData.coffee @@ -0,0 +1,14 @@ +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