Search in sources :

Example 6 with MamReference

use of de.pixart.messenger.xmpp.mam.MamReference in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.services.MessageArchiveService) MamReference(de.pixart.messenger.xmpp.mam.MamReference)

Example 7 with MamReference

use of de.pixart.messenger.xmpp.mam.MamReference in project Pix-Art-Messenger by kriztan.

the class DatabaseBackend method getLastClearDate.

public MamReference 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);
    MamReference maxClearDate = new MamReference(0);
    while (cursor.moveToNext()) {
        try {
            final JSONObject o = new JSONObject(cursor.getString(0));
            maxClearDate = MamReference.max(maxClearDate, MamReference.fromAttribute(o.getString(Conversation.ATTRIBUTE_LAST_CLEAR_HISTORY)));
        } catch (Exception e) {
        // ignored
        }
    }
    cursor.close();
    return maxClearDate;
}
Also used : JSONObject(org.json.JSONObject) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MamReference(de.pixart.messenger.xmpp.mam.MamReference) Cursor(android.database.Cursor) JSONException(org.json.JSONException) CertificateEncodingException(java.security.cert.CertificateEncodingException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Aggregations

MamReference (de.pixart.messenger.xmpp.mam.MamReference)7 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)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 (de.pixart.messenger.entities.Account)1 Conversation (de.pixart.messenger.entities.Conversation)1 MessageArchiveService (de.pixart.messenger.services.MessageArchiveService)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 JSONObject (org.json.JSONObject)1