mark oob messages and always display download button

This commit is contained in:
Daniel Gultsch 2016-03-04 20:09:21 +01:00
parent aa24a0f779
commit 09d87965fb
4 changed files with 30 additions and 6 deletions

View File

@ -52,6 +52,7 @@ public class Message extends AbstractEntity {
public static final String STATUS = "status"; public static final String STATUS = "status";
public static final String TYPE = "type"; public static final String TYPE = "type";
public static final String CARBON = "carbon"; public static final String CARBON = "carbon";
public static final String OOB = "oob";
public static final String EDITED = "edited"; public static final String EDITED = "edited";
public static final String REMOTE_MSG_ID = "remoteMsgId"; public static final String REMOTE_MSG_ID = "remoteMsgId";
public static final String SERVER_MSG_ID = "serverMsgId"; public static final String SERVER_MSG_ID = "serverMsgId";
@ -72,6 +73,7 @@ public class Message extends AbstractEntity {
protected int status; protected int status;
protected int type; protected int type;
protected boolean carbon = false; protected boolean carbon = false;
protected boolean oob = false;
protected String edited = null; protected String edited = null;
protected String relativeFilePath; protected String relativeFilePath;
protected boolean read = true; protected boolean read = true;
@ -107,7 +109,8 @@ public class Message extends AbstractEntity {
null, null,
null, null,
true, true,
null); null,
false);
this.conversation = conversation; this.conversation = conversation;
} }
@ -116,7 +119,7 @@ public class Message extends AbstractEntity {
final int encryption, final int status, final int type, final boolean carbon, final int encryption, final int status, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath, final String remoteMsgId, final String relativeFilePath,
final String serverMsgId, final String fingerprint, final boolean read, final String serverMsgId, final String fingerprint, final boolean read,
final String edited) { final String edited, final boolean oob) {
this.uuid = uuid; this.uuid = uuid;
this.conversationUuid = conversationUUid; this.conversationUuid = conversationUUid;
this.counterpart = counterpart; this.counterpart = counterpart;
@ -133,6 +136,7 @@ public class Message extends AbstractEntity {
this.axolotlFingerprint = fingerprint; this.axolotlFingerprint = fingerprint;
this.read = read; this.read = read;
this.edited = edited; this.edited = edited;
this.oob = oob;
} }
public static Message fromCursor(Cursor cursor) { public static Message fromCursor(Cursor cursor) {
@ -173,7 +177,8 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)), cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)),
cursor.getString(cursor.getColumnIndex(FINGERPRINT)), cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
cursor.getInt(cursor.getColumnIndex(READ)) > 0, cursor.getInt(cursor.getColumnIndex(READ)) > 0,
cursor.getString(cursor.getColumnIndex(EDITED))); cursor.getString(cursor.getColumnIndex(EDITED)),
cursor.getInt(cursor.getColumnIndex(OOB)) > 0);
} }
public static Message createStatusMessage(Conversation conversation, String body) { public static Message createStatusMessage(Conversation conversation, String body) {
@ -219,6 +224,7 @@ public class Message extends AbstractEntity {
values.put(FINGERPRINT, axolotlFingerprint); values.put(FINGERPRINT, axolotlFingerprint);
values.put(READ,read ? 1 : 0); values.put(READ,read ? 1 : 0);
values.put(EDITED, edited); values.put(EDITED, edited);
values.put(OOB, oob ? 1 : 0);
return values; return values;
} }
@ -554,6 +560,10 @@ public class Message extends AbstractEntity {
return edited; return edited;
} }
public void setOob(boolean isOob) {
this.oob = isOob;
}
public enum Decision { public enum Decision {
MUST, MUST,
SHOULD, SHOULD,
@ -610,6 +620,8 @@ public class Message extends AbstractEntity {
URL url = new URL(body); URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) { if (!url.getProtocol().equalsIgnoreCase("http") && !url.getProtocol().equalsIgnoreCase("https")) {
return Decision.NEVER; return Decision.NEVER;
} else if (oob) {
return Decision.MUST;
} }
String extension = extractRelevantExtension(url); String extension = extractRelevantExtension(url);
if (extension == null) { if (extension == null) {

View File

@ -6,6 +6,7 @@ import android.util.Pair;
import net.java.otr4j.session.Session; import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -290,7 +291,9 @@ public class MessageParser extends AbstractParser implements
final String body = packet.getBody(); final String body = packet.getBody();
final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user"); final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user");
final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted"); final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
final Element replaceElement = packet.findChild("replace","urn:xmpp:message-correct:0"); final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0");
final Element oob = packet.findChild("x", "jabber:x:oob");
final boolean isOob = oob!= null && body != null && body.equals(oob.findChildContent("url"));
final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id"); final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id");
final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX); final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
int status; int status;
@ -384,6 +387,7 @@ public class MessageParser extends AbstractParser implements
message.setServerMsgId(serverMsgId); message.setServerMsgId(serverMsgId);
message.setCarbon(isCarbon); message.setCarbon(isCarbon);
message.setTime(timestamp); message.setTime(timestamp);
message.setOob(isOob);
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart()); Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());

View File

@ -51,7 +51,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null; private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history"; private static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 24; private static final int DATABASE_VERSION = 25;
private static String CREATE_CONTATCS_STATEMENT = "create table " private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
@ -163,6 +163,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Message.CARBON + " INTEGER, " + Message.CARBON + " INTEGER, "
+ Message.EDITED + " TEXT, " + Message.EDITED + " TEXT, "
+ Message.READ + " NUMBER DEFAULT 1, " + Message.READ + " NUMBER DEFAULT 1, "
+ Message.OOB + " INTEGER, "
+ Message.REMOTE_MSG_ID + " TEXT, FOREIGN KEY(" + Message.REMOTE_MSG_ID + " TEXT, FOREIGN KEY("
+ Message.CONVERSATION + ") REFERENCES " + Message.CONVERSATION + ") REFERENCES "
+ Conversation.TABLENAME + "(" + Conversation.UUID + Conversation.TABLENAME + "(" + Conversation.UUID
@ -375,6 +376,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
if (oldVersion < 24 && newVersion >= 24) { if (oldVersion < 24 && newVersion >= 24) {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT"); db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
} }
if (oldVersion < 25 && newVersion >= 25) {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
}
} }
public static synchronized DatabaseBackend getInstance(Context context) { public static synchronized DatabaseBackend getInstance(Context context) {

View File

@ -187,10 +187,13 @@ public class UIHelper {
UIHelper.getMessageDisplayName(message) + " "), false); UIHelper.getMessageDisplayName(message) + " "), false);
} else if (GeoHelper.isGeoUri(message.getBody())) { } else if (GeoHelper.isGeoUri(message.getBody())) {
if (message.getStatus() == Message.STATUS_RECEIVED) { if (message.getStatus() == Message.STATUS_RECEIVED) {
return new Pair<>(context.getString(R.string.received_location),true); return new Pair<>(context.getString(R.string.received_location), true);
} else { } else {
return new Pair<>(context.getString(R.string.location), true); return new Pair<>(context.getString(R.string.location), true);
} }
} else if (message.treatAsDownloadable() == Message.Decision.MUST) {
return new Pair<>(context.getString(R.string.x_file_offered_for_download,
getFileDescriptionString(context,message)),true);
} else{ } else{
return new Pair<>(message.getBody().trim(), false); return new Pair<>(message.getBody().trim(), false);
} }