Skip to content
Snippets Groups Projects
Verified Commit e00219c1 authored by Torsten Grote's avatar Torsten Grote
Browse files

Allow responding to sharing invitations based on SessionId

parent 96666273
No related branches found
No related tags found
1 merge request!357Implement UX for showing and answering private group invitations
......@@ -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);
......
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;
......
......@@ -316,27 +316,23 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
try {
// find session state based on shareable
IS localState = getSessionStateForResponse(txn, f, c);
respondToInvitation(txn, localState, accept);
txn.setComplete();
} catch (FormatException e) {
throw new DbException(e);
} finally {
db.endTransaction(txn);
}
}
// 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 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);
......@@ -345,6 +341,29 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
}
}
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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment