mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Allow responding to sharing invitations based on SessionId
This commit is contained in:
@@ -5,16 +5,15 @@ import org.briarproject.api.contact.ContactId;
|
|||||||
import org.briarproject.api.sharing.InvitationRequest;
|
import org.briarproject.api.sharing.InvitationRequest;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class ForumInvitationRequest extends InvitationRequest {
|
public class ForumInvitationRequest extends InvitationRequest {
|
||||||
|
|
||||||
private final String forumName;
|
private final String forumName;
|
||||||
|
|
||||||
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
||||||
GroupId groupId, ContactId contactId, String forumName, String message,
|
GroupId groupId, ContactId contactId, String forumName,
|
||||||
boolean available, long time, boolean local, boolean sent,
|
String message, boolean available, long time, boolean local,
|
||||||
boolean seen, boolean read) {
|
boolean sent, boolean seen, boolean read) {
|
||||||
|
|
||||||
super(id, sessionId, groupId, contactId, message, available, time,
|
super(id, sessionId, groupId, contactId, message, available, time,
|
||||||
local, sent, seen, read);
|
local, sent, seen, read);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.api.sharing;
|
package org.briarproject.api.sharing;
|
||||||
|
|
||||||
import org.briarproject.api.clients.MessageTracker;
|
import org.briarproject.api.clients.MessageTracker;
|
||||||
|
import org.briarproject.api.clients.SessionId;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
@@ -30,7 +31,14 @@ public interface SharingManager<S extends Shareable> extends MessageTracker {
|
|||||||
throws DbException;
|
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(
|
Collection<InvitationMessage> getInvitationMessages(
|
||||||
ContactId contactId) throws DbException;
|
ContactId contactId) throws DbException;
|
||||||
|
|||||||
@@ -316,27 +316,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
|||||||
try {
|
try {
|
||||||
// find session state based on shareable
|
// find session state based on shareable
|
||||||
IS localState = getSessionStateForResponse(txn, f, c);
|
IS localState = getSessionStateForResponse(txn, f, c);
|
||||||
|
respondToInvitation(txn, localState, accept);
|
||||||
// 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);
|
|
||||||
|
|
||||||
txn.setComplete();
|
txn.setComplete();
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(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
|
@Override
|
||||||
public Collection<InvitationMessage> getInvitationMessages(ContactId contactId)
|
public Collection<InvitationMessage> getInvitationMessages(ContactId contactId)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
|||||||
Reference in New Issue
Block a user