mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Factor MessageTracker out of BdfIncomingMessageHook.
This commit is contained in:
@@ -8,6 +8,7 @@ import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.data.MetadataEncoder;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.privategroup.MessageType;
|
||||
import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.privategroup.PrivateGroupFactory;
|
||||
@@ -38,6 +39,7 @@ import static org.briarproject.privategroup.GroupConstants.KEY_READ;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TYPE;
|
||||
|
||||
@NotNullByDefault
|
||||
class GroupMessageValidator extends BdfMessageValidator {
|
||||
|
||||
private final PrivateGroupFactory privateGroupFactory;
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.briarproject.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.clients.MessageTracker.GroupCount;
|
||||
import org.briarproject.api.clients.ProtocolStateException;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfEntry;
|
||||
@@ -75,17 +77,18 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
|
||||
private final PrivateGroupFactory privateGroupFactory;
|
||||
private final IdentityManager identityManager;
|
||||
private final MessageTracker messageTracker;
|
||||
private final List<PrivateGroupHook> hooks;
|
||||
|
||||
@Inject
|
||||
PrivateGroupManagerImpl(ClientHelper clientHelper,
|
||||
MetadataParser metadataParser, DatabaseComponent db,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
IdentityManager identityManager) {
|
||||
IdentityManager identityManager, MessageTracker messageTracker) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
this.identityManager = identityManager;
|
||||
this.messageTracker = messageTracker;
|
||||
hooks = new CopyOnWriteArrayList<PrivateGroupHook>();
|
||||
}
|
||||
|
||||
@@ -126,7 +129,7 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
meta.put(KEY_TYPE, JOIN.getInt());
|
||||
addMessageMetadata(meta, m, true);
|
||||
clientHelper.addLocalMessage(txn, m.getMessage(), meta, true);
|
||||
trackOutgoingMessage(txn, m.getMessage());
|
||||
messageTracker.trackOutgoingMessage(txn, m.getMessage());
|
||||
addMember(txn, m.getMessage().getGroupId(), m.getMember(), VISIBLE);
|
||||
setPreviousMsgId(txn, m.getMessage().getGroupId(),
|
||||
m.getMessage().getId());
|
||||
@@ -218,7 +221,7 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
|
||||
// track message
|
||||
setPreviousMsgId(txn, g, m.getMessage().getId());
|
||||
trackOutgoingMessage(txn, m.getMessage());
|
||||
messageTracker.trackOutgoingMessage(txn, m.getMessage());
|
||||
|
||||
// broadcast event
|
||||
attachGroupMessageAddedEvent(txn, m.getMessage(), meta, true);
|
||||
@@ -437,6 +440,17 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCount getGroupCount(GroupId g) throws DbException {
|
||||
return messageTracker.getGroupCount(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||
throws DbException {
|
||||
messageTracker.setReadFlag(g, m, read);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relationshipRevealed(Transaction txn, GroupId g, AuthorId a,
|
||||
boolean byContact) throws FormatException, DbException {
|
||||
@@ -500,7 +514,7 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
}
|
||||
addMember(txn, m.getGroupId(), member, v);
|
||||
// track message and broadcast event
|
||||
trackIncomingMessage(txn, m);
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
attachJoinMessageAddedEvent(txn, m, meta, false, v);
|
||||
}
|
||||
|
||||
@@ -537,7 +551,7 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
if (previousType != JOIN && previousType != POST)
|
||||
throw new FormatException();
|
||||
// track message and broadcast event
|
||||
trackIncomingMessage(txn, m);
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
attachGroupMessageAddedEvent(txn, m, meta, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.Client;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.clients.ContactGroupFactory;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
@@ -74,13 +75,14 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Inject
|
||||
protected GroupInvitationManagerImpl(DatabaseComponent db,
|
||||
ClientHelper clientHelper, MetadataParser metadataParser,
|
||||
MessageTracker messageTracker,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
PrivateGroupManager privateGroupManager,
|
||||
MessageParser messageParser, SessionParser sessionParser,
|
||||
SessionEncoder sessionEncoder,
|
||||
ProtocolEngineFactory engineFactory) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
this.privateGroupManager = privateGroupManager;
|
||||
@@ -131,7 +133,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID, c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user