fix: allow forwarded messages with media in media-only channels#1419
fix: allow forwarded messages with media in media-only channels#1419VlaM5 wants to merge 2 commits intoTogether-Java:developfrom
Conversation
| // private boolean messageHasNoMediaAttached(Message message) { | ||
| // return message.getAttachments().isEmpty() && message.getEmbeds().isEmpty() | ||
| // && !message.getContentRaw().contains("http"); | ||
| // } |
There was a problem hiding this comment.
please remove commented-out-code
| if (hasMedia(message.getAttachments(), message.getEmbeds(), message.getContentRaw())) { | ||
| return false; | ||
| } | ||
| // checks forwarded snapshots | ||
| for (MessageSnapshot snapshot : message.getMessageSnapshots()) { | ||
| if (hasMedia(snapshot.getAttachments(), snapshot.getEmbeds(), snapshot.getContentRaw())) { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
do Message and MessageSnapshot share a common class? in that case i would prefer putting it all into a single list/stream:
Stream.concat(Stream.of(message), message.getMessageSnapshots().stream())(or a list)
and then looping on that so we dont duplicate the logic with the "if has media ... return false"
There was a problem hiding this comment.
Thank you! Message and MessageSnapshot don't share a common interface with
getAttachments/getEmbeds/getContentRaw, so Stream.concat on the
objects directly isn't possible. In a new commit i used stream().noneMatch() instead
to remove the explicit loop and keep the logic compact.
| * @param embeds the embeds of the message or snapshot | ||
| * @param content the raw text content of the message or snapshot | ||
| */ | ||
|
|
| verify(event.getMessage()).delete(); | ||
| } | ||
|
|
||
| // Добавить этот вспомогательный метод рядом с существующим sendMessage(): |
There was a problem hiding this comment.
Removed the comment — the method name sendMessageWithSnapshots
already describes what it does, so the comment was just noise.
Fixes #1243
Forwarded messages that contain media (attachments, embeds, or links)
were incorrectly deleted in media-only channels, because the bot only
checked the message itself, not its MessageSnapshots.
Changes: