mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
messsage-fetch: Convert channel operator's operand to integer ID.
The operand for the canoncial "channel" operator can be an ID, but it must be an integer and not a string, so we take care of that directly in handle_operators_supporting_id_based_api.
This commit is contained in:
committed by
Tim Abbott
parent
3405e95b6b
commit
09bce62d98
@@ -255,11 +255,15 @@ function handle_operators_supporting_id_based_api(narrow_parameter: string): str
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (canonical_operator === "channel") {
|
if (canonical_operator === "channel") {
|
||||||
const stream_id = stream_data.get_stream_id(raw_term.operand);
|
// An unknown channel will have an empty string set for
|
||||||
if (stream_id !== undefined) {
|
// the operand. And the page_params.narrow may have a
|
||||||
narrow_term.operand = stream_id;
|
// channel name as the operand. But all other cases
|
||||||
|
// should have the channel ID set as the string value
|
||||||
|
// for the operand.
|
||||||
|
const stream = stream_data.get_sub_by_id_string(raw_term.operand);
|
||||||
|
if (stream !== undefined) {
|
||||||
|
narrow_term.operand = stream.stream_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
narrow_terms.push(narrow_term);
|
narrow_terms.push(narrow_term);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -324,26 +328,7 @@ export function load_messages(opts: MessageFetchOptions, attempt = 1): void {
|
|||||||
if (page_params.narrow !== undefined) {
|
if (page_params.narrow !== undefined) {
|
||||||
terms = [...terms, ...page_params.narrow];
|
terms = [...terms, ...page_params.narrow];
|
||||||
}
|
}
|
||||||
// TODO(stream_id): The server would ideally work with stream ids instead
|
narrow_data_string = JSON.stringify(terms);
|
||||||
// of stream names.
|
|
||||||
const server_terms = [];
|
|
||||||
for (const term of terms) {
|
|
||||||
if (term.operator === "channel") {
|
|
||||||
const sub = stream_data.get_sub_by_id_string(term.operand);
|
|
||||||
server_terms.push({
|
|
||||||
...term,
|
|
||||||
// If we can't find the sub, we shouldn't send `undefined`
|
|
||||||
// because we want to preserve the NarrowTerm type, so we just
|
|
||||||
// send the unknown stream id.
|
|
||||||
// This should show a "this channel does not exist or is private"
|
|
||||||
// notice (both logged in and logged out).
|
|
||||||
operand: sub?.name ?? term.operand,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
server_terms.push({...term});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
narrow_data_string = JSON.stringify(server_terms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (narrow_data_string !== "") {
|
if (narrow_data_string !== "") {
|
||||||
|
|||||||
Reference in New Issue
Block a user