Search in sources :

Example 6 with MamReference

use of eu.siacs.conversations.xmpp.mam.MamReference in project Conversations by siacs.

the class MessageAdapter method loadMoreMessages.

private void loadMoreMessages(Conversation conversation) {
    conversation.setLastClearHistory(0, null);
    activity.xmppConnectionService.updateConversation(conversation);
    conversation.setHasMessagesLeftOnServer(true);
    conversation.setFirstMamReference(null);
    long timestamp = conversation.getLastMessageTransmitted().getTimestamp();
    if (timestamp == 0) {
        timestamp = System.currentTimeMillis();
    }
    conversation.messagesLoaded.set(true);
    MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false);
    if (query != null) {
        Toast.makeText(activity, R.string.fetching_history_from_server, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(activity, R.string.not_fetching_history_retention_period, Toast.LENGTH_SHORT).show();
    }
}
Also used : MessageArchiveService(eu.siacs.conversations.services.MessageArchiveService) MamReference(eu.siacs.conversations.xmpp.mam.MamReference)

Example 7 with MamReference

use of eu.siacs.conversations.xmpp.mam.MamReference in project Conversations by siacs.

the class MessageArchiveService method catchup.

private void catchup(final Account account) {
    synchronized (this.queries) {
        for (Iterator<Query> iterator = this.queries.iterator(); iterator.hasNext(); ) {
            Query query = iterator.next();
            if (query.getAccount() == account) {
                iterator.remove();
            }
        }
    }
    MamReference mamReference = MamReference.max(mXmppConnectionService.databaseBackend.getLastMessageReceived(account), mXmppConnectionService.databaseBackend.getLastClearDate(account));
    mamReference = MamReference.max(mamReference, mXmppConnectionService.getAutomaticMessageDeletionDate());
    long endCatchup = account.getXmppConnection().getLastSessionEstablished();
    final Query query;
    if (mamReference.getTimestamp() == 0) {
        return;
    } else if (endCatchup - mamReference.getTimestamp() >= Config.MAM_MAX_CATCHUP) {
        long startCatchup = endCatchup - Config.MAM_MAX_CATCHUP;
        List<Conversation> conversations = mXmppConnectionService.getConversations();
        for (Conversation conversation : conversations) {
            if (conversation.getMode() == Conversation.MODE_SINGLE && conversation.getAccount() == account && startCatchup > conversation.getLastMessageTransmitted().getTimestamp()) {
                this.query(conversation, startCatchup, true);
            }
        }
        query = new Query(account, new MamReference(startCatchup), 0);
    } else {
        query = new Query(account, mamReference, 0);
    }
    synchronized (this.queries) {
        this.queries.add(query);
    }
    this.execute(query);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Conversation(eu.siacs.conversations.entities.Conversation) MamReference(eu.siacs.conversations.xmpp.mam.MamReference)

Aggregations

MamReference (eu.siacs.conversations.xmpp.mam.MamReference)7 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 IOException (java.io.IOException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JSONException (org.json.JSONException)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 Account (eu.siacs.conversations.entities.Account)1 Conversation (eu.siacs.conversations.entities.Conversation)1 MessageArchiveService (eu.siacs.conversations.services.MessageArchiveService)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JSONObject (org.json.JSONObject)1