message edit: Move with_first_message_id to message edit.js.

Prep commit so that the function first_message_id can be used
as an exported function for marking resolved topic as unresolved.

Related to #20584.
This commit is contained in:
Priyam Seth
2021-07-28 00:44:18 +05:30
committed by Tim Abbott
parent 1696144df7
commit 9aa5082d63
2 changed files with 39 additions and 39 deletions

View File

@@ -1099,3 +1099,40 @@ export function move_topic_containing_message_to_stream(
},
});
}
export function with_first_message_id(stream_id, topic_name, success_cb, error_cb) {
// The API endpoint for editing messages to change their
// content, topic, or stream requires a message ID.
//
// Because we don't have full data in the browser client, it's
// possible that we might display a topic in the left sidebar
// (and thus expose the UI for moving its topic to another
// stream) without having a message ID that is definitely
// within the topic. (The comments in stream_topic_history.js
// discuss the tricky issues around message deletion that are
// involved here).
//
// To ensure this option works reliably at a small latency
// cost for a rare operation, we just ask the server for the
// latest message ID in the topic.
const data = {
anchor: "newest",
num_before: 1,
num_after: 0,
narrow: JSON.stringify([
{operator: "stream", operand: stream_id},
{operator: "topic", operand: topic_name},
]),
};
channel.get({
url: "/json/messages",
data,
idempotent: true,
success(data) {
const message_id = data.messages[0].id;
success_cb(message_id);
},
error_cb,
});
}