use translated version of subject if available

This commit is contained in:
Daniel Gultsch 2018-03-05 13:02:00 +01:00
parent 7c1d91dd03
commit 3bff110587
2 changed files with 27 additions and 1 deletions

View file

@ -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);
}

View file

@ -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<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"))) {