2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2024-02-05 19:03:29 +01:00
|
|
|
import assert from "minimalistic-assert";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2024-08-29 18:23:23 +02:00
|
|
|
import render_message_length_toggle from "../templates/message_length_toggle.hbs";
|
|
|
|
|
2021-02-28 01:08:13 +01:00
|
|
|
import * as message_flags from "./message_flags";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2024-03-07 21:46:14 +01:00
|
|
|
import type {Message} from "./message_store";
|
2021-02-28 00:56:48 +01:00
|
|
|
import * as message_viewport from "./message_viewport";
|
|
|
|
import * as rows from "./rows";
|
2024-08-20 07:18:02 +02:00
|
|
|
import * as util from "./util";
|
2021-02-28 00:42:00 +01:00
|
|
|
|
2019-07-14 00:41:01 +02:00
|
|
|
/*
|
|
|
|
This library implements two related, similar concepts:
|
|
|
|
|
|
|
|
- condensing, i.e. cutting off messages taller than about a half
|
|
|
|
screen so that they aren't distractingly tall (and offering a button
|
|
|
|
to uncondense them).
|
|
|
|
|
|
|
|
- Collapsing, i.e. taking a message and reducing its height to a
|
|
|
|
single line, with a button to see the content.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2024-08-29 18:23:23 +02:00
|
|
|
export function show_message_expander($row: JQuery): void {
|
|
|
|
$row.find(".message_length_controller").html(
|
|
|
|
render_message_length_toggle({toggle_type: "expander"}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function show_message_condenser($row: JQuery): void {
|
|
|
|
$row.find(".message_length_controller").html(
|
|
|
|
render_message_length_toggle({toggle_type: "condenser"}),
|
|
|
|
);
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
|
|
|
|
2024-08-29 18:23:23 +02:00
|
|
|
export function hide_message_length_toggle($row: JQuery): void {
|
|
|
|
$row.find(".message_length_controller").empty();
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
function condense_row($row: JQuery): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $row.find(".message_content");
|
|
|
|
$content.addClass("condensed");
|
2024-08-29 18:23:23 +02:00
|
|
|
show_message_expander($row);
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
function uncondense_row($row: JQuery): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $row.find(".message_content");
|
|
|
|
$content.removeClass("condensed");
|
2024-08-29 18:23:23 +02:00
|
|
|
show_message_condenser($row);
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
export function uncollapse(message: Message): void {
|
2023-04-08 15:19:10 +02:00
|
|
|
// Uncollapse a message, restoring the condensed message "Show more" or
|
|
|
|
// "Show less" button if necessary.
|
2014-03-13 20:22:09 +01:00
|
|
|
message.collapsed = false;
|
2018-07-03 01:41:31 +02:00
|
|
|
message_flags.save_uncollapsed(message);
|
2014-03-13 20:22:09 +01:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
const process_row = function process_row($row: JQuery): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $row.find(".message_content");
|
|
|
|
$content.removeClass("collapsed");
|
2016-03-13 19:05:10 +01:00
|
|
|
|
|
|
|
if (message.condensed === true) {
|
|
|
|
// This message was condensed by the user, so re-show the
|
2023-04-08 15:19:10 +02:00
|
|
|
// "Show more" button.
|
2022-01-25 11:36:19 +01:00
|
|
|
condense_row($row);
|
2016-03-13 19:05:10 +01:00
|
|
|
} else if (message.condensed === false) {
|
|
|
|
// This message was un-condensed by the user, so re-show the
|
2023-04-08 15:19:10 +02:00
|
|
|
// "Show less" button.
|
2022-01-25 11:36:19 +01:00
|
|
|
uncondense_row($row);
|
|
|
|
} else if ($content.hasClass("could-be-condensed")) {
|
2016-03-13 19:05:10 +01:00
|
|
|
// By default, condense a long message.
|
2022-01-25 11:36:19 +01:00
|
|
|
condense_row($row);
|
2016-03-13 19:05:10 +01:00
|
|
|
} else {
|
|
|
|
// This was a short message, no more need for a [More] link.
|
2024-08-29 18:23:23 +02:00
|
|
|
hide_message_length_toggle($row);
|
2016-03-13 19:05:10 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-03-06 23:14:37 +01:00
|
|
|
for (const list of message_lists.all_rendered_message_lists()) {
|
|
|
|
const $rendered_row = list.get_row(message.id);
|
|
|
|
if ($rendered_row.length !== 0) {
|
|
|
|
process_row($rendered_row);
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 00:56:48 +01:00
|
|
|
}
|
2014-03-13 20:22:09 +01:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
export function collapse(message: Message): void {
|
2014-03-13 20:22:09 +01:00
|
|
|
message.collapsed = true;
|
2017-12-15 23:32:36 +01:00
|
|
|
|
|
|
|
if (message.locally_echoed) {
|
|
|
|
// Trying to collapse a locally echoed message is
|
|
|
|
// very rare, and in our current implementation the
|
|
|
|
// server response overwrites the flag, so we just
|
|
|
|
// punt for now.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-03 01:41:31 +02:00
|
|
|
message_flags.save_collapsed(message);
|
2016-03-13 19:05:10 +01:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
const process_row = function process_row($row: JQuery): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
$row.find(".message_content").addClass("collapsed");
|
2024-08-29 18:23:23 +02:00
|
|
|
show_message_expander($row);
|
2016-03-13 19:05:10 +01:00
|
|
|
};
|
|
|
|
|
2024-03-06 23:14:37 +01:00
|
|
|
for (const list of message_lists.all_rendered_message_lists()) {
|
|
|
|
const $rendered_row = list.get_row(message.id);
|
|
|
|
if ($rendered_row.length !== 0) {
|
|
|
|
process_row($rendered_row);
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 00:56:48 +01:00
|
|
|
}
|
2017-06-16 06:46:46 +02:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
export function toggle_collapse(message: Message): void {
|
2019-03-07 17:55:17 +01:00
|
|
|
if (message.is_me_message) {
|
|
|
|
// Disabled temporarily because /me messages don't have a
|
|
|
|
// styling for collapsing /me messages (they only recently
|
2023-10-11 01:14:01 +02:00
|
|
|
// added multi-line support). See also popover_menus_data.js.
|
2019-03-07 17:55:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-14 00:41:01 +02:00
|
|
|
// This function implements a multi-way toggle, to try to do what
|
|
|
|
// the user wants for messages:
|
|
|
|
//
|
2023-04-08 15:19:10 +02:00
|
|
|
// * If the message is currently showing any "Show more" button, either
|
2019-07-14 00:41:01 +02:00
|
|
|
// because it was previously condensed or collapsed, fully display it.
|
|
|
|
// * If the message is fully visible, either because it's too short to
|
|
|
|
// condense or because it's already uncondensed, collapse it
|
|
|
|
|
2024-02-05 19:03:29 +01:00
|
|
|
assert(message_lists.current !== undefined);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = message_lists.current.get_row(message.id);
|
|
|
|
if (!$row) {
|
2017-06-16 06:46:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-07-14 00:41:01 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $row.find(".message_content");
|
|
|
|
const is_condensable = $content.hasClass("could-be-condensed");
|
|
|
|
const is_condensed = $content.hasClass("condensed");
|
2017-06-16 06:46:46 +02:00
|
|
|
if (message.collapsed) {
|
2019-07-14 00:41:01 +02:00
|
|
|
if (is_condensable) {
|
|
|
|
message.condensed = true;
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.addClass("condensed");
|
|
|
|
show_message_expander($row);
|
2019-07-14 00:41:01 +02:00
|
|
|
}
|
2024-03-06 23:14:37 +01:00
|
|
|
uncollapse(message);
|
2019-07-14 00:41:01 +02:00
|
|
|
} else {
|
|
|
|
if (is_condensed) {
|
|
|
|
message.condensed = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.removeClass("condensed");
|
2024-08-29 18:23:23 +02:00
|
|
|
show_message_condenser($row);
|
2019-07-14 00:41:01 +02:00
|
|
|
} else {
|
2024-03-06 23:14:37 +01:00
|
|
|
collapse(message);
|
2019-07-14 00:41:01 +02:00
|
|
|
}
|
2017-06-16 06:46:46 +02:00
|
|
|
}
|
2021-02-28 00:56:48 +01:00
|
|
|
}
|
2017-06-16 06:46:46 +02:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
function get_message_height(elem: HTMLElement): number {
|
2023-06-01 08:07:47 +02:00
|
|
|
// This needs to be very fast. This function runs hundreds of times
|
|
|
|
// when displaying a message feed view that has hundreds of message
|
|
|
|
// history, which ideally should render in <100ms.
|
2024-08-20 07:18:02 +02:00
|
|
|
return util.the($(elem).find(".message_content")).scrollHeight;
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
export function condense_and_collapse(elems: JQuery): void {
|
2024-02-05 19:03:29 +01:00
|
|
|
if (message_lists.current === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-01 20:18:56 +02:00
|
|
|
const height_cutoff = message_viewport.max_message_height();
|
2023-05-31 00:30:46 +02:00
|
|
|
const rows_to_resize = [];
|
2014-03-13 20:22:09 +01:00
|
|
|
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
for (const elem of elems) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $(elem).find(".message_content");
|
2020-04-02 15:24:45 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($content.length !== 1) {
|
2020-04-02 15:24:45 +02:00
|
|
|
// We could have a "/me did this" message or something
|
|
|
|
// else without a `message_content` div.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-02 15:44:58 +02:00
|
|
|
const message_id = rows.id($(elem));
|
|
|
|
|
|
|
|
if (!message_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
const message = message_lists.current.get(message_id);
|
2020-04-02 15:44:58 +02:00
|
|
|
if (message === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
const message_height = get_message_height(elem);
|
2023-05-31 00:30:46 +02:00
|
|
|
|
|
|
|
rows_to_resize.push({
|
|
|
|
elem,
|
|
|
|
$content,
|
|
|
|
message,
|
|
|
|
message_height,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we resize all the rows *after* we calculate if we should
|
|
|
|
// resize them or not. This allows us to do all measurements before
|
|
|
|
// changing the layout of the page, which is more performanant.
|
|
|
|
// More information here: https://web.dev/avoid-large-complex-layouts-and-layout-thrashing/#avoid-layout-thrashing
|
|
|
|
for (const {elem, $content, message, message_height} of rows_to_resize) {
|
2020-04-02 15:44:58 +02:00
|
|
|
const long_message = message_height > height_cutoff;
|
|
|
|
if (long_message) {
|
|
|
|
// All long messages are flagged as such.
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.addClass("could-be-condensed");
|
2020-04-02 15:44:58 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.removeClass("could-be-condensed");
|
2020-04-02 15:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If message.condensed is defined, then the user has manually
|
|
|
|
// specified whether this message should be expanded or condensed.
|
|
|
|
if (message.condensed === true) {
|
|
|
|
condense_row($(elem));
|
|
|
|
continue;
|
2020-04-02 15:47:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message.condensed === false) {
|
2020-04-02 15:44:58 +02:00
|
|
|
uncondense_row($(elem));
|
|
|
|
continue;
|
2020-04-02 15:47:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (long_message) {
|
2020-04-02 15:44:58 +02:00
|
|
|
// By default, condense a long message.
|
|
|
|
condense_row($(elem));
|
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.removeClass("condensed");
|
2024-08-29 18:23:23 +02:00
|
|
|
hide_message_length_toggle($(elem));
|
2020-04-02 15:44:58 +02:00
|
|
|
}
|
|
|
|
|
2023-04-08 15:19:10 +02:00
|
|
|
// Completely hide the message and replace it with a "Show more"
|
|
|
|
// button if the user has collapsed it.
|
2020-04-02 15:44:58 +02:00
|
|
|
if (message.collapsed) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$content.addClass("collapsed");
|
2024-08-29 18:23:23 +02:00
|
|
|
show_message_expander($(elem));
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2021-02-28 00:56:48 +01:00
|
|
|
}
|
2014-03-13 20:22:09 +01:00
|
|
|
|
2024-03-07 21:46:14 +01:00
|
|
|
export function initialize(): void {
|
2024-05-02 23:44:32 +02:00
|
|
|
$("#message_feed_container").on("click", ".message_expander", function (this: HTMLElement, e) {
|
2014-03-13 20:22:09 +01:00
|
|
|
// Expanding a message can mean either uncollapsing or
|
|
|
|
// uncondensing it.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2023-08-08 10:44:35 +02:00
|
|
|
const id = rows.id($row);
|
2024-02-05 19:03:29 +01:00
|
|
|
assert(message_lists.current !== undefined);
|
2023-08-08 10:44:35 +02:00
|
|
|
const message = message_lists.current.get(id);
|
2024-03-07 21:46:14 +01:00
|
|
|
assert(message !== undefined);
|
2023-08-08 10:44:35 +02:00
|
|
|
// Focus on the expanded message.
|
|
|
|
message_lists.current.select_id(id);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $content = $row.find(".message_content");
|
2014-03-13 20:22:09 +01:00
|
|
|
if (message.collapsed) {
|
|
|
|
// Uncollapse.
|
2024-03-06 23:14:37 +01:00
|
|
|
uncollapse(message);
|
2022-01-25 11:36:19 +01:00
|
|
|
} else if ($content.hasClass("condensed")) {
|
2014-03-13 20:22:09 +01:00
|
|
|
// Uncondense (show the full long message).
|
|
|
|
message.condensed = false;
|
2024-08-29 18:23:23 +02:00
|
|
|
uncondense_row($row);
|
2014-03-13 20:22:09 +01:00
|
|
|
}
|
2020-07-15 19:41:19 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2014-03-13 20:22:09 +01:00
|
|
|
});
|
|
|
|
|
2024-05-02 23:44:32 +02:00
|
|
|
$("#message_feed_container").on("click", ".message_condenser", function (this: HTMLElement, e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $row = $(this).closest(".message_row");
|
2023-08-08 10:44:35 +02:00
|
|
|
const id = rows.id($row);
|
|
|
|
// Focus on the condensed message.
|
2024-02-05 19:03:29 +01:00
|
|
|
assert(message_lists.current !== undefined);
|
2023-08-08 10:44:35 +02:00
|
|
|
message_lists.current.select_id(id);
|
2024-03-07 21:46:14 +01:00
|
|
|
const message = message_lists.current.get(id);
|
|
|
|
assert(message !== undefined);
|
|
|
|
message.condensed = true;
|
2024-03-15 01:09:57 +01:00
|
|
|
condense_row($row);
|
2020-07-15 19:41:19 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2014-03-13 20:22:09 +01:00
|
|
|
});
|
2021-02-28 00:56:48 +01:00
|
|
|
}
|