mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
message_edit: Extract function to check whether message is valid.
We do not allow sending messages where sending request had failed or message is locally echoed. This commit extracts these checks to a new function so that we can avoid duplicating code.
This commit is contained in:
@@ -98,12 +98,9 @@ function is_widget_message(message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function get_editability(message, edit_limit_seconds_buffer = 0) {
|
||||
export function is_message_editable_ignoring_permissions(message) {
|
||||
if (!message) {
|
||||
return editability_types.NO;
|
||||
}
|
||||
if (!is_topic_editable(message, edit_limit_seconds_buffer)) {
|
||||
return editability_types.NO;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (message.failed_request) {
|
||||
@@ -112,12 +109,27 @@ export function get_editability(message, edit_limit_seconds_buffer = 0) {
|
||||
// other message updates. This commit changed the result
|
||||
// from FULL to NO, since the prior implementation was
|
||||
// buggy.
|
||||
return editability_types.NO;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Locally echoed messages are not editable, since the message hasn't
|
||||
// finished being sent yet.
|
||||
if (message.locally_echoed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currently_echoing_messages.has(message.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function get_editability(message, edit_limit_seconds_buffer = 0) {
|
||||
if (!is_message_editable_ignoring_permissions(message)) {
|
||||
return editability_types.NO;
|
||||
}
|
||||
|
||||
if (!is_topic_editable(message, edit_limit_seconds_buffer)) {
|
||||
return editability_types.NO;
|
||||
}
|
||||
|
||||
@@ -133,10 +145,6 @@ export function get_editability(message, edit_limit_seconds_buffer = 0) {
|
||||
return editability_types.FULL;
|
||||
}
|
||||
|
||||
if (currently_echoing_messages.has(message.id)) {
|
||||
return editability_types.NO;
|
||||
}
|
||||
|
||||
if (
|
||||
page_params.realm_message_content_edit_limit_seconds +
|
||||
edit_limit_seconds_buffer +
|
||||
|
||||
Reference in New Issue
Block a user