Merge branch 'use-contact-id-as-conversation-id' into 'master'

Use contact ID rather than messaging group ID to identify conversation

We originally used the private messaging group ID to identify the private conversation, but now that the conversation includes messages from multiple clients it's more appropriate to use the contact ID.

This refactoring isn't urgent - I've had the branch lying around for a while, but I'm putting it up for review because #734 will touch some of the same code.

See merge request !386
This commit is contained in:
Torsten Grote
2016-11-07 11:24:11 +00:00
15 changed files with 139 additions and 168 deletions

View File

@@ -1,15 +1,11 @@
package org.briarproject.messaging;
import org.briarproject.api.clients.ContactGroupFactory;
import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.messaging.ConversationManager;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -19,14 +15,11 @@ import javax.inject.Inject;
class ConversationManagerImpl implements ConversationManager {
private final DatabaseComponent db;
private final ContactGroupFactory contactGroupFactory;
private final Set<ConversationClient> clients;
@Inject
ConversationManagerImpl(DatabaseComponent db,
ContactGroupFactory contactGroupFactory) {
ConversationManagerImpl(DatabaseComponent db) {
this.db = db;
this.contactGroupFactory = contactGroupFactory;
clients = new CopyOnWriteArraySet<ConversationClient>();
}
@@ -38,23 +31,6 @@ class ConversationManagerImpl implements ConversationManager {
}
}
@Override
public GroupId getConversationId(ContactId contactId) throws DbException {
// TODO we should probably transition this to its own group
// and/or work with the ContactId in the UI instead
Contact contact;
Transaction txn = db.startTransaction(true);
try {
contact = db.getContact(txn, contactId);
db.commitTransaction(txn);
} finally {
db.endTransaction(txn);
}
Group group = contactGroupFactory
.createContactGroup(MessagingManagerImpl.CLIENT_ID, contact);
return group.getId();
}
@Override
public GroupCount getGroupCount(ContactId contactId)
throws DbException {