topic_list_data: Convert module to typescript.

This commit is contained in:
evykassirer
2024-01-10 23:09:17 -08:00
committed by Tim Abbott
parent a4fad5dda1
commit 33e4c9b25c
2 changed files with 53 additions and 7 deletions

View File

@@ -114,7 +114,7 @@ export function get_list_info(zoomed: boolean): {
let more_conversations_unread_count = 0; let more_conversations_unread_count = 0;
function should_show_conversation(idx: number, conversation: DisplayObject): boolean { function should_show_conversation(idx: number, conversation: DisplayObject): boolean {
// We always show the active conversation; see the similar // We always show the active conversation; see the similar
// comment in topic_list_data.js. // comment in topic_list_data.ts.
if (conversation.is_active) { if (conversation.is_active) {
return true; return true;
} }

View File

@@ -1,3 +1,5 @@
import assert from "minimalistic-assert";
import * as resolved_topic from "../shared/src/resolved_topic"; import * as resolved_topic from "../shared/src/resolved_topic";
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
@@ -11,7 +13,37 @@ import * as util from "./util";
const max_topics = 8; const max_topics = 8;
const max_topics_with_unread = 12; const max_topics_with_unread = 12;
function choose_topics(stream_id, topic_names, zoomed, topic_choice_state) { type TopicInfo = {
topic_name: string;
topic_resolved_prefix: string;
topic_display_name: string;
unread: number;
is_zero: boolean;
is_muted: boolean;
is_followed: boolean;
is_unmuted_or_followed: boolean;
is_active_topic: boolean;
url: string;
contains_unread_mention: boolean;
};
type TopicChoiceState = {
active_topic: string | undefined;
topics_with_unread_mentions: Set<string>;
more_topics_unmuted_unreads: number;
more_topics_have_unread_mention_messages: boolean;
more_topics_muted_unreads: number;
more_topics_have_muted_unread_mention_messages: boolean;
topics_selected: number;
items: TopicInfo[];
};
function choose_topics(
stream_id: number,
topic_names: string[],
zoomed: boolean,
topic_choice_state: TopicChoiceState,
): void {
for (const [idx, topic_name] of topic_names.entries()) { for (const [idx, topic_name] of topic_names.entries()) {
const num_unread = unread.num_unread_for_topic(stream_id, topic_name); const num_unread = unread.num_unread_for_topic(stream_id, topic_name);
const is_active_topic = topic_choice_state.active_topic === topic_name.toLowerCase(); const is_active_topic = topic_choice_state.active_topic === topic_name.toLowerCase();
@@ -29,7 +61,7 @@ function choose_topics(stream_id, topic_names, zoomed, topic_choice_state) {
); );
if (!zoomed) { if (!zoomed) {
function should_show_topic(topics_selected) { function should_show_topic(topics_selected: number): boolean {
// This function exists just for readability, to // This function exists just for readability, to
// avoid long chained conditionals to determine // avoid long chained conditionals to determine
// which topics to include. // which topics to include.
@@ -90,7 +122,7 @@ function choose_topics(stream_id, topic_names, zoomed, topic_choice_state) {
// same code we do when zoomed. // same code we do when zoomed.
} }
const topic_info = { const topic_info: TopicInfo = {
topic_name, topic_name,
topic_resolved_prefix, topic_resolved_prefix,
topic_display_name, topic_display_name,
@@ -108,8 +140,20 @@ function choose_topics(stream_id, topic_names, zoomed, topic_choice_state) {
} }
} }
export function get_list_info(stream_id, zoomed, search_term) { type TopicListInfo = {
const topic_choice_state = { items: TopicInfo[];
num_possible_topics: number;
more_topics_unreads: number;
more_topics_have_unread_mention_messages: boolean;
more_topics_unread_count_muted: boolean;
};
export function get_list_info(
stream_id: number,
zoomed: boolean,
search_term: string,
): TopicListInfo {
const topic_choice_state: TopicChoiceState = {
items: [], items: [],
topics_selected: 0, topics_selected: 0,
more_topics_muted_unreads: 0, more_topics_muted_unreads: 0,
@@ -120,7 +164,9 @@ export function get_list_info(stream_id, zoomed, search_term) {
topics_with_unread_mentions: unread.get_topics_with_unread_mentions(stream_id), topics_with_unread_mentions: unread.get_topics_with_unread_mentions(stream_id),
}; };
const stream_muted = sub_store.get(stream_id).is_muted; const sub = sub_store.get(stream_id);
assert(sub !== undefined);
const stream_muted = sub.is_muted;
let topic_names = stream_topic_history.get_recent_topic_names(stream_id); let topic_names = stream_topic_history.get_recent_topic_names(stream_id);
if (zoomed) { if (zoomed) {