mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-26 17:26:22 +00:00
option to hide button
This commit is contained in:
parent
a96e69fae5
commit
20c5d50c2d
1 changed files with 32 additions and 25 deletions
|
@ -31,6 +31,29 @@ const FindReplyIcon = () => {
|
||||||
</svg>;
|
</svg>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function findReply(message: Message) {
|
||||||
|
const messages: Array<Message & { deleted?: boolean; }> = [...MessageStore.getMessages(message.channel_id)?._array ?? []].filter(m => !m.deleted).sort((a, b) => {
|
||||||
|
return a.timestamp.toString().localeCompare(b.timestamp.toString());
|
||||||
|
}); // Need to deep copy Message array when sorting
|
||||||
|
for (const other of messages) {
|
||||||
|
if (other.timestamp.toString().localeCompare(message.timestamp.toString()) <= 0) continue;
|
||||||
|
if (other.messageReference?.message_id === message.id) {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
if (Vencord.Settings.plugins.FindReply.includePings) {
|
||||||
|
if (other.content?.includes(`<@${message.author.id}>`)) {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Vencord.Settings.plugins.FindReply.includeAuthor) {
|
||||||
|
if (messages.find(m => m.id === other.messageReference?.message_id)?.author.id === message.author.id) {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "FindReply",
|
name: "FindReply",
|
||||||
description: "Jumps to the earliest reply to a message in a channel (lets you follow past conversations more easily).",
|
description: "Jumps to the earliest reply to a message in a channel (lets you follow past conversations more easily).",
|
||||||
|
@ -38,37 +61,14 @@ export default definePlugin({
|
||||||
start() {
|
start() {
|
||||||
addButton("vc-findreply", message => {
|
addButton("vc-findreply", message => {
|
||||||
if (!message.id) return null;
|
if (!message.id) return null;
|
||||||
|
const reply = findReply(message);
|
||||||
|
if (Vencord.Settings.plugins.FindReply.hideButtonIfNoReply && !reply) return null;
|
||||||
return {
|
return {
|
||||||
label: "Jump to Reply",
|
label: "Jump to Reply",
|
||||||
icon: FindReplyIcon,
|
icon: FindReplyIcon,
|
||||||
message,
|
message,
|
||||||
channel: ChannelStore.getChannel(message.channel_id),
|
channel: ChannelStore.getChannel(message.channel_id),
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
const messages: Array<Message & { deleted?: boolean; }> = [...MessageStore.getMessages(message.channel_id)?._array ?? []].filter(m => !m.deleted).sort((a, b) => {
|
|
||||||
return a.timestamp.toString().localeCompare(b.timestamp.toString());
|
|
||||||
}); // Need to deep copy Message array when sorting
|
|
||||||
console.log(messages);
|
|
||||||
let reply: Message | null = null;
|
|
||||||
for (const other of messages) {
|
|
||||||
if (other.timestamp.toString().localeCompare(message.timestamp.toString()) <= 0) continue;
|
|
||||||
if (other.messageReference?.message_id === message.id) {
|
|
||||||
reply = other;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Vencord.Settings.plugins.FindReply.includePings) {
|
|
||||||
if (other.content?.includes(`<@${message.author.id}>`)) {
|
|
||||||
reply = other;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Vencord.Settings.plugins.FindReply.includeAuthor) {
|
|
||||||
if (messages.find(m => m.id === other.messageReference?.message_id)?.author.id === message.author.id) {
|
|
||||||
reply = other;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (reply) {
|
if (reply) {
|
||||||
const channelId = reply.channel_id;
|
const channelId = reply.channel_id;
|
||||||
const messageId = reply.id;
|
const messageId = reply.id;
|
||||||
|
@ -104,6 +104,13 @@ export default definePlugin({
|
||||||
description: "Will also search for messages that reply to the author in general, not just that exact message",
|
description: "Will also search for messages that reply to the author in general, not just that exact message",
|
||||||
default: false,
|
default: false,
|
||||||
restartNeeded: false
|
restartNeeded: false
|
||||||
|
},
|
||||||
|
hideButtonIfNoReply: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Hides the button if there are no replies to the message",
|
||||||
|
default: false,
|
||||||
|
restartNeeded: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue