Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented delete button next to edit and modal confirmation #228

Merged
merged 4 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ todda00:friendly-slugs
underscorestring:underscore.string
yasaricli:slugify
konecty:nrr
kevohagan:sweetalert
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jparker:[email protected]
jparker:[email protected]
[email protected]_2
[email protected]
kevohagan:[email protected]
konecty:[email protected]
konecty:[email protected]
konecty:[email protected]
Expand Down
7 changes: 7 additions & 0 deletions client/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
stopTyping()
Meteor.call 'sendMessage', { rid: rid, msg: msg, day: window.day }

deleteMsg = (element) ->
id = element.getAttribute("id")
Meteor.call 'deleteMessage', { id: id }, (error, result) ->
if error
return Errors.throw error.reason

update = (id, input) ->
if _.trim(input.value) isnt ''
msg = input.value
Expand Down Expand Up @@ -171,6 +177,7 @@
# isScrollable: isScrollable
# toBottom: toBottom
keydown: keydown
deleteMsg: deleteMsg
send: send
init: init
edit: edit
Expand Down
3 changes: 3 additions & 0 deletions client/lib/collections.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Meteor.startup ->

changed: (record) ->
ChatMessageHistory.update {_id: record._id, msg: {$ne: record.msg}}, record

removed: (record) ->
ChatMessageHistory.remove {_id: record._id}
10 changes: 10 additions & 0 deletions client/methods/updateMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ Meteor.methods
$set:
ets: message.ets
message: message.msg

deleteMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error 203, t('general.User_logged_out')

Tracker.nonreactive ->

ChatMessage.remove
_id: message.id
'u._id': Meteor.userId()
17 changes: 14 additions & 3 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,13 @@ a.github-fork {
&.own:hover .edit-message {
display: inline-block;
}
.delete-message {
display: none;
cursor: pointer;
}
&.own:hover .delete-message {
display: inline-block;
}
.user {
display: inline-block;
font-weight: 600;
Expand Down Expand Up @@ -1989,8 +1996,8 @@ a.github-fork {
.info {
position: absolute;
text-align: right;
left: -15px;
width: 55px;
left: -20px;
width: 65px;
.time {
display: none;
}
Expand All @@ -1999,8 +2006,12 @@ a.github-fork {
}
.edit-message {
float: left;
margin-left: 5px;
margin-left: 1px;
}
.delete-message {
float: left;
}

}
&:hover {
.time {
Expand Down
1 change: 1 addition & 0 deletions client/views/app/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<span class="edited">({{_ "edited"}})</span>
{{/if}}
<i class="icon-pencil edit-message"></i>
<i class="icon-trash-1 delete-message"></i>
</span>
<div class="body" dir="auto">
{{{body}}}
Expand Down
17 changes: 17 additions & 0 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ Template.room.events
Session.set('flexOpened', true)
Session.set('showUserInfo', $(e.currentTarget).data('username'))

'click .delete-message': (event) ->
msg = event.currentTarget.parentNode.parentNode
return if msg.classList.contains("system")
swal {
title: t('Are_you_sure')
text: t('You_will_not_be_able_to_recover')
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: t('Yes_delete_it')
cancelButtonText: t('Cancel')
closeOnConfirm: false
html: false
}, ->
swal t('Deleted'), t('Your_entry_has_been_deleted'), 'success'
ChatMessages.deleteMsg(msg)

Template.room.onCreated ->
console.log 'room.onCreated' if window.rocketDebug
# this.scrollOnBottom = true
Expand Down
7 changes: 6 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"and" : "and",
"are_also_typing" : "are also typing",
"are_typing" : "are typing",
"Are_you_sure" : "Are you sure?",
"away" : "away",
"Away" : "Away",
"busy" : "busy",
Expand All @@ -29,6 +30,7 @@
"Create_new_private_group" : "Create a new private group",
"Created_at" : "Created at",
"Direct_Messages" : "Direct Messages",
"Deleted" : "Deleted!",
"edited" : "edited",
"Email_or_username" : "Email or username",
"Email_verified" : "Email verified",
Expand Down Expand Up @@ -146,5 +148,8 @@
"Welcome_to_the" : "Welcome to the",
"you_are_in_preview_mode_of" : "You are in preview mode of channel #<strong>__room_name__</strong>",
"You_neeed_confirm_email" : "You need to confirm your email to login!",
"Your_Open_Source_solution" : "Your own Open Source chat solution"
"Your_Open_Source_solution" : "Your own Open Source chat solution",
"You_will_not_be_able_to_recover" : "You will not be able to recover!",
"Yes_delete_it" : "Yes, delete it!",
"Your_entry_has_been_deleted" : "Your entry has been deleted."
}
10 changes: 10 additions & 0 deletions server/methods/updateMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ Meteor.methods
Meteor.defer ->

RocketChat.callbacks.run 'afterSaveMessage', message

deleteMessage: (message) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] deleteMessage -> Invalid user")

console.log '[methods] deleteMessage -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

ChatMessage.remove
_id: message.id
'u._id': Meteor.userId