From 3bff110587d7ff2da92625d10e23ecdcb8d6fb0c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 5 Mar 2018 13:02:00 +0100 Subject: [PATCH] use translated version of subject if available --- .../conversations/parser/MessageParser.java | 2 +- .../eu/siacs/conversations/xml/Element.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index d2d082a84..de1855def 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -606,7 +606,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (packet.hasChild("subject")) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0); - String subject = packet.findChildContent("subject"); + String subject = packet.findInternationalizedChildContent("subject"); if (conversation.getMucOptions().setSubject(subject)) { mXmppConnectionService.updateConversation(conversation); } diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index 34794be1b..97746b2d2 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -1,10 +1,13 @@ package eu.siacs.conversations.xml; +import android.support.annotation.NonNull; import android.util.Log; import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; +import java.util.Locale; import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.XmlHelper; @@ -67,6 +70,29 @@ public class Element { return element == null ? null : element.getContent(); } + public String findInternationalizedChildContent(String name) { + return findInternationalizedChildContent(name, Locale.getDefault().getLanguage()); + } + + public String findInternationalizedChildContent(String name,@NonNull String language) { + HashMap contents = new HashMap<>(); + for(Element child : this.children) { + if (name.equals(child.getName())) { + String lang = child.getAttribute("xml:lang"); + String content = child.getContent(); + if (content != null) { + if (language.equals(lang)) { + return content; + } else { + contents.put(lang, content); + } + } + } + } + + return contents.get(null); + } + public Element findChild(String name, String xmlns) { for (Element child : this.children) { if (name.equals(child.getName()) && xmlns.equals(child.getAttribute("xmlns"))) {