Allow responding to sharing invitations based on SessionId

This commit is contained in:
Torsten Grote
2016-10-18 08:49:34 -02:00
parent 96666273d3
commit e00219c15f
3 changed files with 52 additions and 26 deletions

View File

@@ -5,16 +5,15 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.sharing.InvitationRequest;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable;
public class ForumInvitationRequest extends InvitationRequest {
private final String forumName;
public ForumInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, String forumName, String message,
boolean available, long time, boolean local, boolean sent,
boolean seen, boolean read) {
GroupId groupId, ContactId contactId, String forumName,
String message, boolean available, long time, boolean local,
boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, available, time,
local, sent, seen, read);

View File

@@ -1,6 +1,7 @@
package org.briarproject.api.sharing;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
@@ -30,7 +31,14 @@ public interface SharingManager<S extends Shareable> extends MessageTracker {
throws DbException;
/**
* Returns all group sharing messages sent by the given contact.
* Responds to a pending group invitation
*/
void respondToInvitation(SessionId id, boolean accept)
throws DbException;
/**
* Returns all group sharing messages sent by the Contact
* identified by contactId.
*/
Collection<InvitationMessage> getInvitationMessages(
ContactId contactId) throws DbException;

View File

@@ -316,27 +316,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
try {
// find session state based on shareable
IS localState = getSessionStateForResponse(txn, f, c);
// define action
InviteeSessionState.Action localAction;
if (accept) {
localAction = InviteeSessionState.Action.LOCAL_ACCEPT;
} else {
localAction = InviteeSessionState.Action.LOCAL_DECLINE;
}
// start engine and process its state update
InviteeEngine<IS, IR> engine =
new InviteeEngine<IS, IR>(getIRFactory(), clock);
StateUpdate<IS, BaseMessage> update =
engine.onLocalAction(localState, localAction);
processInviteeStateUpdate(txn, null, update);
// track message
// TODO handle this properly without engine hacks (#376)
long time = update.toSend.get(0).getTime();
trackMessage(txn, localState.getGroupId(), time, true);
respondToInvitation(txn, localState, accept);
txn.setComplete();
} catch (FormatException e) {
throw new DbException(e);
@@ -345,6 +325,45 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
}
}
@Override
public void respondToInvitation(SessionId id, boolean accept)
throws DbException {
Transaction txn = db.startTransaction(false);
try {
IS localState = (IS) getSessionState(txn, id, true);
respondToInvitation(txn, localState, accept);
txn.setComplete();
} catch (FormatException e) {
throw new DbException(e);
} finally {
db.endTransaction(txn);
}
}
private void respondToInvitation(Transaction txn, IS localState,
boolean accept) throws DbException, FormatException {
// define action
InviteeSessionState.Action localAction;
if (accept) {
localAction = InviteeSessionState.Action.LOCAL_ACCEPT;
} else {
localAction = InviteeSessionState.Action.LOCAL_DECLINE;
}
// start engine and process its state update
InviteeEngine<IS, IR> engine =
new InviteeEngine<IS, IR>(getIRFactory(), clock);
StateUpdate<IS, BaseMessage> update =
engine.onLocalAction(localState, localAction);
processInviteeStateUpdate(txn, null, update);
// track message
// TODO handle this properly without engine hacks (#376)
long time = update.toSend.get(0).getTime();
trackMessage(txn, localState.getGroupId(), time, true);
}
@Override
public Collection<InvitationMessage> getInvitationMessages(ContactId contactId)
throws DbException {