Enable edit and delete messages based on settings

pull/495/head
Marcelo Schmidt 11 years ago
parent 8dcdddef8b
commit eb6d49a0eb
  1. 4
      client/stylesheets/base.less
  2. 11
      client/views/app/message.coffee
  3. 4
      client/views/app/message.html
  4. 4
      client/views/settings/settings.coffee
  5. 2
      i18n/en.i18n.json
  6. 39
      server/methods/deleteMessage.coffee
  7. 5
      server/methods/loadHistory.coffee
  8. 2
      server/methods/updateMessage.coffee
  9. 13
      server/publications/messages.coffee
  10. 2
      server/restapi/restapi.coffee
  11. 2
      server/startup/indexes.coffee
  12. 5
      server/stream/messages.coffee

@ -2186,14 +2186,14 @@ a.github-fork {
display: none;
cursor: pointer;
}
&.own:hover .edit-message {
&.own:hover:not(.system) .edit-message {
display: inline-block;
}
.delete-message {
display: none;
cursor: pointer;
}
&.own:hover .delete-message {
&.own:hover:not(.system) .delete-message {
display: inline-block;
}
.user {

@ -1,7 +1,7 @@
Template.message.helpers
own: ->
return 'own' if this.u?._id is Meteor.userId()
return 'own' if this.u?._id is Meteor.userId()
time: ->
return moment(this.ts).format('HH:mm')
@ -23,8 +23,8 @@ Template.message.helpers
when 'nu' then t('User_added', { user_added: this.u.username })
when 'uj' then t('User_joined_channel', { user: this.u.username })
when 'wm' then t('Welcome', { user: this.u.username })
when 'rtc' then RocketChat.callbacks.run 'renderRtcMessage', this
when 'rm' then t('Message_removed', { user: this.u.username })
when 'rtc' then RocketChat.callbacks.run 'renderRtcMessage', this
else
this.html = this.msg
if _.trim(this.html) isnt ''
@ -35,17 +35,14 @@ Template.message.helpers
system: ->
return 'system' if this.t in ['s', 'p', 'f', 'r', 'au', 'ru', 'ul', 'nu', 'wm', 'uj', 'rm']
edited: ->
return @ets and @t not in ['s', 'p', 'f', 'r', 'au', 'ru', 'ul', 'nu', 'wm', 'uj', 'rm']
canEdit: ->
return RocketChat.settings.get 'Message_AllowEditing'
canDelete: ->
return RocketChat.settings.get 'Message_AllowDeleting'
showEditedStatus: ->
return RocketChat.settings.get 'Message_ShowEditedStatus'
showDeletedStatus: ->
return RocketChat.settings.get 'Message_ShowDeletedStatus'
Template.message.onViewRendered = (context) ->
view = this

@ -4,11 +4,9 @@
<a class="user user-card-message" href="#" data-username="{{u.username}}" tabindex="1">{{u.username}}</a>
<span class="info">
<span class="time">{{time}}</span>
{{#if ets}}
{{#if showEditedStatus}}
{{#if edited}}
<span class="edited">({{_ "edited"}})</span>
{{/if}}
{{/if}}
{{#if canEdit}}
<i class="icon-pencil edit-message"></i>
{{/if}}

@ -42,8 +42,8 @@ Template.settings.events
if not _.isEmpty updateSettings
RocketChat.settings.batchSet updateSettings, (err, success) ->
return toastr.error TAPi18next.t 'Error_updating_settings' if err
toastr.success TAPi18next.t 'Settings_updated'
return toastr.error TAPi18next.t 'project:Error_updating_settings' if err
toastr.success TAPi18next.t 'project:Settings_updated'
Template.settings.onRendered ->
Tracker.afterFlush ->

@ -102,7 +102,7 @@
"Message" : "Message",
"Message_AllowDeleting" : "Allow Message Deleting",
"Message_AllowEditing" : "Allow Message Editing",
"Message_KeepHistory" : "Keep Status History",
"Message_KeepHistory" : "Keep Message History",
"Message_removed" : "Message removed",
"Message_ShowDeletedStatus" : "Show Deleted Status",
"Message_ShowEditedStatus" : "Show Edited Status",

@ -5,8 +5,39 @@ Meteor.methods
console.log '[methods] deleteMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
ChatMessage.remove
_id: message._id
'u._id': Meteor.userId()
keepHistory = RocketChat.settings.get 'Message_KeepHistory'
showDeletedStatus = RocketChat.settings.get 'Message_ShowDeletedStatus'
deleteMsgStream.emit message.rid, { _id: message._id }
if keepHistory
if showDeletedStatus
history = ChatMessage.findOne message._id
history._hidden = true
history.parent = history._id
history.ets = new Date()
delete history._id
ChatMessage.insert history
else
ChatMessage.update
_id: message._id
'u._id': Meteor.userId()
,
$set:
_hidden: true
else
if not showDeletedStatus
ChatMessage.remove
_id: message._id
'u._id': Meteor.userId()
if showDeletedStatus
ChatMessage.update
_id: message._id
'u._id': Meteor.userId()
,
$set:
msg: ''
t: 'rm'
ets: new Date()
else
deleteMsgStream.emit message.rid, { _id: message._id }

@ -7,7 +7,7 @@ Meteor.methods
return false
query =
_history: { $ne: true }
_hidden: { $ne: true }
rid: rid
ts:
$lt: end
@ -18,4 +18,7 @@ Meteor.methods
limit: limit
skip: skip
if not RocketChat.settings.get 'Message_ShowEditedStatus'
options.fields = { ets: 0 }
return ChatMessage.find(query, options).fetch()

@ -8,7 +8,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._history = true
history._hidden = true
history.parent = history._id
history.ets = new Date()
delete history._id

@ -14,9 +14,7 @@ Meteor.publish 'messages', (rid, start) ->
cursor = ChatMessage.find
rid: rid
_deleted:
$ne: true
_history:
_hidden:
$ne: true
,
sort:
@ -25,24 +23,23 @@ Meteor.publish 'messages', (rid, start) ->
cursorHandle = cursor.observeChanges
added: (_id, record) ->
if record._history isnt true
publication.added('rocketchat_message', _id, record)
publication.added('rocketchat_message', _id, record)
changed: (_id, record) ->
publication.changed('rocketchat_message', _id, record)
cursorDelete = ChatMessage.find
rid: rid
_deleted: true
_hidden: true
,
fields:
_id: 1
cursorDeleteHandle = cursorDelete.observeChanges
added: (_id, record) ->
publication.added('rocketchat_message', _id, {_deleted: true})
publication.added('rocketchat_message', _id, {_hidden: true})
changed: (_id, record) ->
publication.added('rocketchat_message', _id, {_deleted: true})
publication.added('rocketchat_message', _id, {_hidden: true})
@ready()
@onStop ->

@ -35,7 +35,7 @@ Api.addRoute 'rooms/:id/messages', authRequired: true,
get: ->
try
if Meteor.call('canAccessRoom', @urlParams.id, this.userId)
msgs = ChatMessage.find({rid: @urlParams.id, _deleted: {$ne: true}, _history: {$ne: true}}, {sort: {ts: -1}}, {limit: 50}).fetch()
msgs = ChatMessage.find({rid: @urlParams.id, _hidden: {$ne: true}}, {sort: {ts: -1}}, {limit: 50}).fetch()
status: 'success', messages: msgs
else
statusCode: 403 # forbidden

@ -14,4 +14,4 @@ Meteor.startup ->
try ChatMessage._ensureIndex { 'ets': 1 }, { sparse: 1 } catch e then console.log e
try ChatMessage._ensureIndex { 'rid': 1, 't': 1, 'u._id': 1 } catch e then console.log e
try ChatMessage._ensureIndex { 'expireAt': 1 }, { expireAfterSeconds: 0 } catch e then console.log e
try ChatMessage._ensureIndex { '_deleted': 1 }, { sparse: 1 } catch e then console.log e
try ChatMessage._ensureIndex { '_hidden': 1 }, { sparse: 1 } catch e then console.log e

@ -33,7 +33,7 @@ deleteMsgStream.permissions.read (eventName) ->
Meteor.startup ->
filter =
_history: { $ne: true }
_hidden: { $ne: true }
$or: [
ts:
$gt: new Date()
@ -44,6 +44,9 @@ Meteor.startup ->
options = {}
if not RocketChat.settings.get 'Message_ShowEditedStatus'
options.fields = { ets: 0 }
ChatMessage.find(filter, options).observe
added: (record) ->
msgStream.emit record.rid, record

Loading…
Cancel
Save