Skip to content
Snippets Groups Projects
Commit b145875b authored by Aaron's avatar Aaron
Browse files

Added pin/unpin message

parent dd44eaa5
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,18 @@ class @ChatMessages
if error
return Errors.throw error.reason
pinMsg: (message) ->
message.pinned = true
Meteor.call 'pinMessage', message, (error, result) ->
if error
return Errors.throw error.reason
unpinMsg: (message) ->
message.pinned = false
Meteor.call 'unpinMessage', message, (error, result) ->
if error
return Errors.throw error.reason
update: (id, rid, input) ->
if _.trim(input.value) isnt ''
msg = input.value
......
Meteor.methods
pinMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'message-pinning-not-allowed', t('Message_pinning_not_allowed')
Tracker.nonreactive ->
message.pts = new Date(Date.now() + TimeSync.serverOffset())
message.pinned = true
message = RocketChat.callbacks.run 'beforeSaveMessage', message
ChatMessage.update
_id: message.id
'u._id': Meteor.userId()
,
$set:
pinned: message.pinned
pts: message.pts
Meteor.methods
unpinMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'message-pinning-not-allowed', t('Message_pinning_not_allowed')
Tracker.nonreactive ->
message.pts = new Date(Date.now() + TimeSync.serverOffset())
message.pinned = false
message = RocketChat.callbacks.run 'beforeSaveMessage', message
ChatMessage.update
_id: message.id
'u._id': Meteor.userId()
,
$set:
pinned: message.pinned
pts: message.pts
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')
......@@ -37,10 +37,14 @@ Template.message.helpers
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']
pinned: ->
return this.pinned
canEdit: ->
return RocketChat.settings.get 'Message_AllowEditing'
canDelete: ->
return RocketChat.settings.get 'Message_AllowDeleting'
canPin: ->
return RocketChat.settings.get 'Message_AllowPinning'
showEditedStatus: ->
return RocketChat.settings.get 'Message_ShowEditedStatus'
......
......@@ -7,6 +7,7 @@
{{#if edited}}
<span class="edited">({{_ "edited"}})</span>
{{/if}}
{{#if canEdit}}
<i class="icon-pencil edit-message"></i>
{{/if}}
......
......@@ -228,7 +228,7 @@ Template.room.helpers
userData = {
username: String(username)
}
return userData
seeAll: ->
......@@ -283,14 +283,14 @@ Template.room.helpers
utc: ->
if @utcOffset?
return "UTC #{@utcOffset}"
phoneNumber: ->
return '' unless @phoneNumber
if @phoneNumber.length > 10
return "(#{@phoneNumber.substr(0,2)}) #{@phoneNumber.substr(2,5)}-#{@phoneNumber.substr(7)}"
else
return "(#{@phoneNumber.substr(0,2)}) #{@phoneNumber.substr(2,4)}-#{@phoneNumber.substr(6)}"
lastLogin: ->
if @lastLogin
return moment(@lastLogin).format('LLL')
......@@ -543,14 +543,22 @@ Template.room.events
closeOnConfirm: false
html: false
}, ->
swal
swal
title: t('Deleted')
text: t('Your_entry_has_been_deleted')
type: 'success'
timer: 1000
showConfirmButton: false
showConfirmButton: false
instance.chatMessages.deleteMsg(message)
'click .pin-message': (event) ->
message = @_arguments[1]
instance = Template.instance()
if message.pinned
instance.chatMessages.unpinMsg(message)
else
instance.chatMessages.pinMsg(message)
'click .start-video': (event) ->
_id = Template.instance().data._id
......@@ -635,7 +643,7 @@ Template.room.events
toastr.success t('User_has_been_deactivated')
if error
toastr.error error.reason
'click .activate': ->
username = Session.get('showUserInfo')
user = Meteor.users.findOne { username: String(username) }
......
......@@ -131,10 +131,13 @@
"Message" : "Message",
"Message_AllowDeleting" : "Allow Message Deleting",
"Message_AllowEditing" : "Allow Message Editing",
"Message_deleting_not_allowed": "Message deleting not allowed",
"Message_editing_not_allowed": "Message editing not allowed",
"Message_AllowPinning" : "Allow Message Pinning",
"Message_deleting_not_allowed" : "Message deleting not allowed",
"Message_editing_not_allowed" : "Message editing not allowed",
"Message_pinning_not_allowed" : "Message pinning not allowed",
"Message_KeepHistory" : "Keep Message History",
"Message_removed" : "Message removed",
"Message_pinned" : "Message pinned",
"Message_ShowDeletedStatus" : "Show Deleted Status",
"Message_ShowEditedStatus" : "Show Edited Status",
"Meta_fb_app_id" : "Facebook APP ID",
......@@ -293,4 +296,4 @@
"You_will_not_be_able_to_recover" : "You will not be able to recover!",
"Your_entry_has_been_deleted" : "Your entry has been deleted.",
"Your_Open_Source_solution" : "Your own Open Source chat solution"
}
\ No newline at end of file
}
......@@ -40,6 +40,7 @@ Meteor.startup ->
RocketChat.settings.addGroup 'Message'
RocketChat.settings.add 'Message_AllowEditing', true, { type: 'boolean', group: 'Message', public: true }
RocketChat.settings.add 'Message_AllowDeleting', true, { type: 'boolean', group: 'Message', public: true }
RocketChat.settings.add 'Message_AllowPinning', true, { type: 'boolean', group: 'Message', public: true }
RocketChat.settings.add 'Message_ShowEditedStatus', true, { type: 'boolean', group: 'Message', public: true }
RocketChat.settings.add 'Message_ShowDeletedStatus', false, { type: 'boolean', group: 'Message', public: true }
RocketChat.settings.add 'Message_KeepHistory', false, { type: 'boolean', group: 'Message', public: true }
......
Meteor.methods
pinMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] pinMessage -> Invalid user")
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'message-pinning-not-allowed', "[methods] pinMessage -> Message pinning not allowed"
console.log '[methods] pinMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
# 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._hidden = true
history.parent = history._id
history.pts = new Date()
delete history._id
ChatMessage.insert history
message.pts = new Date()
message.pinned = true
message = RocketChat.callbacks.run 'beforeSaveMessage', message
ChatMessage.update
_id: message._id
'u._id': Meteor.userId()
,
$set:
pinned: message.pinned
pts : message.pts
# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
Meteor.methods
unpinMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] unpinMessage -> Invalid user")
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'message-pinning-not-allowed', "[methods] unpinMessage -> Message pinning not allowed"
console.log '[methods] unpinMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
# 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._hidden = true
history.parent = history._id
history.pts = new Date()
delete history._id
ChatMessage.insert history
message.pts = new Date()
message.pinned = false
message = RocketChat.callbacks.run 'beforeSaveMessage', message
ChatMessage.update
_id: message._id
'u._id': Meteor.userId()
,
$set:
pinned: message.pinned
pts : message.pts
# Meteor.defer ->
# RocketChat.callbacks.run 'afterSaveMessage', ChatMessage.findOne(message.id)
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