diff --git a/build.gradle b/build.gradle index 90ae25443..83dbd83b5 100644 --- a/build.gradle +++ b/build.gradle @@ -113,6 +113,7 @@ dependencies { implementation 'com.github.woltapp:blurhash:master' implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'com.caverock:androidsvg-aar:1.4' + implementation 'org.tomlj:tomlj:1.1.0' } ext { diff --git a/src/main/java/de/monocles/chat/WebxdcPage.java b/src/main/java/de/monocles/chat/WebxdcPage.java index 2c797c345..9e599faa7 100644 --- a/src/main/java/de/monocles/chat/WebxdcPage.java +++ b/src/main/java/de/monocles/chat/WebxdcPage.java @@ -40,6 +40,9 @@ import java.util.zip.ZipFile; import org.json.JSONObject; import org.json.JSONException; +import org.tomlj.Toml; +import org.tomlj.TomlTable; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.WebxdcPageBinding; @@ -56,8 +59,10 @@ public class WebxdcPage implements ConversationPage { protected XmppConnectionService xmppConnectionService; protected WebxdcPageBinding binding = null; protected ZipFile zip = null; + protected TomlTable manifest = null; protected String baseUrl; protected Message source; + protected WebxdcUpdate lastUpdate = null; public WebxdcPage(Cid cid, Message source, XmppConnectionService xmppConnectionService) { this.xmppConnectionService = xmppConnectionService; @@ -65,6 +70,10 @@ public class WebxdcPage implements ConversationPage { File f = xmppConnectionService.getFileForCid(cid); try { if (f != null) zip = new ZipFile(xmppConnectionService.getFileForCid(cid)); + final ZipEntry manifestEntry = zip.getEntry("manifest.toml"); + if (manifestEntry != null) { + manifest = Toml.parse(zip.getInputStream(manifestEntry)); + } } catch (final IOException e) { Log.w(Config.LOGTAG, "WebxdcPage: " + e); } @@ -77,7 +86,15 @@ public class WebxdcPage implements ConversationPage { } public String getTitle() { - return "WebXDC"; + String title = manifest == null ? null : manifest.getString("name"); + if (lastUpdate != null && lastUpdate.getDocument() != null) { + if (title == null) { + title = lastUpdate.getDocument(); + } else { + title += ": " + lastUpdate.getDocument(); + } + } + return title == null ? "ChatApp" : title; } public String getNode() { @@ -316,6 +333,7 @@ public class WebxdcPage implements ConversationPage { StringBuilder builder = new StringBuilder("["); String sep = ""; for (WebxdcUpdate update : xmppConnectionService.findWebxdcUpdates(source, lastKnownSerial)) { + lastUpdate = update; builder.append(sep); builder.append(update.toString()); sep = ","; diff --git a/src/main/java/de/monocles/chat/WebxdcUpdate.java b/src/main/java/de/monocles/chat/WebxdcUpdate.java index 042027047..97db383ab 100644 --- a/src/main/java/de/monocles/chat/WebxdcUpdate.java +++ b/src/main/java/de/monocles/chat/WebxdcUpdate.java @@ -55,6 +55,10 @@ public class WebxdcUpdate { return summary; } + public String getDocument() { + return document; + } + public ContentValues getContentValues() { ContentValues cv = new ContentValues(); cv.put(Message.CONVERSATION, conversationId);