diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-12 19:44:01 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-12 19:44:01 +0200 |
commit | 85b8ec7702f5423c82d601c9c265415de344e26e (patch) | |
tree | 2b62a61dc8fb9540781b44daf781e5fad8a61d40 /src/main/java/de/pixart/messenger/entities | |
parent | 0abffde5ef442e8bff1ce7cbfe84bf7e750b3136 (diff) |
show language in message bubble if multiple language variants were received
XML and by inheritence XMPP has the feature of transmitting multiple language
variants for the same content. This can be really useful if, for example, you
are talking to an automated system. A chat bot could greet you in your own
language.
On the wire this will usually look like this:
```xml
<message to="you">
<body>Good morning</body>
<body xml:lang="de">Guten Morgen</body>
</message>
```
However receiving such a message in a group chat can be very confusing and
potentially dangerous if the sender puts conflicting information in there and
different people get shown different strings.
Disabling support for localization entirely isn’t an ideal solution as on
principle it is still a good feature; and other clients might still show a
localization even if Conversations would always show the default language.
So instead we now show the displayed language in a corner of the
message bubble if more than one translation has been received.
If multiple languages are received we will attempt to find one in
the language the operating system is set to. If no such translation can be
found it will attempt to display the English string.
If English can not be found either (for example a message that only has ru and
fr on a phone that is set to de) it will display what ever language came first.
Furthermore we will discard (not show at all) messages with with
multiple bodies of the same language. (This is considered an invalid message)
The language tag will not be shown if we receive a single body in
a language not understood by the user. (For example operating system set to
'de' and message received with one body in 'ru' will just display that body as
usual.)
As a guide line to the user: If you are reading a message where it is important
that this message is not interpreted differently by different people (like a
vote (+1 / -1) in a chat room) make sure it has *no* language tag.
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/IndividualMessage.java | 8 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Message.java | 21 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java index 195ea82c1..3daa27964 100644 --- a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java +++ b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java @@ -41,8 +41,8 @@ public class IndividualMessage extends Message { super(conversation); } - private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, boolean deleted, String edited, boolean oob, String errorMessage, Set<ReadByMarker> readByMarkers, boolean markable, boolean file_deleted) { - super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, deleted, edited, oob, errorMessage, readByMarkers, markable, file_deleted); + private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, boolean deleted, String edited, boolean oob, String errorMessage, Set<ReadByMarker> readByMarkers, boolean markable, boolean file_deleted, String bodyLanguage) { + super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, deleted, edited, oob, errorMessage, readByMarkers, markable, file_deleted, bodyLanguage); } public static Message createDateSeparator(Message message) { @@ -100,7 +100,9 @@ public class IndividualMessage extends Message { cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)), ReadByMarker.fromJsonString(cursor.getString(cursor.getColumnIndex(READ_BY_MARKERS))), cursor.getInt(cursor.getColumnIndex(MARKABLE)) > 0, - cursor.getInt(cursor.getColumnIndex(FILE_DELETED)) > 0); + cursor.getInt(cursor.getColumnIndex(FILE_DELETED)) > 0, + cursor.getString(cursor.getColumnIndex(BODY_LANGUAGE)) + ); } @Override diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index e67519180..0010222d8 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -64,6 +64,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable public static final String COUNTERPART = "counterpart"; public static final String TRUE_COUNTERPART = "trueCounterpart"; public static final String BODY = "body"; + public static final String BODY_LANGUAGE = "bodyLanguage"; public static final String TIME_SENT = "timeSent"; public static final String ENCRYPTION = "encryption"; public static final String STATUS = "status"; @@ -102,6 +103,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable protected boolean read = true; protected boolean deleted = false; protected String remoteMsgId = null; + private String bodyLanguage = null; protected String serverMsgId = null; private final Conversational conversation; protected Transferable transferable = null; @@ -150,7 +152,8 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable null, null, false, - false); + false, + null); } protected Message(final Conversational conversation, final String uuid, final String conversationUUid, final Jid counterpart, @@ -159,7 +162,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable final String remoteMsgId, final String relativeFilePath, final String serverMsgId, final String fingerprint, final boolean read, final boolean deleted, final String edited, final boolean oob, final String errorMessage, final Set<ReadByMarker> readByMarkers, - final boolean markable, final boolean file_deleted) { + final boolean markable, final boolean file_deleted, final String bodyLanguage) { this.conversation = conversation; this.uuid = uuid; this.conversationUuid = conversationUUid; @@ -183,6 +186,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable this.readByMarkers = readByMarkers == null ? new HashSet<ReadByMarker>() : readByMarkers; this.markable = markable; this.file_deleted = file_deleted; + this.bodyLanguage = bodyLanguage; } public static Message fromCursor(Cursor cursor, Conversation conversation) { @@ -208,7 +212,9 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)), ReadByMarker.fromJsonString(cursor.getString(cursor.getColumnIndex(READ_BY_MARKERS))), cursor.getInt(cursor.getColumnIndex(MARKABLE)) > 0, - cursor.getInt(cursor.getColumnIndex(FILE_DELETED)) > 0); + cursor.getInt(cursor.getColumnIndex(FILE_DELETED)) > 0, + cursor.getString(cursor.getColumnIndex(BODY_LANGUAGE)) + ); } private static Jid fromString(String value) { @@ -270,6 +276,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable values.put(READ_BY_MARKERS, ReadByMarker.toJson(readByMarkers).toString()); values.put(MARKABLE, markable ? 1 : 0); values.put(FILE_DELETED, file_deleted ? 1 : 0); + values.put(BODY_LANGUAGE, bodyLanguage); return values; } @@ -440,6 +447,14 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable this.edited = edited; } + public String getBodyLanguage() { + return this.bodyLanguage; + } + + public void setBodyLanguage(String language) { + this.bodyLanguage = language; + } + public boolean edited() { return this.edited != null; } |