From 1bd22920c6f0dc558677dbc4d8bcd42ea6570987 Mon Sep 17 00:00:00 2001 From: Arne Date: Mon, 22 May 2023 17:27:41 +0200 Subject: [PATCH] Helper to get thumbnails from SIMS element (Cheogram) --- .../siacs/conversations/entities/Message.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 4708c3311b..64331231a0 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -1402,6 +1402,26 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable return sims; } + public List getThumbnails() { + List thumbs = new ArrayList<>(); + if (sims == null) return thumbs; + + Element mediaSharing = sims.findChild("media-sharing", "urn:xmpp:sims:1"); + if (mediaSharing == null) return thumbs; + Element file = mediaSharing.findChild("file", "urn:xmpp:jingle:apps:file-transfer:5"); + if (file == null) file = mediaSharing.findChild("file", "urn:xmpp:jingle:apps:file-transfer:4"); + if (file == null) file = mediaSharing.findChild("file", "urn:xmpp:jingle:apps:file-transfer:3"); + if (file == null) return thumbs; + + for (Element child : file.getChildren()) { + if (child.getName().equals("thumbnail") && child.getNamespace().equals("urn:xmpp:thumbs:1")) { + thumbs.add(child); + } + } + + return thumbs; + } + public String toString() { final StringBuilder builder = new StringBuilder(); if (url != null) builder.append(url);