mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 12:54:58 +00:00
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:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user