Replace all ChatMessage.findOne

pull/822/head
Rodrigo Nascimento 10 years ago
parent bb65dd5688
commit 8dedb22795
  1. 1
      packages/rocketchat-lib/package.js
  2. 59
      packages/rocketchat-lib/server/models/Messages.coffee
  3. 4
      server/methods/deleteMessage.coffee
  4. 4
      server/methods/pinMessage.coffee
  5. 4
      server/methods/unpinMessage.coffee
  6. 4
      server/methods/updateMessage.coffee

@ -71,6 +71,7 @@ Package.onUse(function(api) {
api.addFiles('server/models/Users.coffee', 'server');
api.addFiles('server/models/Subscriptions.coffee', 'server');
api.addFiles('server/models/Rooms.coffee', 'server');
api.addFiles('server/models/Messages.coffee', 'server');
// TAPi18n -- needs to be added last
api.addFiles(tapi18nFiles, ["client", "server"]);

@ -0,0 +1,59 @@
RocketChat.models.Messages = new class asd extends RocketChat.models._Base
constructor: ->
# @model = new Meteor.Collection 'rocketchat_message'
@model = @ChatMessage
# @tryEnsureIndex { 'name': 1 }, { unique: 1, sparse: 1 }
# @tryEnsureIndex { 'u._id': 1 }
# FIND ONE
findOneById: (_id, options) ->
query =
_id: _id
return @findOne query, options
# # FIND
# findByType: (type, options) ->
# query =
# t: type
# return @find query, options
# # UPDATE
# archiveById: (_id) ->
# query =
# _id: _id
# update =
# $set:
# archived: true
# return @update query, update
# # INSERT
# createWithTypeNameUserAndUsernames: (type, name, user, usernames, extraData) ->
# room =
# t: type
# name: name
# usernames: usernames
# msgs: 0
# u:
# _id: user._id
# username: user.username
# _.extend room, extraData
# room._id = @insert room
# return room
# # REMOVE
# removeById: (_id) ->
# query =
# _id: _id
# return @remove query

@ -3,7 +3,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] deleteMessage -> Invalid user")
originalMessage = ChatMessage.findOne message._id, {fields: {u: 1, rid: 1}}
originalMessage = RocketChat.models.Messages.findOneById message._id, {fields: {u: 1, rid: 1}}
if not originalMessage?
throw new Meteor.Error 'message-deleting-not-allowed', "[methods] deleteMessage -> Message with id [#{message._id} dos not exists]"
@ -25,7 +25,7 @@ Meteor.methods
if keepHistory
if showDeletedStatus
history = ChatMessage.findOne originalMessage._id
history = RocketChat.models.Messages.findOneById originalMessage._id
history._hidden = true
history.parent = history._id
history.ets = new Date()

@ -10,7 +10,7 @@ Meteor.methods
# If we keep history of edits, insert a new message to store history information
if RocketChat.settings.get 'Message_KeepHistory'
history = ChatMessage.findOne message._id
history = RocketChat.models.Messages.findOneById message._id
history._hidden = true
history.parent = history._id
history.pts = new Date()
@ -32,4 +32,4 @@ Meteor.methods
# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
# RocketChat.callbacks.run 'afterSaveMessage', RocketChat.models.Messages.findOneById(message.id)

@ -10,7 +10,7 @@ Meteor.methods
# If we keep history of edits, insert a new message to store history information
if RocketChat.settings.get 'Message_KeepHistory'
history = ChatMessage.findOne message._id
history = RocketChat.models.Messages.findOneById message._id
history._hidden = true
history.parent = history._id
history.pts = new Date()
@ -32,4 +32,4 @@ Meteor.methods
# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
# RocketChat.callbacks.run 'afterSaveMessage', RocketChat.models.Messages.findOneById(message.id)

@ -3,7 +3,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] updateMessage -> Invalid user")
originalMessage = ChatMessage.findOne message._id
originalMessage = RocketChat.models.Messages.findOneById message._id
hasPermission = RocketChat.authz.hasPermission(Meteor.userId(), 'edit-message', message.rid)
editAllowed = RocketChat.settings.get 'Message_AllowEditing'
@ -38,5 +38,5 @@ Meteor.methods
$set: message
# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
# RocketChat.callbacks.run 'afterSaveMessage', RocketChat.models.Messages.findOneById(message.id)

Loading…
Cancel
Save