/** * Returns <code>true</code> if conversation is in the given state */ public boolean hasState(ConversationState s) { return state.equals(s); }
/** * Returns the <code>{@link ConversationState}</code> object corresponding * to <code>value</code> or <code>UNDEFINED</code> if <code>value</code> * is out of range */ public static ConversationState valueOf(byte value) { final ConversationState[] values = ConversationState.values(); if (value >= 0 && value < values.length) { return values[value]; } return UNDEFINED; } }
@Override public void writeExternal(DataOutput out) throws IOException { out.writeUTF(localConversationId); writeNullableUTF(out, conversationId); writeNullableUTF(out, conversationToken); out.writeUTF(dataFile.getAbsolutePath()); out.writeUTF(messagesFile.getAbsolutePath()); out.writeByte(conversationState.ordinal()); writeNullableUTF(out, conversationEncryptionKey != null ? conversationEncryptionKey.getHexKey() : null); writeNullableUTF(out, userId); }
public ConversationMetadataItem(DataInput in) throws IOException { localConversationId = in.readUTF(); conversationId = readNullableUTF(in); conversationToken = readNullableUTF(in); dataFile = getEncryptedFilename(new File(in.readUTF())); messagesFile = getEncryptedFilename(new File(in.readUTF())); conversationState = ConversationState.valueOf(in.readByte()); String conversationEncryptionKeyHex = readNullableUTF(in); conversationEncryptionKey = conversationEncryptionKeyHex != null ? new EncryptionKey(conversationEncryptionKeyHex) : null; userId = readNullableUTF(in); }
/** * Returns <code>true</code> if conversation is in one of the given states */ public boolean hasState(ConversationState... states) { for (ConversationState s : states) { if (s.equals(state)) { return true; } } return false; }
@Override public boolean accept(ConversationMetadataItem item) { return state.equals(item.getConversationState()); } });
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; }
final String conversationToken = notNull(conversation.getConversationToken()); final String conversationLocalIdentifier = notNull(conversation.getLocalIdentifier()); final boolean legacyPayloads = ConversationState.LEGACY_PENDING.equals(conversation.getPrevState());
if (LOGGED_IN.equals(item.getConversationState())) { item.setConversationState(LOGGED_OUT);