Search in sources :

Example 1 with ChatData

use of com.xabber.android.data.message.ChatData in project xabber-android by redsolution.

the class ChatManager method loadChatDataFromRealm.

@Nullable
public ChatData loadChatDataFromRealm(AbstractChat chat) {
    String accountJid = chat.getAccount().toString();
    String userJid = chat.getUser().toString();
    ChatData chatData = null;
    Realm realm = RealmManager.getInstance().getNewRealm();
    ChatDataRealm realmChat = realm.where(ChatDataRealm.class).equalTo("accountJid", accountJid).equalTo("userJid", userJid).findFirst();
    if (realmChat != null) {
        NotificationState notificationState;
        if (realmChat.getNotificationState() != null) {
            notificationState = new NotificationState(realmChat.getNotificationState().getMode(), realmChat.getNotificationState().getTimestamp());
        } else
            notificationState = new NotificationState(NotificationState.NotificationMode.bydefault, 0);
        chatData = new ChatData(realmChat.getSubject(), realmChat.getAccountJid(), realmChat.getUserJid(), realmChat.getUnreadCount(), realmChat.isArchived(), notificationState);
    }
    realm.close();
    return chatData;
}
Also used : ChatData(com.xabber.android.data.message.ChatData) NotificationStateRealm(com.xabber.android.data.database.realm.NotificationStateRealm) Realm(io.realm.Realm) ChatDataRealm(com.xabber.android.data.database.realm.ChatDataRealm) ChatDataRealm(com.xabber.android.data.database.realm.ChatDataRealm) NotificationState(com.xabber.android.data.message.NotificationState) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)1 ChatDataRealm (com.xabber.android.data.database.realm.ChatDataRealm)1 NotificationStateRealm (com.xabber.android.data.database.realm.NotificationStateRealm)1 ChatData (com.xabber.android.data.message.ChatData)1 NotificationState (com.xabber.android.data.message.NotificationState)1 Realm (io.realm.Realm)1