mirror of https://github.com/zulip/zulip.git
user_topics: Always store stream name in UserTopic.
This commit is contained in:
parent
b0a4b8e439
commit
741b8c308a
|
@ -19,7 +19,7 @@ type ServerUserTopic = z.infer<typeof user_topic_schema>;
|
||||||
|
|
||||||
export type UserTopic = {
|
export type UserTopic = {
|
||||||
stream_id: number;
|
stream_id: number;
|
||||||
stream: string | undefined;
|
stream: string;
|
||||||
topic: string;
|
topic: string;
|
||||||
date_updated: number;
|
date_updated: number;
|
||||||
date_updated_str: string;
|
date_updated_str: string;
|
||||||
|
@ -37,6 +37,7 @@ const user_topic_schema = z.object({
|
||||||
const all_user_topics = new Map<
|
const all_user_topics = new Map<
|
||||||
number,
|
number,
|
||||||
FoldDict<{
|
FoldDict<{
|
||||||
|
stream_name: string;
|
||||||
date_updated: number;
|
date_updated: number;
|
||||||
visibility_policy: number;
|
visibility_policy: number;
|
||||||
}>
|
}>
|
||||||
|
@ -51,6 +52,7 @@ export const all_visibility_policies = {
|
||||||
|
|
||||||
export function update_user_topics(
|
export function update_user_topics(
|
||||||
stream_id: number,
|
stream_id: number,
|
||||||
|
stream_name: string,
|
||||||
topic: string,
|
topic: string,
|
||||||
visibility_policy: number,
|
visibility_policy: number,
|
||||||
date_updated: number,
|
date_updated: number,
|
||||||
|
@ -64,7 +66,7 @@ export function update_user_topics(
|
||||||
all_user_topics.set(stream_id, sub_dict);
|
all_user_topics.set(stream_id, sub_dict);
|
||||||
}
|
}
|
||||||
const time = get_time_from_date_muted(date_updated);
|
const time = get_time_from_date_muted(date_updated);
|
||||||
sub_dict.set(topic, {date_updated: time, visibility_policy});
|
sub_dict.set(topic, {date_updated: time, visibility_policy, stream_name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +97,14 @@ export function is_topic_unmuted_or_followed(stream_id: number, topic: string):
|
||||||
export function get_user_topics_for_visibility_policy(visibility_policy: number): UserTopic[] {
|
export function get_user_topics_for_visibility_policy(visibility_policy: number): UserTopic[] {
|
||||||
const topics: UserTopic[] = [];
|
const topics: UserTopic[] = [];
|
||||||
for (const [stream_id, sub_dict] of all_user_topics) {
|
for (const [stream_id, sub_dict] of all_user_topics) {
|
||||||
const stream = sub_store.maybe_get_stream_name(stream_id);
|
|
||||||
for (const topic of sub_dict.keys()) {
|
for (const topic of sub_dict.keys()) {
|
||||||
if (sub_dict.get(topic)!.visibility_policy === visibility_policy) {
|
if (sub_dict.get(topic)!.visibility_policy === visibility_policy) {
|
||||||
const date_updated = sub_dict.get(topic)!.date_updated;
|
const topic_dict = sub_dict.get(topic)!;
|
||||||
|
const date_updated = topic_dict.date_updated;
|
||||||
const date_updated_str = timerender.render_now(new Date(date_updated)).time_str;
|
const date_updated_str = timerender.render_now(new Date(date_updated)).time_str;
|
||||||
topics.push({
|
topics.push({
|
||||||
stream_id,
|
stream_id,
|
||||||
stream,
|
stream: topic_dict.stream_name,
|
||||||
topic,
|
topic,
|
||||||
date_updated,
|
date_updated,
|
||||||
date_updated_str,
|
date_updated_str,
|
||||||
|
@ -210,7 +212,7 @@ export function set_user_topic(user_topic: ServerUserTopic): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_user_topics(stream_id, topic, user_topic.visibility_policy, date_updated);
|
update_user_topics(stream_id, stream_name, topic, user_topic.visibility_policy, date_updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function set_user_topics(user_topics: ServerUserTopic[]): void {
|
export function set_user_topics(user_topics: ServerUserTopic[]): void {
|
||||||
|
|
|
@ -151,7 +151,12 @@ run_test("muting", () => {
|
||||||
{id: 9, type: "private", to_user_ids: "9", sender_id: 11},
|
{id: 9, type: "private", to_user_ids: "9", sender_id: 11},
|
||||||
];
|
];
|
||||||
|
|
||||||
user_topics.update_user_topics(1, "muted", user_topics.all_visibility_policies.MUTED);
|
user_topics.update_user_topics(
|
||||||
|
1,
|
||||||
|
"random stream name",
|
||||||
|
"muted",
|
||||||
|
user_topics.all_visibility_policies.MUTED,
|
||||||
|
);
|
||||||
muted_users.add_muted_user(10);
|
muted_users.add_muted_user(10);
|
||||||
|
|
||||||
// `messages_filtered_for_topic_mutes` should skip filtering
|
// `messages_filtered_for_topic_mutes` should skip filtering
|
||||||
|
|
|
@ -38,12 +38,14 @@ stream_data.add_sub(muted);
|
||||||
|
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
general.stream_id,
|
general.stream_id,
|
||||||
|
general.name,
|
||||||
"muted topic",
|
"muted topic",
|
||||||
user_topics.all_visibility_policies.MUTED,
|
user_topics.all_visibility_policies.MUTED,
|
||||||
);
|
);
|
||||||
|
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
general.stream_id,
|
general.stream_id,
|
||||||
|
general.name,
|
||||||
"followed topic",
|
"followed topic",
|
||||||
user_topics.all_visibility_policies.FOLLOWED,
|
user_topics.all_visibility_policies.FOLLOWED,
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,6 +23,7 @@ stream_data.add_sub(frontend);
|
||||||
run_test("settings", ({override, override_rewire}) => {
|
run_test("settings", ({override, override_rewire}) => {
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
frontend.stream_id,
|
frontend.stream_id,
|
||||||
|
frontend.name,
|
||||||
"js",
|
"js",
|
||||||
user_topics.all_visibility_policies.MUTED,
|
user_topics.all_visibility_policies.MUTED,
|
||||||
1577836800,
|
1577836800,
|
||||||
|
|
|
@ -245,6 +245,7 @@ test("muting", () => {
|
||||||
|
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
social.stream_id,
|
social.stream_id,
|
||||||
|
social.stream_name,
|
||||||
"test_muting",
|
"test_muting",
|
||||||
user_topics.all_visibility_policies.MUTED,
|
user_topics.all_visibility_policies.MUTED,
|
||||||
);
|
);
|
||||||
|
@ -481,11 +482,12 @@ test("mentions", () => {
|
||||||
test_notifiable_count(counts.home_unread_messages, 0);
|
test_notifiable_count(counts.home_unread_messages, 0);
|
||||||
|
|
||||||
const muted_stream_id = 900;
|
const muted_stream_id = 900;
|
||||||
|
const muted_stream_name = "muted stream for testing unread mentions";
|
||||||
const unmuted_stream_id = 901;
|
const unmuted_stream_id = 901;
|
||||||
|
|
||||||
sub_store.add_hydrated_sub(muted_stream_id, {
|
sub_store.add_hydrated_sub(muted_stream_id, {
|
||||||
muted_stream_id,
|
muted_stream_id,
|
||||||
name: "muted stream for testing unread mentions",
|
name: muted_stream_name,
|
||||||
subscribed: true,
|
subscribed: true,
|
||||||
is_muted: true,
|
is_muted: true,
|
||||||
});
|
});
|
||||||
|
@ -498,6 +500,7 @@ test("mentions", () => {
|
||||||
|
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
muted_stream_id,
|
muted_stream_id,
|
||||||
|
muted_stream_name,
|
||||||
"lunch",
|
"lunch",
|
||||||
user_topics.all_visibility_policies.MUTED,
|
user_topics.all_visibility_policies.MUTED,
|
||||||
);
|
);
|
||||||
|
@ -638,7 +641,12 @@ test("mention updates", () => {
|
||||||
|
|
||||||
test("stream_has_any_unread_mentions", () => {
|
test("stream_has_any_unread_mentions", () => {
|
||||||
const muted_stream_id = 401;
|
const muted_stream_id = 401;
|
||||||
user_topics.update_user_topics(401, "lunch", user_topics.all_visibility_policies.MUTED);
|
user_topics.update_user_topics(
|
||||||
|
401,
|
||||||
|
"random_stream_name",
|
||||||
|
"lunch",
|
||||||
|
user_topics.all_visibility_policies.MUTED,
|
||||||
|
);
|
||||||
|
|
||||||
const mention_me_message = {
|
const mention_me_message = {
|
||||||
id: 15,
|
id: 15,
|
||||||
|
|
|
@ -55,64 +55,139 @@ test("edge_cases", () => {
|
||||||
|
|
||||||
test("add_and_remove_mutes", () => {
|
test("add_and_remove_mutes", () => {
|
||||||
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.MUTED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.MUTED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.MUTED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.MUTED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
||||||
|
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test unknown stream is harmless too
|
// test unknown stream is harmless too
|
||||||
user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
unknown.stream_id,
|
||||||
|
unknown.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_muted(unknown.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_muted(unknown.stream_id, "java"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("add_and_remove_unmutes", () => {
|
test("add_and_remove_unmutes", () => {
|
||||||
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.UNMUTED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.UNMUTED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.UNMUTED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.UNMUTED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
||||||
|
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test unknown stream is harmless too
|
// test unknown stream is harmless too
|
||||||
user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
unknown.stream_id,
|
||||||
|
unknown.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_unmuted(unknown.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_unmuted(unknown.stream_id, "java"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("add_and_remove_follows", () => {
|
test("add_and_remove_follows", () => {
|
||||||
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.FOLLOWED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.FOLLOWED);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.FOLLOWED,
|
||||||
|
);
|
||||||
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
||||||
|
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test idempotency
|
// test idempotency
|
||||||
user_topics.update_user_topics(devel.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
||||||
|
|
||||||
// test unknown stream is harmless too
|
// test unknown stream is harmless too
|
||||||
user_topics.update_user_topics(unknown.stream_id, "java", all_visibility_policies.INHERIT);
|
user_topics.update_user_topics(
|
||||||
|
unknown.stream_id,
|
||||||
|
unknown.name,
|
||||||
|
"java",
|
||||||
|
all_visibility_policies.INHERIT,
|
||||||
|
);
|
||||||
assert.ok(!user_topics.is_topic_followed(unknown.stream_id, "java"));
|
assert.ok(!user_topics.is_topic_followed(unknown.stream_id, "java"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -125,12 +200,14 @@ test("get_mutes", () => {
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
office.stream_id,
|
office.stream_id,
|
||||||
|
office.name,
|
||||||
"gossip",
|
"gossip",
|
||||||
all_visibility_policies.MUTED,
|
all_visibility_policies.MUTED,
|
||||||
1577836800,
|
1577836800,
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
devel.stream_id,
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
"java",
|
"java",
|
||||||
all_visibility_policies.MUTED,
|
all_visibility_policies.MUTED,
|
||||||
1577836700,
|
1577836700,
|
||||||
|
@ -168,12 +245,14 @@ test("get_unmutes", () => {
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
office.stream_id,
|
office.stream_id,
|
||||||
|
office.name,
|
||||||
"gossip",
|
"gossip",
|
||||||
all_visibility_policies.UNMUTED,
|
all_visibility_policies.UNMUTED,
|
||||||
1577836800,
|
1577836800,
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
devel.stream_id,
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
"java",
|
"java",
|
||||||
all_visibility_policies.UNMUTED,
|
all_visibility_policies.UNMUTED,
|
||||||
1577836700,
|
1577836700,
|
||||||
|
@ -211,12 +290,14 @@ test("get_follows", () => {
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
office.stream_id,
|
office.stream_id,
|
||||||
|
office.name,
|
||||||
"gossip",
|
"gossip",
|
||||||
all_visibility_policies.FOLLOWED,
|
all_visibility_policies.FOLLOWED,
|
||||||
1577836800,
|
1577836800,
|
||||||
);
|
);
|
||||||
user_topics.update_user_topics(
|
user_topics.update_user_topics(
|
||||||
devel.stream_id,
|
devel.stream_id,
|
||||||
|
devel.name,
|
||||||
"java",
|
"java",
|
||||||
all_visibility_policies.FOLLOWED,
|
all_visibility_policies.FOLLOWED,
|
||||||
1577836700,
|
1577836700,
|
||||||
|
|
Loading…
Reference in New Issue