aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-01 23:27:28 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-01 23:27:28 +0200
commit0534717f1ed05bbcc8789f8105a77df6823c69e6 (patch)
treee453ede40d87ba478637eb80b976314804d1302d
parent554266bbf63551547c82ada832469eddd59a356e (diff)
use translated version of subject if available
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java2
-rw-r--r--src/main/java/de/pixart/messenger/xml/Element.java26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 4591ca138..e352d0771 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -714,7 +714,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/de/pixart/messenger/xml/Element.java b/src/main/java/de/pixart/messenger/xml/Element.java
index 7ed08a483..13f5125ed 100644
--- a/src/main/java/de/pixart/messenger/xml/Element.java
+++ b/src/main/java/de/pixart/messenger/xml/Element.java
@@ -1,10 +1,13 @@
package de.pixart.messenger.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 de.pixart.messenger.Config;
import de.pixart.messenger.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<String, String> 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"))) {