diff options
Diffstat (limited to '')
8 files changed, 51 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 23001de7..38b5a999 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -277,8 +277,10 @@ public class Account extends AbstractEntity { return jid.getLocalpart(); } - public void setJid(final Jid jid) { - this.jid = jid; + public boolean setJid(final Jid next) { + final Jid prev = this.jid != null ? this.jid.toBareJid() : null; + this.jid = next; + return prev == null || (next != null && !prev.equals(next.toBareJid())); } public Jid getServer() { diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 3c00fd59..d9a03fc9 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -53,6 +53,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public static final String ATTRIBUTE_MUTED_TILL = "muted_till"; public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify"; public static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets"; + public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history"; private String name; private String contactUuid; @@ -332,11 +333,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public void setLastClearHistory(long time) { - setAttribute("last_clear_history",String.valueOf(time)); + setAttribute(ATTRIBUTE_LAST_CLEAR_HISTORY,String.valueOf(time)); } public long getLastClearHistory() { - return getLongAttribute("last_clear_history", 0); + return getLongAttribute(ATTRIBUTE_LAST_CLEAR_HISTORY, 0); } public List<Jid> getAcceptedCryptoTargets() { diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 0b3b2990..484b7b15 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -11,6 +11,7 @@ import android.util.Base64; import android.util.Log; import android.util.Pair; +import org.json.JSONObject; import org.whispersystems.libaxolotl.AxolotlAddress; import org.whispersystems.libaxolotl.IdentityKey; import org.whispersystems.libaxolotl.IdentityKeyPair; @@ -44,6 +45,7 @@ import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.PresenceTemplate; import eu.siacs.conversations.entities.Roster; import eu.siacs.conversations.entities.ServiceDiscoveryResult; +import eu.siacs.conversations.generator.AbstractGenerator; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -727,21 +729,37 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } + public Pair<Long,String> getLastClearDate(Account account) { + SQLiteDatabase db = this.getReadableDatabase(); + String[] columns = {Conversation.ATTRIBUTES}; + String selection = Conversation.ACCOUNT + "=?"; + String[] args = {account.getUuid()}; + Cursor cursor = db.query(Conversation.TABLENAME,columns,selection,args,null,null,null); + long maxClearDate = 0; + while (cursor.moveToNext()) { + try { + final JSONObject jsonObject = new JSONObject(cursor.getString(0)); + maxClearDate = Math.max(maxClearDate, jsonObject.getLong(Conversation.ATTRIBUTE_LAST_CLEAR_HISTORY)); + } catch (Exception e) { + //ignored + } + } + cursor.close(); + return new Pair<>(maxClearDate,null); + } + private Cursor getCursorForSession(Account account, AxolotlAddress contact) { final SQLiteDatabase db = this.getReadableDatabase(); - String[] columns = null; String[] selectionArgs = {account.getUuid(), contact.getName(), Integer.toString(contact.getDeviceId())}; - Cursor cursor = db.query(SQLiteAxolotlStore.SESSION_TABLENAME, - columns, + return db.query(SQLiteAxolotlStore.SESSION_TABLENAME, + null, SQLiteAxolotlStore.ACCOUNT + " = ? AND " + SQLiteAxolotlStore.NAME + " = ? AND " + SQLiteAxolotlStore.DEVICE_ID + " = ? ", selectionArgs, null, null, null); - - return cursor; } public SessionRecord loadSession(Account account, AxolotlAddress contact) { diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 06df1b38..a27e6c3e 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -45,8 +45,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } } - Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); - long startCatchup = pair == null ? 0 : pair.first; + final Pair<Long,String> lastMessageReceived = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); + final Pair<Long,String> lastClearDate = mXmppConnectionService.databaseBackend.getLastClearDate(account); + long startCatchup; + final String reference; + if (lastMessageReceived != null && lastMessageReceived.first >= lastClearDate.first) { + startCatchup = lastMessageReceived.first; + reference = lastMessageReceived.second; + } else { + startCatchup = lastClearDate.first; + reference = null; + } long endCatchup = account.getXmppConnection().getLastSessionEstablished(); final Query query; if (startCatchup == 0) { @@ -62,7 +71,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { query = new Query(account, startCatchup, endCatchup); } else { query = new Query(account, startCatchup, endCatchup); - query.reference = pair.second; + query.reference = reference; } this.queries.add(query); this.execute(query); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 4374b3f6..3bf1e745 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3340,6 +3340,7 @@ public class XmppConnectionService extends Service { @Override public void run() { databaseBackend.deleteMessagesInConversation(conversation); + databaseBackend.updateConversation(conversation); } }; mDatabaseExecutor.execute(runnable); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index ae31adcb..9e2b3ba7 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -458,6 +458,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { private void loadMoreMessages(Conversation conversation) { conversation.setLastClearHistory(0); + activity.xmppConnectionService.databaseBackend.updateConversation(conversation); conversation.setHasMessagesLeftOnServer(true); conversation.setFirstMamReference(null); long timestamp = conversation.getLastMessageTransmitted(); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index c9b5ea67..bf997bc1 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -95,10 +95,6 @@ public class UIHelper { return sameDay(date,new Date(System.currentTimeMillis())); } - public static boolean sameDay(long timestamp1, long timestamp2) { - return sameDay(new Date(timestamp1),new Date(timestamp2)); - } - private static boolean sameDay(Date a, Date b) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); @@ -185,7 +181,9 @@ public class UIHelper { } } else { String body = message.getBody(); - if (body.length() > 256) { + if (body == null) { + body = ""; + } else if (body.length() > 256) { body = body.substring(0,256); } if (body.startsWith(Message.ME_COMMAND)) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index fca5c566..e3af48e3 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -981,7 +981,10 @@ public class XmppConnection implements Runnable { final Element jid = bind.findChild("jid"); if (jid != null && jid.getContent() != null) { try { - account.setJid(Jid.fromString(jid.getContent())); + if (account.setJid(Jid.fromString(jid.getContent()))) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": bare jid changed during bind. updating database"); + mXmppConnectionService.databaseBackend.updateAccount(account); + } if (streamFeatures.hasChild("session") && !streamFeatures.findChild("session").hasChild("optional")) { sendStartSession(); |