resolve channel names
This commit is contained in:
parent
ece85e2b78
commit
b881898e1a
@ -1,5 +1,6 @@
|
||||
var contentTable;
|
||||
contentOptions = null;
|
||||
channelResolveInterval = null;
|
||||
|
||||
async function initContentTable() {
|
||||
contentOptions = await getTrackedContentOptions();
|
||||
@ -67,9 +68,13 @@ async function initContentTable() {
|
||||
{
|
||||
title: "Channel",
|
||||
data: "channel_id",
|
||||
className: "text-start content-channel-id",
|
||||
render: function(data) {
|
||||
return $("<span>").text(data)[0];
|
||||
className: "text-start",
|
||||
render: function(data, type, row) {
|
||||
return `<div class="resolve-channel-name text-center" data-channel-id="${data}" data-msg-id="${row.message_id}">
|
||||
<div class="spinner-border spinner-border-sm" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -100,47 +105,54 @@ async function initContentTable() {
|
||||
});
|
||||
|
||||
bindTableCheckboxes("#contentTable", contentTable, "#contentTabPane .table-del-btn");
|
||||
|
||||
contentTable.on("draw", function() {
|
||||
restartResolveChannelNamesTask();
|
||||
});
|
||||
}
|
||||
|
||||
function handleDiscordChannelNames() {
|
||||
let interval = setInterval(function() {
|
||||
|
||||
if (!discordChannels.length)
|
||||
return;
|
||||
// #region Resolve Channels
|
||||
|
||||
$("#contentTable tr td.content-channel-id").each(function() {
|
||||
let tracked = contentTable.row($(this).closest("tr")).data();
|
||||
channel = discordChannels.find(item => item.value === tracked.channel_id);
|
||||
function restartResolveChannelNamesTask() {
|
||||
clearInterval(channelResolveInterval);
|
||||
startResolveChannelNamesTask();
|
||||
}
|
||||
|
||||
if (!channel)
|
||||
return;
|
||||
function startResolveChannelNamesTask() {
|
||||
const guildId = getCurrentlyActiveServer().guild_id;
|
||||
channelResolveInterval = setInterval(function() {
|
||||
if (resolveChannelNames(guildId))
|
||||
clearInterval(channelResolveInterval);
|
||||
}, 50)
|
||||
}
|
||||
|
||||
$(this).text("").append(
|
||||
$("<a>")
|
||||
.attr("href", `https://discord.com/channels/${getCurrentlyActiveServer().guild_id}/${channel.value}/${tracked.message_id}`)
|
||||
.attr("target", "_blank")
|
||||
.addClass("text-decoration-none")
|
||||
.text(channel.text)
|
||||
function resolveChannelNames(guildId) {
|
||||
if (!discordChannels.length)
|
||||
return false
|
||||
|
||||
$(".resolve-channel-name").each(function() {
|
||||
const channelId = $(this).data("channel-id");
|
||||
const messageId = $(this).data("msg-id");
|
||||
console.log(channelId + " " + messageId);
|
||||
const channel = discordChannels.find(channel => channel.value === channelId);
|
||||
|
||||
if (channel) {
|
||||
const href = `https://discord.com/channels/${guildId}/${channelId}/${messageId}/`;
|
||||
$(this).replaceWith(
|
||||
$("<a>").text(channel.text)
|
||||
.attr("href", href)
|
||||
.attr("target", "_blank")
|
||||
.addClass("text-decoration-none text-nowrap")
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// $(".replace-discord-channel-id-with-name").each(function() {
|
||||
// let displayChannel = discordChannels.find(channel => channel.value == $(this).text());
|
||||
// if (displayChannel) {
|
||||
// $(this).text("").append(
|
||||
// $("<a>")
|
||||
// .attr("href", `https://discord.com/channels/${getCurrentlyActiveServer().guild_id}/${displayChannel.value}`)
|
||||
// .attr("target", "_blank")
|
||||
// .addClass("text-decoration-none")
|
||||
// .text(displayChannel.text)
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
}, 600);
|
||||
return true;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
async function goToSubscription(subId) {
|
||||
$("#subscriptionsTab").click();
|
||||
await showEditSubModal(subId);
|
||||
@ -181,9 +193,12 @@ function clearExistingContentRows() {
|
||||
}
|
||||
|
||||
$("#contentTabPane").on("click", ".table-refresh-btn", async function() {
|
||||
loadContent(getCurrentlyActiveServer().guild_id);
|
||||
await loadContent(getCurrentlyActiveServer().guild_id);
|
||||
});
|
||||
|
||||
|
||||
// #region Load Content
|
||||
|
||||
async function loadContent(guildId) {
|
||||
|
||||
if (!guildId)
|
||||
@ -223,3 +238,5 @@ $(document).on("selectedServerChange", async function() {
|
||||
const activeServer = getCurrentlyActiveServer();
|
||||
await loadContent(activeServer.guild_id);
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user