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

[NEW] Update message actions #14268

Merged
merged 11 commits into from
Apr 27, 2019
31 changes: 28 additions & 3 deletions app/autotranslate/client/lib/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Meteor.startup(function() {
Tracker.autorun(function() {
if (settings.get('AutoTranslate_Enabled') && hasAtLeastOnePermission(['auto-translate'])) {
MessageAction.addButton({
id: 'toggle-language',
id: 'translate',
icon: 'language',
label: 'Toggle_original_translated',
label: 'Translate',
context: [
'message',
'message-mobile',
Expand All @@ -30,7 +30,32 @@ Meteor.startup(function() {
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition(message) {
return message && message.u && message.u._id !== Meteor.userId();
return message && message.u && message.u._id !== Meteor.userId() && message.translations && !message.translations.original;
},
order: 90,
});
MessageAction.addButton({
id: 'view-original',
icon: 'language',
label: 'View_original',
context: [
'message',
'message-mobile',
],
action() {
const { msg: message } = messageArgs(this);
const language = AutoTranslate.getLanguage(message.rid);
if ((!message.translations || !message.translations[language])) { // } && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
AutoTranslate.messageIdsToWait[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
}
const action = message.autoTranslateShowInverse ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition(message) {
return message && message.u && message.u._id !== Meteor.userId() && message.translations && message.translations.original;

},
order: 90,
});
Expand Down
4 changes: 2 additions & 2 deletions app/message-mark-as-unread/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Meteor.startup(() => {
MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'flag',
label: 'Mark_as_unread',
label: 'Mark_unread',
context: ['message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
Expand All @@ -30,7 +30,7 @@ Meteor.startup(() => {
condition(message) {
return Meteor.userId() && message.u._id !== Meteor.userId();
},
order: 22,
order: 10,
group: 'menu',
});
});
10 changes: 5 additions & 5 deletions app/message-pin/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Meteor.startup(function() {
MessageAction.addButton({
id: 'pin-message',
icon: 'pin',
label: 'Pin_Message',
label: 'Pin',
context: ['pinned', 'message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
Expand All @@ -31,14 +31,14 @@ Meteor.startup(function() {

return hasAtLeastOnePermission('pin-message', message.rid);
},
order: 20,
order: 7,
group: 'menu',
});

MessageAction.addButton({
id: 'unpin-message',
icon: 'pin',
label: 'Unpin_Message',
label: 'Unpin',
context: ['pinned', 'message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
Expand All @@ -56,7 +56,7 @@ Meteor.startup(function() {

return hasAtLeastOnePermission('pin-message', message.rid);
},
order: 21,
order: 8,
group: 'menu',
});

Expand Down Expand Up @@ -85,7 +85,7 @@ Meteor.startup(function() {
MessageAction.addButton({
id: 'permalink-pinned',
icon: 'permalink',
label: 'Permalink',
label: 'Get_link',
classes: 'clipboard',
context: ['pinned'],
async action(event) {
Expand Down
137 changes: 69 additions & 68 deletions app/message-snippet/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
import { Meteor } from 'meteor/meteor';
import { MessageAction, modal } from '../../ui-utils';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
import { t, handleError } from '../../utils';
import { settings } from '../../settings';
import { Subscriptions } from '../../models';
import { hasAtLeastOnePermission } from '../../authorization';

Meteor.startup(function() {
MessageAction.addButton({
id: 'snippeted-message',
icon: 'code',
label: 'Snippet',
context: [
'snippeted',
'message',
'message-mobile',
],
order: 10,
group: 'menu',
action() {
const { msg: message } = messageArgs(this);

modal.open({
title: 'Create a Snippet',
text: 'The name of your snippet (with file extension):',
type: 'input',
showCancelButton: true,
closeOnConfirm: false,
inputPlaceholder: 'Snippet name',
}, function(filename) {
if (filename === false) {
return false;
}
if (filename === '') {
modal.showInputError('You need to write something!');
return false;
}
message.snippeted = true;
Meteor.call('snippetMessage', message, filename, function(error) {
if (error) {
return handleError(error);
}
modal.open({
title: t('Nice'),
text: `Snippet '${ filename }' created.`,
type: 'success',
timer: 2000,
});
});
});

},
condition(message) {
if (Subscriptions.findOne({ rid: message.rid, 'u._id': Meteor.userId() }) === undefined) {
return false;
}

if (message.snippeted || ((settings.get('Message_AllowSnippeting') === undefined) ||
(settings.get('Message_AllowSnippeting') === null) ||
(settings.get('Message_AllowSnippeting')) === false)) {
return false;
}

return hasAtLeastOnePermission('snippet-message', message.rid);
},
});
});
// import { Meteor } from 'meteor/meteor';
// import { MessageAction, modal } from '../../ui-utils';
// import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
// import { t, handleError } from '../../utils';
// import { settings } from '../../settings';
// import { Subscriptions } from '../../models';
// import { hasAtLeastOnePermission } from '../../authorization';
//
// Meteor.startup(function() {
// MessageAction.addButton({
// id: 'snippeted-message',
// icon: 'code',
// label: 'Snippet',
// context: [
// 'snippeted',
// 'message',
// 'message-mobile',
// ],
// order: 10,
// group: 'menu',
// action() {
// const { msg: message } = messageArgs(this);
//
// modal.open({
// title: 'Create a Snippet',
// text: 'The name of your snippet (with file extension):',
// type: 'input',
// showCancelButton: true,
// closeOnConfirm: false,
// inputPlaceholder: 'Snippet name',
// }, function(filename) {
// if (filename === false) {
// return false;
// }
// if (filename === '') {
// modal.showInputError('You need to write something!');
// return false;
// }
// message.snippeted = true;
// Meteor.call('snippetMessage', message, filename, function(error) {
// if (error) {
// return handleError(error);
// }
// modal.open({
// title: t('Nice'),
// text: `Snippet '${ filename }' created.`,
// type: 'success',
// timer: 2000,
// });
// });
// });
//
// },
// condition(message) {
// if (Subscriptions.findOne({ rid: message.rid, 'u._id': Meteor.userId() }) === undefined) {
// return false;
// }
//
// if (message.snippeted || ((settings.get('Message_AllowSnippeting') === undefined) ||
// (settings.get('Message_AllowSnippeting') === null) ||
// (settings.get('Message_AllowSnippeting')) === false)) {
// return false;
// }
//
// return hasAtLeastOnePermission('snippet-message', message.rid);
// },
// });
//
// });
8 changes: 4 additions & 4 deletions app/message-star/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Meteor.startup(function() {
MessageAction.addButton({
id: 'star-message',
icon: 'star',
label: 'Star_Message',
label: 'Star',
context: ['starred', 'message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
Expand All @@ -29,7 +29,7 @@ Meteor.startup(function() {

return !message.starred || !message.starred.find((star) => star._id === Meteor.userId());
},
order: 10,
order: 9,
group: 'menu',
});

Expand All @@ -54,7 +54,7 @@ Meteor.startup(function() {

return message.starred && message.starred.find((star) => star._id === Meteor.userId());
},
order: 10,
order: 9,
group: 'menu',
});

Expand Down Expand Up @@ -83,7 +83,7 @@ Meteor.startup(function() {
MessageAction.addButton({
id: 'permalink-star',
icon: 'permalink',
label: 'Permalink',
label: 'Get_link',
classes: 'clipboard',
context: ['starred'],
async action(event) {
Expand Down
2 changes: 2 additions & 0 deletions app/threads/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import './flextab/threads';
import './threads.css';
import './messageAction/follow';
import './messageAction/unfollow';
import './messageAction/replyInThread';

2 changes: 1 addition & 1 deletion app/threads/client/messageAction/follow.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Meteor.startup(function() {
id: 'follow-message',
icon: 'bell',
label: 'Follow_message',
context: ['message', 'message-mobile', 'threads'],
context: ['threads'],
async action() {
const { msg } = messageArgs(this);
call('followMessage', { mid: msg._id });
Expand Down
41 changes: 41 additions & 0 deletions app/threads/client/messageAction/replyInThread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { settings } from '../../../settings/client';
import { MessageAction } from '../../../ui-utils/client';
import { messageArgs } from '../../../ui-utils/client/lib/messageArgs';
import { chatMessages } from '../../../ui/client';
import { addMessageToList } from '../../../ui-utils/client/lib/MessageAction';
import { Subscriptions } from '../../../models/client';

Meteor.startup(function() {
Tracker.autorun(() => {
if (!settings.get('Threads_enabled')) {
return MessageAction.removeButton('reply-in-thread');
}
MessageAction.addButton({
id: 'reply-in-thread',
icon: 'thread',
label: 'Reply_in_thread',
context: ['message', 'message-mobile', 'threads'],
action() {
const { msg: message } = messageArgs(this);
const { input } = chatMessages[message.rid];
const $input = $(input);

const messages = addMessageToList($input.data('reply') || [], message, input);

$(input)
.focus()
.data('mention-user', true)
.data('reply', messages)
.trigger('dataChange');
},
condition(message) {
return Boolean(Subscriptions.findOne({ rid: message.rid }));
},
order: 1,
group: 'menu',
});
});
});
2 changes: 1 addition & 1 deletion app/threads/client/messageAction/unfollow.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Meteor.startup(function() {
id: 'unfollow-message',
icon: 'bell-off',
label: 'Unfollow_message',
context: ['message', 'message-mobile', 'threads'],
context: ['threads'],
async action() {
const { msg } = messageArgs(this);
call('unfollowMessage', { mid: msg._id });
Expand Down
3 changes: 3 additions & 0 deletions app/ui-master/public/icons/discussion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/ui-master/public/icons/reply-directly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/ui-master/public/icons/report.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions app/ui-message/client/messageBox/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Template.messageBox.onCreated(function() {
});

Template.messageBox.onRendered(function() {
const $input = $(this.find('.js-input-message'));
$input.on('dataChange', () => {
const messages = $input.data('reply') || [];
this.replyMessageData.set(messages);
});
this.autorun(() => {
const { rid, subscription } = Template.currentData();
const room = Session.get(`roomData${ rid }`);
Expand Down Expand Up @@ -156,12 +161,6 @@ Template.messageBox.onRendered(function() {

const shadow = this.find('.js-input-message-shadow');
this.autogrow = setupAutogrow(input, shadow, onResize);

const $input = $(input);
$input.on('dataChange', () => {
const messages = $input.data('reply') || [];
this.replyMessageData.set(messages);
});
});
});
});
Expand Down
Loading