mirror of https://github.com/zulip/zulip.git
lightbox: Rewrite logic depending on last_message CSS class.
The last_message CSS class didn't mean what it said it did, due to issues with live update. Further, this logic was poorly written, with `$message` changing types from a .message_row to a .recipient_row for now apparent reason. I was able to reproduce at least one bug where the `v` shortcut would not correctly open the lightbox that is fixed by this rewrite.
This commit is contained in:
parent
2fa88362bc
commit
b1155516d1
|
@ -335,15 +335,22 @@ export function show_from_selected_message() {
|
||||||
let $image = $message.find(".message_inline_image img");
|
let $image = $message.find(".message_inline_image img");
|
||||||
let $prev_traverse = false;
|
let $prev_traverse = false;
|
||||||
|
|
||||||
|
// First, we walk upwards/backwards, starting with the current
|
||||||
|
// message, looking for an image to preview.
|
||||||
|
//
|
||||||
|
// Care must be taken, since both recipient_row elements and
|
||||||
|
// message_row objects have siblings of different types, such as
|
||||||
|
// date elements.
|
||||||
while ($image.length === 0) {
|
while ($image.length === 0) {
|
||||||
if ($message.prev().length === 0) {
|
if ($message.prev().length === 0) {
|
||||||
$message = $message.parent().prev();
|
const $prev_message_group = $message.parent().prevAll(".recipient_row").first();
|
||||||
if ($message.length === 0) {
|
if ($prev_message_group.length === 0) {
|
||||||
$prev_traverse = true;
|
$prev_traverse = true;
|
||||||
$message = $message_selected;
|
$message = $message_selected;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
$message = $message.find(".last_message");
|
$message = $prev_message_group.find(".message_row").last();
|
||||||
|
$image = $message.find(".message_inline_image img");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,11 +361,12 @@ export function show_from_selected_message() {
|
||||||
if ($prev_traverse) {
|
if ($prev_traverse) {
|
||||||
while ($image.length === 0) {
|
while ($image.length === 0) {
|
||||||
if ($message.next().length === 0) {
|
if ($message.next().length === 0) {
|
||||||
$message = $message.parent().next();
|
const $next_message_group = $message.parent().nextAll(".recipient_row").first();
|
||||||
if ($message.length === 0) {
|
if ($next_message_group.length === 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
$message = $message.children().first();
|
$message = $next_message_group.find(".message_row").first();
|
||||||
|
$image = $message.find(".message_inline_image img");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue