File messagesFile = generateMessagesFilename(); Conversation conversation = new Conversation(dataFile, messagesFile, encryptionKey); conversation.setState(LEGACY_PENDING); conversation.setConversationToken(legacyConversationToken);
private @Nullable Conversation loadActiveConversationGuarded() throws ConversationLoadException { // try to load an active conversation from metadata first try { if (conversationMetadata.hasItems()) { return loadConversationFromMetadata(conversationMetadata); } // try to load legacy conversation Conversation legacyConversation = migrateLegacyConversation(getContext()); if (legacyConversation != null) { return legacyConversation; } } catch (Exception e) { ApptentiveLog.e(e, "Exception while loading conversation"); logException(e); // do not re-create a conversation if the last loading was unsuccessful throw new ConversationLoadException("Unable to load conversation", e); } // no active conversations: create a new one ApptentiveLog.i(CONVERSATION, "Creating 'anonymous' conversation..."); File dataFile = generateConversationDataFilename(); File messagesFile = generateMessagesFilename(); Conversation conversation = new Conversation(dataFile, messagesFile, encryptionKey); conversation.setState(ANONYMOUS_PENDING); fetchConversationToken(conversation); return conversation; }
public void logout() { checkConversationQueue(); if (activeConversation != null) { switch (activeConversation.getState()) { case LOGGED_IN: ApptentiveLog.d(CONVERSATION, "Ending active conversation."); EngagementModule.engageInternal(getContext(), activeConversation, "logout"); // Post synchronously to ensure logout payload can be sent before destroying the logged in conversation. ApptentiveNotificationCenter.defaultCenter().postNotification(NOTIFICATION_CONVERSATION_WILL_LOGOUT, ObjectUtils.toMap(NOTIFICATION_KEY_CONVERSATION, activeConversation)); activeConversation.destroy(); activeConversation.setState(LOGGED_OUT); handleConversationStateChange(activeConversation); setActiveConversation(null); ApptentiveInternal.dismissAllInteractions(); break; default: ApptentiveLog.w(CONVERSATION, "Attempted to logout() from Conversation, but the Active Conversation was not in LOGGED_IN state."); break; } } else { ApptentiveLog.w(CONVERSATION, "Attempted to logout(), but there was no Active Conversation."); } }
private Conversation loadConversation(ConversationMetadataItem item) throws SerializerException, ConversationLoadException { checkConversationQueue(); // logged-in conversations should use an encryption key which was received from the backend. EncryptionKey conversationEncryptionKey = encryptionKey; if (LOGGED_IN.equals(item.getConversationState())) { conversationEncryptionKey = item.getConversationEncryptionKey(); if (conversationEncryptionKey == null) { throw new ConversationLoadException("Missing conversation encryption key"); } } // TODO: use same serialization logic across the project final Conversation conversation = new Conversation(item.getDataFile(), item.getMessagesFile(), conversationEncryptionKey); conversation.setState(item.getConversationState()); // set the state same as the item's state conversation.setUserId(item.getUserId()); conversation.setConversationToken(item.getConversationToken()); // TODO: this would be overwritten by the next call // try to migrate legacy conversation first boolean migrated = conversation.migrateConversationData(); // if failed - load from encrypted data if (!migrated) { conversation.loadConversationData(); } // check inconsistency conversation.checkInternalConsistency(); return conversation; }