use of com.xabber.android.data.database.messagerealm.SyncInfo in project xabber-android by redsolution.
the class MamManager method updatePreviousHistorySyncInfo.
private void updatePreviousHistorySyncInfo(Realm realm, BaseEntity chat, org.jivesoftware.smackx.mam.MamManager.MamQueryResult mamQueryResult, List<MessageItem> messageItems) {
SyncInfo syncInfo = getSyncInfo(realm, chat.getAccount(), chat.getUser());
realm.beginTransaction();
if (mamQueryResult.forwardedMessages.size() < PAGE_SIZE) {
syncInfo.setRemoteHistoryCompletelyLoaded(true);
}
syncInfo.setFirstMamMessageMamId(mamQueryResult.mamFin.getRSMSet().getFirst());
if (!mamQueryResult.forwardedMessages.isEmpty()) {
syncInfo.setFirstMamMessageStanzaId(mamQueryResult.forwardedMessages.get(0).getForwardedStanza().getStanzaId());
}
realm.commitTransaction();
}
use of com.xabber.android.data.database.messagerealm.SyncInfo in project xabber-android by redsolution.
the class MamManager method requestFullChatHistory.
/**
* Only for debugging
* Call only from background thread
* @param chat
*/
public void requestFullChatHistory(final AbstractChat chat) {
if (chat == null || chat.isRemotePreviousHistoryCompletelyLoaded()) {
return;
}
final AccountItem accountItem = AccountManager.getInstance().getAccount(chat.getAccount());
if (accountItem == null || !accountItem.getFactualStatusMode().isOnline()) {
return;
}
if (!checkSupport(accountItem)) {
return;
}
String firstMamMessageMamId;
boolean remoteHistoryCompletelyLoaded;
{
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
SyncInfo syncInfo = getSyncInfo(realm, chat.getAccount(), chat.getUser());
firstMamMessageMamId = syncInfo.getFirstMamMessageMamId();
remoteHistoryCompletelyLoaded = syncInfo.isRemoteHistoryCompletelyLoaded();
realm.close();
}
if (remoteHistoryCompletelyLoaded) {
chat.setRemotePreviousHistoryCompletelyLoaded(true);
}
if (firstMamMessageMamId == null || remoteHistoryCompletelyLoaded) {
return;
}
org.jivesoftware.smackx.mam.MamManager mamManager = org.jivesoftware.smackx.mam.MamManager.getInstanceFor(accountItem.getConnection());
final org.jivesoftware.smackx.mam.MamManager.MamQueryResult mamQueryResult;
try {
LogManager.i("MAM", "Loading previous history");
mamQueryResult = mamManager.queryArchive(chat.getUser().getJid());
} catch (SmackException.NotLoggedInException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
LogManager.exception(this, e);
return;
}
LogManager.i("MAM", "queryArchive finished. fin count expected: " + mamQueryResult.mamFin.getRSMSet().getCount() + " real: " + mamQueryResult.forwardedMessages.size());
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
List<MessageItem> messageItems = getMessageItems(mamQueryResult, chat);
syncMessages(realm, chat, messageItems);
updatePreviousHistorySyncInfo(realm, chat, mamQueryResult, messageItems);
realm.close();
}
use of com.xabber.android.data.database.messagerealm.SyncInfo in project xabber-android by redsolution.
the class MamManager method setRemoteHistoryCompletelyLoaded.
public void setRemoteHistoryCompletelyLoaded(AbstractChat chat) {
LogManager.i(this, "setRemoteHistoryCompletelyLoaded " + chat.getUser());
Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
SyncInfo syncInfo = getSyncInfo(realm, chat.getAccount(), chat.getUser());
realm.beginTransaction();
syncInfo.setRemoteHistoryCompletelyLoaded(true);
realm.commitTransaction();
realm.close();
}
use of com.xabber.android.data.database.messagerealm.SyncInfo in project xabber-android by redsolution.
the class MamManager method getSyncInfo.
@NonNull
private SyncInfo getSyncInfo(Realm realm, AccountJid account, UserJid user) {
SyncInfo syncInfo = realm.where(SyncInfo.class).equalTo(SyncInfo.FIELD_ACCOUNT, account.toString()).equalTo(SyncInfo.FIELD_USER, user.toString()).findFirst();
if (syncInfo == null) {
realm.beginTransaction();
syncInfo = realm.createObject(SyncInfo.class);
syncInfo.setAccount(account);
syncInfo.setUser(user);
realm.commitTransaction();
}
return syncInfo;
}
use of com.xabber.android.data.database.messagerealm.SyncInfo in project xabber-android by redsolution.
the class NextMamManager method runMigrationToNewArchive.
private void runMigrationToNewArchive(AccountItem accountItem, Realm realm) {
LogManager.d(LOG_TAG, "run migration for account: " + accountItem.getAccount().toString());
Collection<RosterContact> contacts = RosterManager.getInstance().getAccountRosterContacts(accountItem.getAccount());
for (RosterContact contact : contacts) {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(contact.getAccount(), contact.getUser());
MessageItem firstMessage = getFirstMessageForMigration(chat, realm);
SyncInfo syncInfo = realm.where(SyncInfo.class).equalTo(SyncInfo.FIELD_ACCOUNT, accountItem.getAccount().toString()).equalTo(SyncInfo.FIELD_USER, chat.getUser().toString()).findFirst();
if (firstMessage != null && syncInfo != null) {
realm.beginTransaction();
firstMessage.setArchivedId(syncInfo.getFirstMamMessageMamId());
firstMessage.setPreviousId(null);
realm.commitTransaction();
}
}
}
Aggregations