Search in sources :

Example 1 with MessageItem

use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.

the class AbstractChat method createMessageItem.

protected MessageItem createMessageItem(Resourcepart resource, String text, ChatAction action, Date delayTimestamp, boolean incoming, boolean notify, boolean encrypted, boolean offline, String stanzaId) {
    final boolean visible = MessageManager.getInstance().isVisibleChat(this);
    boolean read = incoming ? visible : true;
    boolean send = incoming;
    if (action == null && text == null) {
        throw new IllegalArgumentException();
    }
    if (text == null) {
        text = " ";
    }
    if (action != null) {
        read = true;
        send = true;
    }
    final Date timestamp = new Date();
    if (text.trim().isEmpty()) {
        notify = false;
    }
    if (notify || !incoming) {
        openChat();
    }
    if (!incoming) {
        notify = false;
    }
    if (isPrivateMucChat) {
        if (!isPrivateMucChatAccepted) {
            notify = false;
        }
    }
    MessageItem messageItem = new MessageItem();
    messageItem.setAccount(account);
    messageItem.setUser(user);
    if (resource == null) {
        messageItem.setResource(Resourcepart.EMPTY);
    } else {
        messageItem.setResource(resource);
    }
    if (action != null) {
        messageItem.setAction(action.toString());
    }
    messageItem.setText(text);
    messageItem.setTimestamp(timestamp.getTime());
    if (delayTimestamp != null) {
        messageItem.setDelayTimestamp(delayTimestamp.getTime());
    }
    messageItem.setIncoming(incoming);
    messageItem.setRead(read);
    messageItem.setSent(send);
    messageItem.setEncrypted(encrypted);
    messageItem.setOffline(offline);
    messageItem.setStanzaId(stanzaId);
    FileManager.processFileMessage(messageItem);
    if (notify && notifyAboutMessage() && !visible) {
        NotificationManager.getInstance().onMessageNotification(messageItem);
    }
    // unread message count
    if (!visible && action == null) {
        if (incoming)
            increaseUnreadMessageCount();
        else
            resetUnreadMessageCount();
    }
    // remove notifications if get outgoing message
    if (!incoming)
        NotificationManager.getInstance().removeMessageNotification(account, user);
    // when getting new message, unarchive chat if chat not muted
    if (this.notifyAboutMessage())
        this.archived = false;
    return messageItem;
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Date(java.util.Date)

Example 2 with MessageItem

use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.

the class MessageManager method onLoad.

@Override
public void onLoad() {
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            RealmResults<MessageItem> messagesToSend = realm.where(MessageItem.class).equalTo(MessageItem.Fields.SENT, false).findAll();
            for (MessageItem messageItem : messagesToSend) {
                AccountJid account = messageItem.getAccount();
                UserJid user = messageItem.getUser();
                if (account != null && user != null) {
                    if (getChat(account, user) == null) {
                        createChat(account, user);
                    }
                }
            }
        }
    });
    realm.close();
    NotificationManager.getInstance().registerNotificationProvider(mucPrivateChatRequestProvider);
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Realm(io.realm.Realm) RealmResults(io.realm.RealmResults)

Example 3 with MessageItem

use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.

the class MessageManager method updateFileMessage.

public void updateFileMessage(AccountJid account, UserJid user, final String messageId, final String url) {
    final AbstractChat chat = getChat(account, user);
    if (chat == null) {
        return;
    }
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
            if (messageItem != null) {
                messageItem.setText(url);
                messageItem.setSent(false);
                messageItem.setInProgress(false);
            }
        }
    });
    realm.close();
    chat.sendMessages();
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Realm(io.realm.Realm)

Example 4 with MessageItem

use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.

the class MessageManager method updateMessageWithError.

public void updateMessageWithError(final String messageId, final String errorDescription) {
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            MessageItem messageItem = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, messageId).findFirst();
            if (messageItem != null) {
                messageItem.setError(true);
                messageItem.setErrorDescription(errorDescription);
                messageItem.setInProgress(false);
            }
        }
    });
    realm.close();
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Realm(io.realm.Realm)

Example 5 with MessageItem

use of com.xabber.android.data.database.messagerealm.MessageItem in project xabber-android by redsolution.

the class ReceiptManager method markAsDelivered.

private void markAsDelivered(final Jid toJid, final String receiptId) {
    Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
    realm.beginTransaction();
    MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.STANZA_ID, receiptId).findFirst();
    if (first != null) {
        first.setDelivered(true);
    }
    realm.commitTransaction();
    realm.close();
    EventBus.getDefault().post(new MessageUpdateEvent());
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Realm(io.realm.Realm)

Aggregations

MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)24 Realm (io.realm.Realm)14 Date (java.util.Date)6 UserJid (com.xabber.android.data.entity.UserJid)4 AccountItem (com.xabber.android.data.account.AccountItem)3 ArrayList (java.util.ArrayList)3 Message (org.jivesoftware.smack.packet.Message)3 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)3 NetworkException (com.xabber.android.data.NetworkException)2 SyncInfo (com.xabber.android.data.database.messagerealm.SyncInfo)2 AccountJid (com.xabber.android.data.entity.AccountJid)2 AbstractChat (com.xabber.android.data.message.AbstractChat)2 ChatAction (com.xabber.android.data.message.ChatAction)2 RealmResults (io.realm.RealmResults)2 File (java.io.File)2 IOException (java.io.IOException)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1