mirror of https://github.com/zulip/zulip.git
condense: Convert module to Typescript.
This commit is contained in:
parent
e00641b0c4
commit
42dd55df42
|
@ -81,7 +81,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/src/compose_ui.ts",
|
"web/src/compose_ui.ts",
|
||||||
"web/src/compose_validate.js",
|
"web/src/compose_validate.js",
|
||||||
"web/src/composebox_typeahead.js",
|
"web/src/composebox_typeahead.js",
|
||||||
"web/src/condense.js",
|
"web/src/condense.ts",
|
||||||
"web/src/confirm_dialog.ts",
|
"web/src/confirm_dialog.ts",
|
||||||
"web/src/copied_tooltip.ts",
|
"web/src/copied_tooltip.ts",
|
||||||
"web/src/copy_and_paste.js",
|
"web/src/copy_and_paste.js",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import * as message_flags from "./message_flags";
|
import * as message_flags from "./message_flags";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
|
import type {Message} from "./message_store";
|
||||||
import * as message_viewport from "./message_viewport";
|
import * as message_viewport from "./message_viewport";
|
||||||
import * as rows from "./rows";
|
import * as rows from "./rows";
|
||||||
|
|
||||||
|
@ -18,35 +19,35 @@ This library implements two related, similar concepts:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function show_more_link($row) {
|
function show_more_link($row: JQuery): void {
|
||||||
$row.find(".message_condenser").hide();
|
$row.find(".message_condenser").hide();
|
||||||
$row.find(".message_expander").show();
|
$row.find(".message_expander").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_condense_link($row) {
|
function show_condense_link($row: JQuery): void {
|
||||||
$row.find(".message_expander").hide();
|
$row.find(".message_expander").hide();
|
||||||
$row.find(".message_condenser").show();
|
$row.find(".message_condenser").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
function condense_row($row) {
|
function condense_row($row: JQuery): void {
|
||||||
const $content = $row.find(".message_content");
|
const $content = $row.find(".message_content");
|
||||||
$content.addClass("condensed");
|
$content.addClass("condensed");
|
||||||
show_more_link($row);
|
show_more_link($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
function uncondense_row($row) {
|
function uncondense_row($row: JQuery): void {
|
||||||
const $content = $row.find(".message_content");
|
const $content = $row.find(".message_content");
|
||||||
$content.removeClass("condensed");
|
$content.removeClass("condensed");
|
||||||
show_condense_link($row);
|
show_condense_link($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uncollapse(message) {
|
export function uncollapse(message: Message): void {
|
||||||
// Uncollapse a message, restoring the condensed message "Show more" or
|
// Uncollapse a message, restoring the condensed message "Show more" or
|
||||||
// "Show less" button if necessary.
|
// "Show less" button if necessary.
|
||||||
message.collapsed = false;
|
message.collapsed = false;
|
||||||
message_flags.save_uncollapsed(message);
|
message_flags.save_uncollapsed(message);
|
||||||
|
|
||||||
const process_row = function process_row($row) {
|
const process_row = function process_row($row: JQuery): void {
|
||||||
const $content = $row.find(".message_content");
|
const $content = $row.find(".message_content");
|
||||||
$content.removeClass("collapsed");
|
$content.removeClass("collapsed");
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ export function uncollapse(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collapse(message) {
|
export function collapse(message: Message): void {
|
||||||
message.collapsed = true;
|
message.collapsed = true;
|
||||||
|
|
||||||
if (message.locally_echoed) {
|
if (message.locally_echoed) {
|
||||||
|
@ -88,7 +89,7 @@ export function collapse(message) {
|
||||||
|
|
||||||
message_flags.save_collapsed(message);
|
message_flags.save_collapsed(message);
|
||||||
|
|
||||||
const process_row = function process_row($row) {
|
const process_row = function process_row($row: JQuery): void {
|
||||||
$row.find(".message_content").addClass("collapsed");
|
$row.find(".message_content").addClass("collapsed");
|
||||||
show_more_link($row);
|
show_more_link($row);
|
||||||
};
|
};
|
||||||
|
@ -101,7 +102,7 @@ export function collapse(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggle_collapse(message) {
|
export function toggle_collapse(message: Message): void {
|
||||||
if (message.is_me_message) {
|
if (message.is_me_message) {
|
||||||
// Disabled temporarily because /me messages don't have a
|
// Disabled temporarily because /me messages don't have a
|
||||||
// styling for collapsing /me messages (they only recently
|
// styling for collapsing /me messages (they only recently
|
||||||
|
@ -146,38 +147,38 @@ export function toggle_collapse(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_message_height(elem) {
|
function get_message_height(elem: HTMLElement): number {
|
||||||
// This needs to be very fast. This function runs hundreds of times
|
// This needs to be very fast. This function runs hundreds of times
|
||||||
// when displaying a message feed view that has hundreds of message
|
// when displaying a message feed view that has hundreds of message
|
||||||
// history, which ideally should render in <100ms.
|
// history, which ideally should render in <100ms.
|
||||||
return $(elem).find(".message_content")[0].scrollHeight;
|
return $(elem).find(".message_content")[0].scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hide_message_expander($row) {
|
export function hide_message_expander($row: JQuery): void {
|
||||||
if ($row.find(".could-be-condensed").length !== 0) {
|
if ($row.find(".could-be-condensed").length !== 0) {
|
||||||
$row.find(".message_expander").hide();
|
$row.find(".message_expander").hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hide_message_condenser($row) {
|
export function hide_message_condenser($row: JQuery): void {
|
||||||
if ($row.find(".could-be-condensed").length !== 0) {
|
if ($row.find(".could-be-condensed").length !== 0) {
|
||||||
$row.find(".message_condenser").hide();
|
$row.find(".message_condenser").hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function show_message_expander($row) {
|
export function show_message_expander($row: JQuery): void {
|
||||||
if ($row.find(".could-be-condensed").length !== 0) {
|
if ($row.find(".could-be-condensed").length !== 0) {
|
||||||
$row.find(".message_expander").show();
|
$row.find(".message_expander").show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function show_message_condenser($row) {
|
export function show_message_condenser($row: JQuery): void {
|
||||||
if ($row.find(".could-be-condensed").length !== 0) {
|
if ($row.find(".could-be-condensed").length !== 0) {
|
||||||
$row.find(".message_condenser").show();
|
$row.find(".message_condenser").show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function condense_and_collapse(elems) {
|
export function condense_and_collapse(elems: JQuery): void {
|
||||||
if (message_lists.current === undefined) {
|
if (message_lists.current === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +206,7 @@ export function condense_and_collapse(elems) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const message_height = get_message_height(elem, message.id);
|
const message_height = get_message_height(elem);
|
||||||
|
|
||||||
rows_to_resize.push({
|
rows_to_resize.push({
|
||||||
elem,
|
elem,
|
||||||
|
@ -257,7 +258,7 @@ export function condense_and_collapse(elems) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initialize() {
|
export function initialize(): void {
|
||||||
$("#message_feed_container").on("click", ".message_expander", function (e) {
|
$("#message_feed_container").on("click", ".message_expander", function (e) {
|
||||||
// Expanding a message can mean either uncollapsing or
|
// Expanding a message can mean either uncollapsing or
|
||||||
// uncondensing it.
|
// uncondensing it.
|
||||||
|
@ -265,6 +266,7 @@ export function initialize() {
|
||||||
const id = rows.id($row);
|
const id = rows.id($row);
|
||||||
assert(message_lists.current !== undefined);
|
assert(message_lists.current !== undefined);
|
||||||
const message = message_lists.current.get(id);
|
const message = message_lists.current.get(id);
|
||||||
|
assert(message !== undefined);
|
||||||
// Focus on the expanded message.
|
// Focus on the expanded message.
|
||||||
message_lists.current.select_id(id);
|
message_lists.current.select_id(id);
|
||||||
const $content = $row.find(".message_content");
|
const $content = $row.find(".message_content");
|
||||||
|
@ -288,8 +290,9 @@ export function initialize() {
|
||||||
// Focus on the condensed message.
|
// Focus on the condensed message.
|
||||||
assert(message_lists.current !== undefined);
|
assert(message_lists.current !== undefined);
|
||||||
message_lists.current.select_id(id);
|
message_lists.current.select_id(id);
|
||||||
message_lists.current.get(id).condensed = true;
|
const message = message_lists.current.get(id);
|
||||||
condense_row($row);
|
assert(message !== undefined);
|
||||||
|
message.condensed = true;
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
|
@ -86,6 +86,7 @@ export type MessageWithBooleans = (
|
||||||
stream_wildcard_mentioned: boolean;
|
stream_wildcard_mentioned: boolean;
|
||||||
topic_wildcard_mentioned: boolean;
|
topic_wildcard_mentioned: boolean;
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
|
condensed?: boolean;
|
||||||
alerted: boolean;
|
alerted: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue