Skip to content

Commit 22ad879

Browse files
committed
fix: properly configure individual lightbox galleries per message.
Each message has a gallery id of the index of the message. Each message should be its own gallery, so you can't accidentally page to a different messages attachments. Mirrors discord behavior.
1 parent 3eb4a2a commit 22ad879

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/main/jte/macros/MediaAttachment.jte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
@param Attachment attachment
66
@param Message message
77
@param boolean nsfw
8+
@param int galleryIndex = 0
89

910
<%--'data-type="video"' must be properly set, otherwise, some videos will download instead of opening the lightbox --%>
1011

1112
@if(attachment.filename().startsWith("SPOILER_"))
1213
<div class="image spoilerImage">
1314
<input id="${attachment.id()}" type="checkbox">
1415
@if(AttachmentFormatUtils.isImage(attachment))
15-
<a href="${attachment.url()}" class="glightbox">
16+
<a href="${attachment.url()}" class="glightbox" data-gallery="${"gallery"+galleryIndex}">
1617
<img class="image img-fluid rounded-2"
1718
src="${attachment.url()}"
1819
alt="Image ${attachment.filename()} uploaded by ${message.getAuthor().name()}"
1920
loading="lazy">
2021
</a>
2122
@else
22-
<a href="${attachment.url()}" class="glightbox" data-type="video">
23+
<a href="${attachment.url()}" class="glightbox" data-type="video" data-gallery="${"gallery"+galleryIndex}">
2324
<video class="image img-fluid rounded-2"
2425
src="${attachment.url()}"
2526
preload="metadata"
@@ -34,14 +35,14 @@
3435
<div class="image spoilerImage">
3536
<input id="${attachment.id()}" type="checkbox">
3637
@if(AttachmentFormatUtils.isImage(attachment))
37-
<a href="${attachment.url()}" class="glightbox">
38+
<a href="${attachment.url()}" class="glightbox" data-gallery="${"gallery"+galleryIndex}">
3839
<img class="image img-fluid rounded-2"
3940
src="${attachment.url()}"
4041
alt="Image ${attachment.filename()} uploaded by ${message.getAuthor().name()}"
4142
loading="lazy">
4243
</a>
4344
@else
44-
<a href="${attachment.url()}" class="glightbox" data-type="video">
45+
<a href="${attachment.url()}" class="glightbox" data-type="video" data-gallery="${"gallery"+galleryIndex}">
4546
<video class="image img-fluid rounded-2"
4647
src="${attachment.url()}"
4748
preload="metadata"
@@ -56,14 +57,14 @@
5657
@else
5758
<div class="image">
5859
@if(AttachmentFormatUtils.isImage(attachment))
59-
<a href="${attachment.url()}" class="glightbox">
60+
<a href="${attachment.url()}" class="glightbox" data-gallery="${"gallery"+galleryIndex}">
6061
<img class="image img-fluid rounded-2"
6162
src="${attachment.url()}"
6263
alt="Image ${attachment.filename()} uploaded by ${message.getAuthor().name()}"
6364
loading="lazy">
6465
</a>
6566
@else
66-
<a href="${attachment.url()}" class="glightbox" data-type="video">
67+
<a href="${attachment.url()}" class="glightbox" data-type="video" data-gallery="${"gallery"+galleryIndex}">
6768
<%-- <span>potato</span>--%>
6869
<video class="image img-fluid rounded-2" controls src="${attachment.url()}" preload="metadata"></video>
6970
</a>

src/main/jte/pages/LogEntryView.jte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<div class="media-attachments mb-2 row" data-gallery="${"gallery"+message.getIndex()}">
7777
@for(var attachment: message.get().getAttachments().stream().filter(AttachmentFormatUtils::isMediaAttachment).toList())
7878
<div class="col-md-auto col-12">
79-
@template.macros.MediaAttachment(attachment = attachment, message = message.get(), nsfw = modmailLog.isNsfw())
79+
@template.macros.MediaAttachment(attachment = attachment, message = message.get(), nsfw = modmailLog.isNsfw(), galleryIndex = message.getIndex())
8080
</div>
8181
@endfor
8282
</div>
@@ -153,7 +153,7 @@
153153
<div class="media-attachments mb-2 row" data-gallery="${"gallery"+message.getIndex()}">
154154
@for(var attachment: message.get().getAttachments().stream().filter(AttachmentFormatUtils::isMediaAttachment).toList())
155155
<div class="col-md-auto col-12">
156-
@template.macros.MediaAttachment(attachment = attachment, message = message.get(), nsfw = modmailLog.isNsfw())
156+
@template.macros.MediaAttachment(attachment = attachment, message = message.get(), nsfw = modmailLog.isNsfw(), galleryIndex = message.getIndex())
157157
</div>
158158
@endfor
159159
</div>

0 commit comments

Comments
 (0)