Skip to content

Comments

fix: allow forwarded messages with media in media-only channels#1419

Open
VlaM5 wants to merge 2 commits intoTogether-Java:developfrom
VlaM5:fix/forward-media-to-media-channel
Open

fix: allow forwarded messages with media in media-only channels#1419
VlaM5 wants to merge 2 commits intoTogether-Java:developfrom
VlaM5:fix/forward-media-to-media-channel

Conversation

@VlaM5
Copy link

@VlaM5 VlaM5 commented Feb 23, 2026

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:

  • Extended messageHasNoMediaAttached() to also check MessageSnapshot contents
  • Extracted hasMedia() helper method for reuse
  • Added tests for forwarded messages with and without media

@VlaM5 VlaM5 requested a review from a team as a code owner February 23, 2026 13:06
@CLAassistant
Copy link

CLAassistant commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

Comment on lines 56 to 59
// private boolean messageHasNoMediaAttached(Message message) {
// return message.getAttachments().isEmpty() && message.getEmbeds().isEmpty()
// && !message.getContentRaw().contains("http");
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented-out-code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines 72 to 80
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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dangling newline

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

verify(event.getMessage()).delete();
}

// Добавить этот вспомогательный метод рядом с существующим sendMessage():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

english please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment — the method name sendMessageWithSnapshots
already describes what it does, so the comment was just noise.

@VlaM5 VlaM5 requested a review from Zabuzard February 23, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to forward messages with images to media channels

3 participants