mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
refactor: Move respond/reply methods to compose_actions.js.
This moves respond_to_mention() and reply_with_mention() to compose_actions.js. These methods are basically thin layers on top of compose_actions.start().
This commit is contained in:
@@ -24,10 +24,8 @@ var compose_actions = require('js/compose_actions.js');
|
|||||||
var start = compose_actions.start;
|
var start = compose_actions.start;
|
||||||
var cancel = compose_actions.cancel;
|
var cancel = compose_actions.cancel;
|
||||||
var get_focus_area = compose_actions._get_focus_area;
|
var get_focus_area = compose_actions._get_focus_area;
|
||||||
var respond_to_message = global.compose.respond_to_message;
|
var respond_to_message = compose_actions.respond_to_message;
|
||||||
var reply_with_mention = global.compose.reply_with_mention;
|
var reply_with_mention = compose_actions.reply_with_mention;
|
||||||
|
|
||||||
set_global('compose_actions', compose_actions); // This is hacky--we'll fix in the next commit.
|
|
||||||
|
|
||||||
set_global('reload', {
|
set_global('reload', {
|
||||||
is_in_progress: return_false,
|
is_in_progress: return_false,
|
||||||
|
|||||||
@@ -217,11 +217,11 @@ function stubbing(func_name_to_stub, test_function) {
|
|||||||
|
|
||||||
// TODO: Similar check for being in the subs page
|
// TODO: Similar check for being in the subs page
|
||||||
|
|
||||||
assert_mapping('@', 'compose.reply_with_mention');
|
assert_mapping('@', 'compose_actions.reply_with_mention');
|
||||||
assert_mapping('*', 'message_flags.toggle_starred');
|
assert_mapping('*', 'message_flags.toggle_starred');
|
||||||
assert_mapping('+', 'reactions.toggle_reaction');
|
assert_mapping('+', 'reactions.toggle_reaction');
|
||||||
assert_mapping('r', 'compose.respond_to_message');
|
assert_mapping('r', 'compose_actions.respond_to_message');
|
||||||
assert_mapping('R', 'compose.respond_to_message', true);
|
assert_mapping('R', 'compose_actions.respond_to_message', true);
|
||||||
assert_mapping('j', 'navigate.down');
|
assert_mapping('j', 'navigate.down');
|
||||||
assert_mapping('J', 'navigate.page_down');
|
assert_mapping('J', 'navigate.page_down');
|
||||||
assert_mapping('k', 'navigate.up');
|
assert_mapping('k', 'navigate.up');
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ $(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_msg_list.select_id(id);
|
current_msg_list.select_id(id);
|
||||||
compose.respond_to_message({trigger: 'message click'});
|
compose_actions.respond_to_message({trigger: 'message click'});
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
popovers.hide_all();
|
popovers.hide_all();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,58 +389,6 @@ exports.enter_with_preview_open = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.respond_to_message = function (opts) {
|
|
||||||
var message;
|
|
||||||
var msg_type;
|
|
||||||
// Before initiating a reply to a message, if there's an
|
|
||||||
// in-progress composition, snapshot it.
|
|
||||||
drafts.update_draft();
|
|
||||||
|
|
||||||
message = current_msg_list.selected_message();
|
|
||||||
|
|
||||||
if (message === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unread_ops.mark_message_as_read(message);
|
|
||||||
|
|
||||||
var stream = '';
|
|
||||||
var subject = '';
|
|
||||||
if (message.type === "stream") {
|
|
||||||
stream = message.stream;
|
|
||||||
subject = message.subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pm_recipient = message.reply_to;
|
|
||||||
if (message.type === "private") {
|
|
||||||
if (opts.reply_type === "personal") {
|
|
||||||
// reply_to for private messages is everyone involved, so for
|
|
||||||
// personals replies we need to set the private message
|
|
||||||
// recipient to just the sender
|
|
||||||
pm_recipient = people.get_person_from_user_id(message.sender_id).email;
|
|
||||||
} else {
|
|
||||||
pm_recipient = people.pm_reply_to(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (opts.reply_type === 'personal' || message.type === 'private') {
|
|
||||||
msg_type = 'private';
|
|
||||||
} else {
|
|
||||||
msg_type = message.type;
|
|
||||||
}
|
|
||||||
compose_actions.start(msg_type, {stream: stream, subject: subject,
|
|
||||||
private_message_recipient: pm_recipient,
|
|
||||||
replying_to_message: message,
|
|
||||||
trigger: opts.trigger});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.reply_with_mention = function (opts) {
|
|
||||||
exports.respond_to_message(opts);
|
|
||||||
var message = current_msg_list.selected_message();
|
|
||||||
var mention = '@**' + message.sender_full_name + '**';
|
|
||||||
$('#new_message_content').val(mention + ' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
// This function is for debugging / data collection only. Arguably it
|
// This function is for debugging / data collection only. Arguably it
|
||||||
// should live in debug.js, but then it wouldn't be able to call
|
// should live in debug.js, but then it wouldn't be able to call
|
||||||
// send_message() directly below.
|
// send_message() directly below.
|
||||||
|
|||||||
@@ -243,6 +243,58 @@ exports.cancel = function () {
|
|||||||
$(document).trigger($.Event('compose_canceled.zulip'));
|
$(document).trigger($.Event('compose_canceled.zulip'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.respond_to_message = function (opts) {
|
||||||
|
var message;
|
||||||
|
var msg_type;
|
||||||
|
// Before initiating a reply to a message, if there's an
|
||||||
|
// in-progress composition, snapshot it.
|
||||||
|
drafts.update_draft();
|
||||||
|
|
||||||
|
message = current_msg_list.selected_message();
|
||||||
|
|
||||||
|
if (message === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unread_ops.mark_message_as_read(message);
|
||||||
|
|
||||||
|
var stream = '';
|
||||||
|
var subject = '';
|
||||||
|
if (message.type === "stream") {
|
||||||
|
stream = message.stream;
|
||||||
|
subject = message.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pm_recipient = message.reply_to;
|
||||||
|
if (message.type === "private") {
|
||||||
|
if (opts.reply_type === "personal") {
|
||||||
|
// reply_to for private messages is everyone involved, so for
|
||||||
|
// personals replies we need to set the private message
|
||||||
|
// recipient to just the sender
|
||||||
|
pm_recipient = people.get_person_from_user_id(message.sender_id).email;
|
||||||
|
} else {
|
||||||
|
pm_recipient = people.pm_reply_to(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (opts.reply_type === 'personal' || message.type === 'private') {
|
||||||
|
msg_type = 'private';
|
||||||
|
} else {
|
||||||
|
msg_type = message.type;
|
||||||
|
}
|
||||||
|
exports.start(msg_type, {stream: stream, subject: subject,
|
||||||
|
private_message_recipient: pm_recipient,
|
||||||
|
replying_to_message: message,
|
||||||
|
trigger: opts.trigger});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.reply_with_mention = function (opts) {
|
||||||
|
exports.respond_to_message(opts);
|
||||||
|
var message = current_msg_list.selected_message();
|
||||||
|
var mention = '@**' + message.sender_full_name + '**';
|
||||||
|
$('#new_message_content').val(mention + ' ');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ exports.process_enter_key = function (e) {
|
|||||||
// view and there is a "current" message, so in that case
|
// view and there is a "current" message, so in that case
|
||||||
// "enter" is the hotkey to respond to a message. Note that
|
// "enter" is the hotkey to respond to a message. Note that
|
||||||
// "r" has same effect, but that is handled in process_hotkey().
|
// "r" has same effect, but that is handled in process_hotkey().
|
||||||
compose.respond_to_message({trigger: 'hotkey enter'});
|
compose_actions.respond_to_message({trigger: 'hotkey enter'});
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -648,13 +648,13 @@ exports.process_hotkey = function (e, hotkey) {
|
|||||||
case 'reply_message': // 'r': respond to message
|
case 'reply_message': // 'r': respond to message
|
||||||
// Note that you can "enter" to respond to messages as well,
|
// Note that you can "enter" to respond to messages as well,
|
||||||
// but that is handled in process_enter_key().
|
// but that is handled in process_enter_key().
|
||||||
compose.respond_to_message({trigger: 'hotkey'});
|
compose_actions.respond_to_message({trigger: 'hotkey'});
|
||||||
return true;
|
return true;
|
||||||
case 'respond_to_author': // 'R': respond to author
|
case 'respond_to_author': // 'R': respond to author
|
||||||
compose.respond_to_message({reply_type: "personal", trigger: 'hotkey pm'});
|
compose_actions.respond_to_message({reply_type: "personal", trigger: 'hotkey pm'});
|
||||||
return true;
|
return true;
|
||||||
case 'compose_reply_with_mention': // '@': respond to message with mention to author
|
case 'compose_reply_with_mention': // '@': respond to message with mention to author
|
||||||
compose.reply_with_mention({trigger: 'hotkey'});
|
compose_actions.reply_with_mention({trigger: 'hotkey'});
|
||||||
return true;
|
return true;
|
||||||
case 'show_lightbox':
|
case 'show_lightbox':
|
||||||
lightbox.show_from_selected_message();
|
lightbox.show_from_selected_message();
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ exports.register_click_handlers = function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('body').on('click', '.sender_info_popover .mention_user', function (e) {
|
$('body').on('click', '.sender_info_popover .mention_user', function (e) {
|
||||||
compose.respond_to_message({trigger: 'user sidebar popover'});
|
compose_actions.respond_to_message({trigger: 'user sidebar popover'});
|
||||||
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
var user_id = $(e.target).parents('ul').attr('data-user-id');
|
||||||
var name = people.get_person_from_user_id(user_id).full_name;
|
var name = people.get_person_from_user_id(user_id).full_name;
|
||||||
var textarea = $("#new_message_content");
|
var textarea = $("#new_message_content");
|
||||||
@@ -647,7 +647,7 @@ exports.register_click_handlers = function () {
|
|||||||
var textarea = $("#new_message_content");
|
var textarea = $("#new_message_content");
|
||||||
var msgid = $(e.currentTarget).data("message-id");
|
var msgid = $(e.currentTarget).data("message-id");
|
||||||
|
|
||||||
compose.respond_to_message({trigger: 'popover respond'});
|
compose_actions.respond_to_message({trigger: 'popover respond'});
|
||||||
channel.get({
|
channel.get({
|
||||||
url: '/json/messages/' + msgid,
|
url: '/json/messages/' + msgid,
|
||||||
idempotent: true,
|
idempotent: true,
|
||||||
@@ -665,7 +665,7 @@ exports.register_click_handlers = function () {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
$('body').on('click', '.respond_personal_button', function (e) {
|
$('body').on('click', '.respond_personal_button', function (e) {
|
||||||
compose.respond_to_message({reply_type: 'personal', trigger: 'popover respond pm'});
|
compose_actions.respond_to_message({reply_type: 'personal', trigger: 'popover respond pm'});
|
||||||
popovers.hide_all();
|
popovers.hide_all();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ def find_edges_to_remove(graph, methods):
|
|||||||
('activity', 'narrow'),
|
('activity', 'narrow'),
|
||||||
('compose', 'compose_actions'),
|
('compose', 'compose_actions'),
|
||||||
('compose', 'subs'),
|
('compose', 'subs'),
|
||||||
|
('compose_actions', 'drafts'),
|
||||||
|
('compose_actions', 'unread_ops'),
|
||||||
('drafts', 'compose'),
|
('drafts', 'compose'),
|
||||||
('drafts', 'echo'),
|
('drafts', 'echo'),
|
||||||
('echo', 'compose'),
|
('echo', 'compose'),
|
||||||
|
|||||||
Reference in New Issue
Block a user