Create a basic ConversationManager for querying GroupCount

This is also lays the groundwork for #384
This commit is contained in:
Torsten Grote
2016-10-05 14:38:51 -03:00
parent 457c30f3f2
commit f52819f4ca
14 changed files with 214 additions and 23 deletions

View File

@@ -29,7 +29,7 @@ import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageStatus;
import org.briarproject.clients.BdfIncomingMessageHook;
import org.briarproject.clients.ConversationClient;
import org.briarproject.util.StringUtils;
import java.io.IOException;
@@ -76,7 +76,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUE
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE;
import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
class IntroductionManagerImpl extends BdfIncomingMessageHook
class IntroductionManagerImpl extends ConversationClient
implements IntroductionManager, Client, AddContactHook,
RemoveContactHook {
@@ -119,7 +119,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
public void addingContact(Transaction txn, Contact c) throws DbException {
try {
// Create an introduction group for sending introduction messages
Group g = introductionGroupFactory.createIntroductionGroup(c);
Group g = getContactGroup(c);
// Return if we've already set things up for this contact
if (db.containsGroup(txn, g.getId())) return;
// Store the group and share it with the contact
@@ -196,7 +196,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
// remove the group (all messages will be removed with it)
// this contact won't get our abort message, but the other will
db.removeGroup(txn, introductionGroupFactory.createIntroductionGroup(c));
db.removeGroup(txn, getContactGroup(c));
}
/**
@@ -288,6 +288,11 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
return false;
}
@Override
protected Group getContactGroup(Contact contact) {
return introductionGroupFactory.createIntroductionGroup(contact);
}
@Override
public void makeIntroduction(Contact c1, Contact c2, String msg,
final long timestamp)
@@ -296,8 +301,8 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
Transaction txn = db.startTransaction(false);
try {
introducerManager.makeIntroduction(txn, c1, c2, msg, timestamp);
Group g1 = introductionGroupFactory.createIntroductionGroup(c1);
Group g2 = introductionGroupFactory.createIntroductionGroup(c2);
Group g1 = getContactGroup(c1);
Group g2 = getContactGroup(c2);
trackMessage(txn, g1.getId(), timestamp, true);
trackMessage(txn, g2.getId(), timestamp, true);
txn.setComplete();
@@ -314,7 +319,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
Transaction txn = db.startTransaction(false);
try {
Contact c = db.getContact(txn, contactId);
Group g = introductionGroupFactory.createIntroductionGroup(c);
Group g = getContactGroup(c);
BdfDictionary state =
getSessionState(txn, g.getId(), sessionId.getBytes());
@@ -334,7 +339,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
Transaction txn = db.startTransaction(false);
try {
Contact c = db.getContact(txn, contactId);
Group g = introductionGroupFactory.createIntroductionGroup(c);
Group g = getContactGroup(c);
BdfDictionary state =
getSessionState(txn, g.getId(), sessionId.getBytes());
@@ -358,9 +363,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
Transaction txn = db.startTransaction(true);
try {
// get messages and their status
GroupId g = introductionGroupFactory
.createIntroductionGroup(db.getContact(txn, contactId))
.getId();
GroupId g = getContactGroup(db.getContact(txn, contactId)).getId();
metadata = clientHelper.getMessageMetadataAsDictionary(txn, g);
statuses = db.getMessageStatus(txn, contactId, g);

View File

@@ -6,6 +6,7 @@ import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.introduction.IntroductionManager;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.messaging.ConversationManager;
import org.briarproject.api.system.Clock;
import javax.inject.Inject;
@@ -47,6 +48,7 @@ public class IntroductionModule {
LifecycleManager lifecycleManager,
ContactManager contactManager,
MessageQueueManager messageQueueManager,
ConversationManager conversationManager,
IntroductionManagerImpl introductionManager) {
lifecycleManager.registerClient(introductionManager);
@@ -55,6 +57,7 @@ public class IntroductionModule {
messageQueueManager.registerIncomingMessageHook(
introductionManager.getClientId(),
introductionManager);
conversationManager.registerConversationClient(introductionManager);
return introductionManager;
}