2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
// We don't need an andSelf() here because we already know
|
|
|
|
// that our next element is *not* a message_row, so this
|
|
|
|
// isn't going to end up empty unless we're at the bottom or top.
|
|
|
|
exports.next_visible = function (message_row) {
|
2014-02-21 21:52:51 +01:00
|
|
|
if (message_row === undefined || message_row.length === 0) {
|
2013-08-14 20:57:29 +02:00
|
|
|
return $();
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const row = message_row.next(".selectable_row");
|
2013-08-14 20:57:29 +02:00
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const recipient_row = exports.get_message_recipient_row(message_row);
|
2020-07-15 01:29:15 +02:00
|
|
|
const next_recipient_rows = $(recipient_row).nextAll(".recipient_row");
|
2014-02-05 16:55:24 +01:00
|
|
|
if (next_recipient_rows.length === 0) {
|
|
|
|
return $();
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".selectable_row", next_recipient_rows[0]).first();
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.prev_visible = function (message_row) {
|
2014-02-21 21:52:51 +01:00
|
|
|
if (message_row === undefined || message_row.length === 0) {
|
2013-08-14 20:57:29 +02:00
|
|
|
return $();
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const row = message_row.prev(".selectable_row");
|
2013-08-14 20:57:29 +02:00
|
|
|
if (row.length !== 0) {
|
|
|
|
return row;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const recipient_row = exports.get_message_recipient_row(message_row);
|
2020-07-15 01:29:15 +02:00
|
|
|
const prev_recipient_rows = $(recipient_row).prevAll(".recipient_row");
|
2014-02-05 16:55:24 +01:00
|
|
|
if (prev_recipient_rows.length === 0) {
|
|
|
|
return $();
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".selectable_row", prev_recipient_rows[0]).last();
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.first_visible = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".focused_table .selectable_row").first();
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.last_visible = function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".focused_table .selectable_row").last();
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-03 20:49:58 +02:00
|
|
|
|
2020-04-02 23:34:54 +02:00
|
|
|
exports.visible_range = function (start_id, end_id) {
|
|
|
|
/*
|
|
|
|
Get all visible rows between start_id
|
|
|
|
and end_in, being inclusive on both ends.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const rows = [];
|
|
|
|
|
|
|
|
let row = current_msg_list.get_row(start_id);
|
|
|
|
let msg_id = exports.id(row);
|
|
|
|
|
|
|
|
while (msg_id <= end_id) {
|
|
|
|
rows.push(row);
|
|
|
|
|
|
|
|
if (msg_id >= end_id) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
row = exports.next_visible(row);
|
|
|
|
msg_id = exports.id(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
};
|
|
|
|
|
2020-04-02 15:13:23 +02:00
|
|
|
exports.is_draft_row = function (row) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return row.find(".restore-draft").length >= 1;
|
2020-04-02 15:13:23 +02:00
|
|
|
};
|
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.id = function (message_row) {
|
2020-04-02 15:13:23 +02:00
|
|
|
if (exports.is_draft_row(message_row)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Drafts have no zid");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-04-02 15:13:23 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 17:29:23 +01:00
|
|
|
/*
|
|
|
|
For blueslip errors, don't return early, since
|
|
|
|
we may have some code now that actually relies
|
|
|
|
on the NaN behavior here. We can try to clean
|
|
|
|
that up in the future, but we mainly just want
|
|
|
|
more data now.
|
|
|
|
*/
|
2020-04-02 15:13:23 +02:00
|
|
|
|
2020-02-21 17:29:23 +01:00
|
|
|
if (message_row.length !== 1) {
|
|
|
|
blueslip.error("Caller should pass in a single row.");
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const zid = message_row.attr("zid");
|
2020-02-21 17:29:23 +01:00
|
|
|
|
|
|
|
if (zid === undefined) {
|
|
|
|
blueslip.error("Calling code passed rows.id a row with no zid attr.");
|
|
|
|
}
|
|
|
|
|
2020-10-07 09:17:30 +02:00
|
|
|
return Number.parseFloat(zid);
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-18 20:55:41 +02:00
|
|
|
|
2020-04-09 21:31:15 +02:00
|
|
|
exports.local_echo_id = function (message_row) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const zid = message_row.attr("zid");
|
2020-04-09 21:31:15 +02:00
|
|
|
|
|
|
|
if (zid === undefined) {
|
|
|
|
blueslip.error("Calling code passed rows.local_id a row with no zid attr.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-04-09 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (!zid.includes(".0")) {
|
|
|
|
blueslip.error("Trying to get local_id from row that has reified message id: " + zid);
|
2020-04-09 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return zid;
|
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const valid_table_names = new Set(["zhome", "zfilt"]);
|
2012-10-27 02:05:54 +02:00
|
|
|
|
2013-08-14 20:57:29 +02:00
|
|
|
exports.get_table = function (table_name) {
|
2020-05-27 04:04:54 +02:00
|
|
|
if (!valid_table_names.has(table_name)) {
|
2013-08-14 20:57:29 +02:00
|
|
|
return $();
|
|
|
|
}
|
2012-10-27 03:03:06 +02:00
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
return $(`#${CSS.escape(table_name)}`);
|
2013-08-14 20:57:29 +02:00
|
|
|
};
|
2012-10-27 03:03:06 +02:00
|
|
|
|
2017-07-19 13:53:30 +02:00
|
|
|
exports.get_message_id = function (elem) {
|
|
|
|
// Gets the message_id for elem, where elem is a DOM
|
|
|
|
// element inside a message. This is typically used
|
|
|
|
// in click handlers for things like the reaction button.
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = $(elem).closest(".message_row");
|
|
|
|
const message_id = exports.id(row);
|
2017-07-19 13:53:30 +02:00
|
|
|
return message_id;
|
|
|
|
};
|
|
|
|
|
2014-02-05 16:55:24 +01:00
|
|
|
exports.get_closest_group = function (element) {
|
2013-08-27 17:09:27 +02:00
|
|
|
// This gets the closest message row to an element, whether it's
|
2014-02-03 22:48:25 +01:00
|
|
|
// a recipient bar or message. With our current markup,
|
2013-08-27 17:09:27 +02:00
|
|
|
// this is the most reliable way to do it.
|
2014-02-05 16:55:24 +01:00
|
|
|
return $(element).closest("div.recipient_row");
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.first_message_in_group = function (message_group) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $("div.message_row", message_group).first();
|
2014-02-05 16:55:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_message_recipient_row = function (message_row) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(message_row).parent(".recipient_row").expectOne();
|
2014-02-05 16:55:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.get_message_recipient_header = function (message_row) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(message_row).parent(".recipient_row").find(".message_header").expectOne();
|
2014-02-05 16:55:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.recipient_from_group = function (message_group) {
|
2020-07-15 00:34:28 +02:00
|
|
|
return message_store.get(
|
|
|
|
exports.id($(message_group).children(".message_row").first().expectOne()),
|
|
|
|
);
|
2013-08-27 17:09:27 +02:00
|
|
|
};
|
|
|
|
|
2014-03-13 04:25:34 +01:00
|
|
|
exports.id_for_recipient_row = function (recipient_row) {
|
|
|
|
// A recipient row can be either a normal recipient row, or
|
|
|
|
// the FRB, which is a fake recipient row. If it's a FRB, it has
|
|
|
|
// a 'zid' property that stores the message id it is directly over
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_row = exports.first_message_in_group(recipient_row);
|
2014-03-13 04:25:34 +01:00
|
|
|
if (msg_row.length === 0) {
|
|
|
|
// If we're narrowing from the FRB, take the msg id
|
|
|
|
// directly from it
|
|
|
|
return exports.id(recipient_row);
|
|
|
|
}
|
2016-12-02 21:34:35 +01:00
|
|
|
return exports.id(msg_row);
|
2014-03-13 04:25:34 +01:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.rows = exports;
|