message-editing: Make default "Move messages" form context-dependent.

In the previous menu for moving messages, the default option was
"Move this and all following messages." However, this default choice
was not always aligned with user intentions, particularly when moving
the first or last message in a topic. In such cases, the desired
behavior often corresponds to "Move all messages in this topic" for the
first message and "Move only this message" for the last message.

To address this, we have updated the default options as follows:

1. **When moving the first message in a topic:** The default option is
now "Move all messages in this topic." This change better represents
the user's intention when moving the initial message in a topic.

2. **When moving the last message in a topic:** The default option has
been adjusted to "Move only this message." This change ensures that
users can easily move the last message without affecting other messages
in the topic.

These changes are designed to enhance the user experience and
facilitate the management of topics, especially when users follow or
unmute topics.

Fixes: #27298.
This commit is contained in:
Sayam Samal
2023-10-23 03:06:26 +05:30
committed by Tim Abbott
parent 49263ba69f
commit 5c82a923a9
3 changed files with 159 additions and 4 deletions

View File

@@ -1337,3 +1337,39 @@ export function with_first_message_id(stream_id, topic_name, success_cb, error_c
error: error_cb,
});
}
export function is_message_oldest_or_newest(
stream_id,
topic_name,
message_id,
success_callback,
error_callback,
) {
const data = {
anchor: message_id,
num_before: 1,
num_after: 1,
narrow: JSON.stringify([
{operator: "stream", operand: stream_id},
{operator: "topic", operand: topic_name},
]),
};
channel.get({
url: "/json/messages",
data,
success(data) {
let is_oldest = true;
let is_newest = true;
for (const message of data.messages) {
if (message.id < message_id) {
is_oldest = false;
} else if (message.id > message_id) {
is_newest = false;
}
}
success_callback(is_oldest, is_newest);
},
error: error_callback,
});
}