mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-05 18:58:34 +01:00
Fix editing & deleting not working with mirroring
This commit is contained in:
parent
62b3f0b8b3
commit
2cc92d6179
@ -49,7 +49,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
||||||
|
|
||||||
private final Cache<MessageReference, Set<MessageReference>> mapping;
|
private final Cache<String, Set<MessageReference>> mapping;
|
||||||
|
|
||||||
public DiscordMessageMirroringModule(DiscordSRV discordSRV) {
|
public DiscordMessageMirroringModule(DiscordSRV discordSRV) {
|
||||||
super(discordSRV, new NamedLogger(discordSRV, "DISCORD_MIRRORING"));
|
super(discordSRV, new NamedLogger(discordSRV, "DISCORD_MIRRORING"));
|
||||||
@ -133,7 +133,7 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
|||||||
for (Pair<ReceivedDiscordMessage, OrDefault<MirroringConfig>> pair : messages) {
|
for (Pair<ReceivedDiscordMessage, OrDefault<MirroringConfig>> pair : messages) {
|
||||||
references.add(getReference(pair.getKey(), pair.getValue()));
|
references.add(getReference(pair.getKey(), pair.getValue()));
|
||||||
}
|
}
|
||||||
mapping.put(getReference(message, null), references);
|
mapping.put(getCacheKey(message), references);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDiscordMessageUpdate(DiscordMessageUpdateEvent event) {
|
public void onDiscordMessageUpdate(DiscordMessageUpdateEvent event) {
|
||||||
ReceivedDiscordMessage message = event.getMessage();
|
ReceivedDiscordMessage message = event.getMessage();
|
||||||
Set<MessageReference> references = mapping.get(getReference(message, null), k -> null);
|
Set<MessageReference> references = mapping.get(getCacheKey(message), k -> null);
|
||||||
if (references == null) {
|
if (references == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onDiscordMessageDelete(DiscordMessageDeleteEvent event) {
|
public void onDiscordMessageDelete(DiscordMessageDeleteEvent event) {
|
||||||
Set<MessageReference> references = mapping.get(getReference(event.getChannel(), event.getMessageId(), false, null), k -> null);
|
Set<MessageReference> references = mapping.get(getCacheKey(event.getChannel(), event.getMessageId()), k -> null);
|
||||||
if (references == null) {
|
if (references == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -230,6 +230,26 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
|||||||
throw new IllegalStateException("Unexpected channel type: " + channel.getClass().getName());
|
throw new IllegalStateException("Unexpected channel type: " + channel.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getCacheKey(ReceivedDiscordMessage message) {
|
||||||
|
return getCacheKey(message.getChannel(), message.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getCacheKey(DiscordMessageChannel channel, long messageId) {
|
||||||
|
if (channel instanceof DiscordTextChannel) {
|
||||||
|
return getCacheKey(channel.getId(), 0L, messageId);
|
||||||
|
} else if (channel instanceof DiscordThreadChannel) {
|
||||||
|
long parentId = ((DiscordThreadChannel) channel).getParentChannel().getId();
|
||||||
|
return getCacheKey(channel.getId(), parentId, messageId);
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Unexpected channel type: " + channel.getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getCacheKey(long channelId, long threadId, long messageId) {
|
||||||
|
return Long.toUnsignedString(channelId)
|
||||||
|
+ (threadId > 0 ? ":" + Long.toUnsignedString(threadId) : "")
|
||||||
|
+ ":" + Long.toUnsignedString(messageId);
|
||||||
|
}
|
||||||
|
|
||||||
public static class MessageReference {
|
public static class MessageReference {
|
||||||
|
|
||||||
private final long channelId;
|
private final long channelId;
|
||||||
@ -285,20 +305,5 @@ public class DiscordMessageMirroringModule extends AbstractModule<DiscordSRV> {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
MessageReference that = (MessageReference) o;
|
|
||||||
// Intentionally ignores webhookMessage
|
|
||||||
return channelId == that.channelId && threadId == that.threadId && messageId == that.messageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
// Intentionally ignores webhookMessage
|
|
||||||
return Objects.hash(channelId, threadId, messageId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user