Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Fix: Auto-expand content in old messages too. #669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions client/js/shout.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ $(function() {
function renderChannelMessages(data) {
var documentFragment = buildChannelMessages(data.id, data.messages);
chat.find("#chan-" + data.id + " .messages").append(documentFragment);
data.messages.forEach(function(e) {
if (e.type === "toggle" && e.toggle !== undefined) {
showToggle(e.toggle, false);
}
});
}

socket.on("msg", function(data) {
Expand All @@ -297,6 +302,11 @@ $(function() {
if (data.messages.length !== 100) {
chan.find(".show-more").removeClass("show");
}
data.messages.forEach(function(e) {
if (e.type === "toggle" && e.toggle !== undefined) {
showToggle(e.toggle, false);
}
});
});

socket.on("network", function(data) {
Expand Down Expand Up @@ -371,21 +381,7 @@ $(function() {
});

socket.on("toggle", function(data) {
var toggle = $("#toggle-" + data.id);
toggle.parent().after(render("toggle", {toggle: data}));
switch (data.type) {
case "link":
if (options.links) {
toggle.click();
}
break;

case "image":
if (options.thumbnails) {
toggle.click();
}
break;
}
showToggle(data, true);
});

socket.on("topic", function(data) {
Expand Down Expand Up @@ -953,6 +949,26 @@ $(function() {
return array;
}

function showToggle(data, renderNeeded) {
var toggle = $("#toggle-" + data.id);
if (renderNeeded) {
toggle.parent().after(render("toggle", {toggle: data}));
}
switch (data.type) {
case "link":
if (options.links) {
toggle.click();
}
break;

case "image":
if (options.thumbnails) {
toggle.click();
}
break;
}
}

document.addEventListener(
"visibilitychange",
function() {
Expand Down