mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Introduce SharingStatus to report more fine-grained status
This commit is contained in:
@@ -12,7 +12,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public abstract class BaseContactSelectorAdapter<I extends SelectableContactItem, H extends ContactItemViewHolder<I>>
|
public abstract class BaseContactSelectorAdapter<I extends BaseSelectableContactItem, H extends ContactItemViewHolder<I>>
|
||||||
extends BaseContactListAdapter<I, H> {
|
extends BaseContactListAdapter<I, H> {
|
||||||
|
|
||||||
public BaseContactSelectorAdapter(Context context, Class<I> c,
|
public BaseContactSelectorAdapter(Context context, Class<I> c,
|
||||||
@@ -24,7 +24,7 @@ public abstract class BaseContactSelectorAdapter<I extends SelectableContactItem
|
|||||||
Collection<ContactId> selected = new ArrayList<>();
|
Collection<ContactId> selected = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
SelectableContactItem item = items.get(i);
|
BaseSelectableContactItem item = items.get(i);
|
||||||
if (item.isSelected()) selected.add(item.getContact().getId());
|
if (item.isSelected()) selected.add(item.getContact().getId());
|
||||||
}
|
}
|
||||||
return selected;
|
return selected;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import static org.briarproject.briar.android.contactselection.ContactSelectorAct
|
|||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public abstract class BaseContactSelectorFragment<I extends SelectableContactItem, A extends BaseContactSelectorAdapter<I, ? extends ContactItemViewHolder<I>>>
|
public abstract class BaseContactSelectorFragment<I extends BaseSelectableContactItem, A extends BaseContactSelectorAdapter<I, ? extends ContactItemViewHolder<I>>>
|
||||||
extends BaseFragment
|
extends BaseFragment
|
||||||
implements OnContactClickListener<I> {
|
implements OnContactClickListener<I> {
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import static org.briarproject.briar.android.util.UiUtils.GREY_OUT;
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class BaseSelectableContactHolder<I extends SelectableContactItem>
|
public abstract class BaseSelectableContactHolder<I extends BaseSelectableContactItem>
|
||||||
extends ContactItemViewHolder<I> {
|
extends ContactItemViewHolder<I> {
|
||||||
|
|
||||||
private final CheckBox checkBox;
|
private final CheckBox checkBox;
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.briarproject.briar.android.contactselection;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.briar.android.contact.ContactItem;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class BaseSelectableContactItem extends ContactItem {
|
||||||
|
|
||||||
|
private boolean selected;
|
||||||
|
|
||||||
|
public BaseSelectableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||||
|
boolean selected) {
|
||||||
|
super(contact, authorInfo);
|
||||||
|
this.selected = selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSelected() {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleSelected() {
|
||||||
|
selected = !selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isDisabled();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import org.briarproject.nullsafety.NotNullByDefault;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface ContactSelectorController<I extends SelectableContactItem>
|
public interface ContactSelectorController<I extends BaseSelectableContactItem>
|
||||||
extends DbController {
|
extends DbController {
|
||||||
|
|
||||||
void loadContacts(GroupId g, Collection<ContactId> selection,
|
void loadContacts(GroupId g, Collection<ContactId> selection,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.briarproject.briar.android.controller.DbControllerImpl;
|
|||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -53,10 +54,8 @@ public abstract class ContactSelectorControllerImpl
|
|||||||
AuthorInfo authorInfo = authorManager.getAuthorInfo(c);
|
AuthorInfo authorInfo = authorManager.getAuthorInfo(c);
|
||||||
// was this contact already selected?
|
// was this contact already selected?
|
||||||
boolean selected = selection.contains(c.getId());
|
boolean selected = selection.contains(c.getId());
|
||||||
// can this contact be selected?
|
|
||||||
boolean disabled = isDisabled(g, c);
|
|
||||||
contacts.add(new SelectableContactItem(c, authorInfo,
|
contacts.add(new SelectableContactItem(c, authorInfo,
|
||||||
selected, disabled));
|
selected, getSharingStatus(g, c)));
|
||||||
}
|
}
|
||||||
handler.onResult(contacts);
|
handler.onResult(contacts);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -67,7 +66,7 @@ public abstract class ContactSelectorControllerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
protected abstract boolean isDisabled(GroupId g, Contact c)
|
protected abstract SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,20 @@ package org.briarproject.briar.android.contactselection;
|
|||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.INVITED;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.NOT_SUPPORTED;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -27,6 +32,15 @@ class SelectableContactHolder
|
|||||||
super.bind(item, listener);
|
super.bind(item, listener);
|
||||||
|
|
||||||
if (item.isDisabled()) {
|
if (item.isDisabled()) {
|
||||||
|
@StringRes int strRes;
|
||||||
|
if (item.getSharingStatus() == SHARING) {
|
||||||
|
strRes = R.string.forum_invitation_already_sharing;
|
||||||
|
} else if (item.getSharingStatus() == INVITED) {
|
||||||
|
strRes = R.string.forum_invitation_already_invited;
|
||||||
|
} else if (item.getSharingStatus() == NOT_SUPPORTED) {
|
||||||
|
strRes = R.string.forum_invitation_not_supported;
|
||||||
|
} else throw new AssertionError("Unhandled SharingStatus");
|
||||||
|
info.setText(strRes);
|
||||||
info.setVisibility(VISIBLE);
|
info.setVisibility(VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
info.setVisibility(GONE);
|
info.setVisibility(GONE);
|
||||||
|
|||||||
@@ -1,36 +1,33 @@
|
|||||||
package org.briarproject.briar.android.contactselection;
|
package org.briarproject.briar.android.contactselection;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.briar.android.contact.ContactItem;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class SelectableContactItem extends ContactItem {
|
public class SelectableContactItem extends BaseSelectableContactItem {
|
||||||
|
|
||||||
private boolean selected;
|
private final SharingStatus sharingStatus;
|
||||||
private final boolean disabled;
|
|
||||||
|
|
||||||
public SelectableContactItem(Contact contact, AuthorInfo authorInfo,
|
public SelectableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||||
boolean selected, boolean disabled) {
|
boolean selected, SharingStatus sharingStatus) {
|
||||||
super(contact, authorInfo);
|
super(contact, authorInfo, selected);
|
||||||
this.selected = selected;
|
this.sharingStatus = sharingStatus;
|
||||||
this.disabled = disabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSelected() {
|
public SharingStatus getSharingStatus() {
|
||||||
return selected;
|
return sharingStatus;
|
||||||
}
|
|
||||||
|
|
||||||
void toggleSelected() {
|
|
||||||
selected = !selected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isDisabled() {
|
public boolean isDisabled() {
|
||||||
return disabled;
|
return sharingStatus != SHAREABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
|||||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -140,8 +141,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
protected SharingStatus getSharingStatus(GroupId g, Contact c) throws DbException {
|
||||||
return !groupInvitationManager.isInvitationAllowed(c, g);
|
return groupInvitationManager.getSharingStatus(c, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class RevealContactsControllerImpl extends DbControllerImpl
|
|||||||
boolean selected =
|
boolean selected =
|
||||||
disabled || selection.contains(c.getId());
|
disabled || selection.contains(c.getId());
|
||||||
items.add(new RevealableContactItem(c, authorInfo, selected,
|
items.add(new RevealableContactItem(c, authorInfo, selected,
|
||||||
disabled, m.getVisibility()));
|
m.getVisibility()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
package org.briarproject.briar.android.privategroup.reveal;
|
package org.briarproject.briar.android.privategroup.reveal;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.briar.android.contactselection.SelectableContactItem;
|
import org.briarproject.briar.android.contactselection.BaseSelectableContactItem;
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.privategroup.Visibility;
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class RevealableContactItem extends SelectableContactItem {
|
class RevealableContactItem extends BaseSelectableContactItem {
|
||||||
|
|
||||||
private final Visibility visibility;
|
private final Visibility visibility;
|
||||||
|
|
||||||
RevealableContactItem(Contact contact, AuthorInfo authorInfo,
|
RevealableContactItem(Contact contact, AuthorInfo authorInfo,
|
||||||
boolean selected, boolean disabled, Visibility visibility) {
|
boolean selected, Visibility visibility) {
|
||||||
super(contact, authorInfo, selected, disabled);
|
super(contact, authorInfo, selected);
|
||||||
this.visibility = visibility;
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,4 +26,8 @@ class RevealableContactItem extends SelectableContactItem {
|
|||||||
return visibility;
|
return visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisabled() {
|
||||||
|
return visibility != INVISIBLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.briarproject.briar.android.contactselection.ContactSelectorController
|
|||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -47,8 +48,9 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
protected SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||||
return !blogSharingManager.canBeShared(g, c);
|
throws DbException {
|
||||||
|
return blogSharingManager.getSharingStatus(g, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.briarproject.briar.android.contactselection.ContactSelectorController
|
|||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -47,8 +48,9 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isDisabled(GroupId g, Contact c) throws DbException {
|
protected SharingStatus getSharingStatus(GroupId g, Contact c)
|
||||||
return !forumSharingManager.canBeShared(g, c);
|
throws DbException {
|
||||||
|
return forumSharingManager.getSharingStatus(g, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -461,6 +461,8 @@
|
|||||||
<string name="forum_declined_toast">Invitation declined</string>
|
<string name="forum_declined_toast">Invitation declined</string>
|
||||||
<string name="shared_by_format">Shared by %s</string>
|
<string name="shared_by_format">Shared by %s</string>
|
||||||
<string name="forum_invitation_already_sharing">Already sharing</string>
|
<string name="forum_invitation_already_sharing">Already sharing</string>
|
||||||
|
<string name="forum_invitation_already_invited">Already invited</string>
|
||||||
|
<string name="forum_invitation_not_supported">Not supported by this contact</string>
|
||||||
<string name="forum_invitation_response_accepted_sent">You accepted the forum invitation from %s.</string>
|
<string name="forum_invitation_response_accepted_sent">You accepted the forum invitation from %s.</string>
|
||||||
<string name="forum_invitation_response_declined_sent">You declined the forum invitation from %s.</string>
|
<string name="forum_invitation_response_declined_sent">You declined the forum invitation from %s.</string>
|
||||||
<string name="forum_invitation_response_declined_auto">The forum invitation from %s was automatically declined.</string>
|
<string name="forum_invitation_response_declined_auto">The forum invitation from %s was automatically declined.</string>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.briarproject.briar.api.client.ProtocolStateException;
|
|||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
|
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -82,5 +83,5 @@ public interface GroupInvitationManager extends ConversationClient {
|
|||||||
* Returns true if the given contact can be invited to the given private
|
* Returns true if the given contact can be invited to the given private
|
||||||
* group.
|
* group.
|
||||||
*/
|
*/
|
||||||
boolean isInvitationAllowed(Contact c, GroupId g) throws DbException;
|
SharingStatus getSharingStatus(Contact c, GroupId g) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import javax.annotation.Nullable;
|
|||||||
public interface SharingManager<S extends Shareable>
|
public interface SharingManager<S extends Shareable>
|
||||||
extends ConversationClient {
|
extends ConversationClient {
|
||||||
|
|
||||||
|
enum SharingStatus {
|
||||||
|
SHAREABLE, INVITED, SHARING, NOT_SUPPORTED
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an invitation to share the given group with the given contact,
|
* Sends an invitation to share the given group with the given contact,
|
||||||
* including optional text.
|
* including optional text.
|
||||||
@@ -80,12 +84,12 @@ public interface SharingManager<S extends Shareable>
|
|||||||
/**
|
/**
|
||||||
* Returns true if the group not already shared and no invitation is open
|
* Returns true if the group not already shared and no invitation is open
|
||||||
*/
|
*/
|
||||||
boolean canBeShared(GroupId g, Contact c) throws DbException;
|
SharingStatus getSharingStatus(GroupId g, Contact c) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the group not already shared and no invitation is open
|
* Returns true if the group not already shared and no invitation is open
|
||||||
*/
|
*/
|
||||||
boolean canBeShared(Transaction txn, GroupId g, Contact c)
|
SharingStatus getSharingStatus(Transaction txn, GroupId g, Contact c)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationItem;
|
|||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.sharing.SharingManager.SharingStatus;
|
||||||
import org.briarproject.briar.client.ConversationClientImpl;
|
import org.briarproject.briar.client.ConversationClientImpl;
|
||||||
import org.briarproject.nullsafety.NotNullByDefault;
|
import org.briarproject.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ import javax.inject.Inject;
|
|||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
import static org.briarproject.briar.privategroup.invitation.CreatorState.JOINED;
|
||||||
import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
|
import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
||||||
@@ -511,7 +513,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInvitationAllowed(Contact c, GroupId privateGroupId)
|
public SharingStatus getSharingStatus(Contact c, GroupId privateGroupId)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
GroupId contactGroupId = getContactGroup(c).getId();
|
GroupId contactGroupId = getContactGroup(c).getId();
|
||||||
SessionId sessionId = getSessionId(privateGroupId);
|
SessionId sessionId = getSessionId(privateGroupId);
|
||||||
@@ -523,13 +525,16 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
|||||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
// The group can't be shared unless the contact supports the client
|
// The group can't be shared unless the contact supports the client
|
||||||
if (client != SHARED) return false;
|
if (client != SHARED) return SharingStatus.NOT_SUPPORTED;
|
||||||
// If there's no session, the contact can be invited
|
// If there's no session, the contact can be invited
|
||||||
if (ss == null) return true;
|
if (ss == null) return SharingStatus.SHAREABLE;
|
||||||
// If the session's in the start state, the contact can be invited
|
// If the session's in the start state, the contact can be invited
|
||||||
CreatorSession session = sessionParser
|
CreatorSession session = sessionParser
|
||||||
.parseCreatorSession(contactGroupId, ss.bdfSession);
|
.parseCreatorSession(contactGroupId, ss.bdfSession);
|
||||||
return session.getState() == START;
|
CreatorState state = session.getState();
|
||||||
|
if (state == START) return SharingStatus.SHAREABLE;
|
||||||
|
if (state == JOINED) return SharingStatus.SHARING;
|
||||||
|
return SharingStatus.INVITED;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import javax.annotation.Nullable;
|
|||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
import static org.briarproject.briar.sharing.MessageType.ABORT;
|
import static org.briarproject.briar.sharing.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.sharing.MessageType.ACCEPT;
|
import static org.briarproject.briar.sharing.MessageType.ACCEPT;
|
||||||
import static org.briarproject.briar.sharing.MessageType.DECLINE;
|
import static org.briarproject.briar.sharing.MessageType.DECLINE;
|
||||||
@@ -269,7 +270,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
|||||||
SessionId sessionId = getSessionId(shareableId);
|
SessionId sessionId = getSessionId(shareableId);
|
||||||
try {
|
try {
|
||||||
Contact contact = db.getContact(txn, contactId);
|
Contact contact = db.getContact(txn, contactId);
|
||||||
if (!canBeShared(txn, shareableId, contact))
|
if (getSharingStatus(txn, shareableId, contact) != SHAREABLE)
|
||||||
// we might have received an invitation in the meantime
|
// we might have received an invitation in the meantime
|
||||||
return;
|
return;
|
||||||
// Look up the session, if there is one
|
// Look up the session, if there is one
|
||||||
@@ -467,34 +468,36 @@ abstract class SharingManagerImpl<S extends Shareable>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeShared(GroupId g, Contact c) throws DbException {
|
public SharingStatus getSharingStatus(GroupId g, Contact c) throws DbException {
|
||||||
Transaction txn = db.startTransaction(true);
|
Transaction txn = db.startTransaction(true);
|
||||||
try {
|
try {
|
||||||
boolean canBeShared = canBeShared(txn, g, c);
|
SharingStatus sharingStatus = getSharingStatus(txn, g, c);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return canBeShared;
|
return sharingStatus;
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeShared(Transaction txn, GroupId g, Contact c)
|
public SharingStatus getSharingStatus(Transaction txn, GroupId g, Contact c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
// The group can't be shared unless the contact supports the client
|
// The group can't be shared unless the contact supports the client
|
||||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||||
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
||||||
if (client != SHARED) return false;
|
if (client != SHARED) return SharingStatus.NOT_SUPPORTED;
|
||||||
GroupId contactGroupId = getContactGroup(c).getId();
|
GroupId contactGroupId = getContactGroup(c).getId();
|
||||||
SessionId sessionId = getSessionId(g);
|
SessionId sessionId = getSessionId(g);
|
||||||
try {
|
try {
|
||||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||||
// If there's no session, we can share the group with the contact
|
// If there's no session, we can share the group with the contact
|
||||||
if (ss == null) return true;
|
if (ss == null) return SharingStatus.SHAREABLE;
|
||||||
// If the session's in the right state, the contact can be invited
|
// If the session's in the right state, the contact can be invited
|
||||||
Session session =
|
Session session =
|
||||||
sessionParser.parseSession(contactGroupId, ss.bdfSession);
|
sessionParser.parseSession(contactGroupId, ss.bdfSession);
|
||||||
return session.getState().canInvite();
|
if (session.getState().canInvite()) return SharingStatus.SHAREABLE;
|
||||||
|
if (session.getState().isSharing()) return SharingStatus.SHARING;
|
||||||
|
return SharingStatus.INVITED;
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ enum State {
|
|||||||
return this == START;
|
return this == START;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSharing() {
|
||||||
|
return this == SHARING;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAwaitingResponse() {
|
public boolean isAwaitingResponse() {
|
||||||
return this == LOCAL_INVITED || this == REMOTE_INVITED;
|
return this == LOCAL_INVITED || this == REMOTE_INVITED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import javax.annotation.Nullable;
|
|||||||
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
|
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
import static org.briarproject.briar.test.TestEventListener.assertEvent;
|
import static org.briarproject.briar.test.TestEventListener.assertEvent;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -157,8 +159,8 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
|||||||
waitForEvents(c1);
|
waitForEvents(c1);
|
||||||
|
|
||||||
// 0 can invite 1 again
|
// 0 can invite 1 again
|
||||||
assertTrue(groupInvitationManager0
|
assertEquals(SHAREABLE, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// Before 1's timer elapses, 1 should still see the auto-decline message
|
// Before 1's timer elapses, 1 should still see the auto-decline message
|
||||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||||
@@ -194,8 +196,8 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
|||||||
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
||||||
|
|
||||||
// 0 can invite 1 again and really does invite
|
// 0 can invite 1 again and really does invite
|
||||||
assertTrue(groupInvitationManager0
|
assertEquals(SHAREABLE, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
sendInvitation(privateGroup, contact1From0.getId(),
|
sendInvitation(privateGroup, contact1From0.getId(),
|
||||||
"Join this faster please!");
|
"Join this faster please!");
|
||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
@@ -395,8 +397,8 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
|||||||
// 1 joined the PrivateGroup
|
// 1 joined the PrivateGroup
|
||||||
assertEquals(pg,
|
assertEquals(pg,
|
||||||
c1.getPrivateGroupManager().getPrivateGroup(pg.getId()));
|
c1.getPrivateGroupManager().getPrivateGroup(pg.getId()));
|
||||||
assertFalse(groupInvitationManager0
|
assertEquals(SHARING, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, pg.getId()));
|
.getSharingStatus(contact1From0, pg.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import static java.util.Collections.emptySet;
|
import static java.util.Collections.emptySet;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.INVITED;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -319,8 +322,8 @@ public class GroupInvitationIntegrationTest
|
|||||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||||
|
|
||||||
// invitation is not allowed before the first hasn't been answered
|
// invitation is not allowed before the first hasn't been answered
|
||||||
assertFalse(groupInvitationManager0
|
assertEquals(INVITED, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// deliver invitation and response
|
// deliver invitation and response
|
||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
@@ -329,8 +332,8 @@ public class GroupInvitationIntegrationTest
|
|||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
// after invitation was declined, inviting again is possible
|
// after invitation was declined, inviting again is possible
|
||||||
assertTrue(groupInvitationManager0
|
assertEquals(SHAREABLE, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// send and accept the second invitation
|
// send and accept the second invitation
|
||||||
sendInvitation(c0.getClock().currentTimeMillis(), "Second Invitation");
|
sendInvitation(c0.getClock().currentTimeMillis(), "Second Invitation");
|
||||||
@@ -340,8 +343,8 @@ public class GroupInvitationIntegrationTest
|
|||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
// invitation is not allowed since the member joined the group now
|
// invitation is not allowed since the member joined the group now
|
||||||
assertFalse(groupInvitationManager0
|
assertEquals(SHARING, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// don't allow another invitation request
|
// don't allow another invitation request
|
||||||
try {
|
try {
|
||||||
@@ -723,8 +726,8 @@ public class GroupInvitationIntegrationTest
|
|||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
// inviting again is not possible
|
// inviting again is not possible
|
||||||
assertFalse(groupInvitationManager0
|
assertEquals(SHARING, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// contacts remove each other
|
// contacts remove each other
|
||||||
removeAllContacts();
|
removeAllContacts();
|
||||||
@@ -737,8 +740,8 @@ public class GroupInvitationIntegrationTest
|
|||||||
addDefaultContacts();
|
addDefaultContacts();
|
||||||
|
|
||||||
// creator can still not invite again
|
// creator can still not invite again
|
||||||
assertFalse(groupInvitationManager0
|
assertEquals(INVITED, groupInvitationManager0
|
||||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
.getSharingStatus(contact1From0, privateGroup.getId()));
|
||||||
|
|
||||||
// finally invitee can remove group without issues
|
// finally invitee can remove group without issues
|
||||||
groupManager1.removePrivateGroup(privateGroup.getId());
|
groupManager1.removePrivateGroup(privateGroup.getId());
|
||||||
|
|||||||
@@ -62,12 +62,14 @@ import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROU
|
|||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.MAJOR_VERSION;
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.MAJOR_VERSION;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.INVITED;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.LEAVE;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.LEAVE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||||
@@ -871,31 +873,31 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsInvitationAllowed() throws Exception {
|
public void testIsInvitationAllowed() throws Exception {
|
||||||
expectIsInvitationAllowed(CreatorState.START);
|
expectIsInvitationAllowed(CreatorState.START);
|
||||||
assertTrue(groupInvitationManager
|
assertEquals(SHAREABLE, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotInvitationAllowed() throws Exception {
|
public void testIsNotInvitationAllowed() throws Exception {
|
||||||
expectIsInvitationAllowed(CreatorState.DISSOLVED);
|
expectIsInvitationAllowed(CreatorState.DISSOLVED);
|
||||||
assertFalse(groupInvitationManager
|
assertEquals(INVITED, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
|
|
||||||
expectIsInvitationAllowed(CreatorState.ERROR);
|
expectIsInvitationAllowed(CreatorState.ERROR);
|
||||||
assertFalse(groupInvitationManager
|
assertEquals(INVITED, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
|
|
||||||
expectIsInvitationAllowed(CreatorState.INVITED);
|
expectIsInvitationAllowed(CreatorState.INVITED);
|
||||||
assertFalse(groupInvitationManager
|
assertEquals(INVITED, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
|
|
||||||
expectIsInvitationAllowed(CreatorState.JOINED);
|
expectIsInvitationAllowed(CreatorState.JOINED);
|
||||||
assertFalse(groupInvitationManager
|
assertEquals(SHARING, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
|
|
||||||
expectIsInvitationAllowed(CreatorState.LEFT);
|
expectIsInvitationAllowed(CreatorState.LEFT);
|
||||||
assertFalse(groupInvitationManager
|
assertEquals(INVITED, groupInvitationManager
|
||||||
.isInvitationAllowed(contact, privateGroup.getId()));
|
.getSharingStatus(contact, privateGroup.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectIsInvitationAllowed(CreatorState state)
|
private void expectIsInvitationAllowed(CreatorState state)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
|
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
import static org.briarproject.briar.test.TestEventListener.assertEvent;
|
import static org.briarproject.briar.test.TestEventListener.assertEvent;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -146,8 +147,8 @@ public abstract class AbstractAutoDeleteIntegrationTest
|
|||||||
waitForEvents(c1);
|
waitForEvents(c1);
|
||||||
|
|
||||||
// 0 can invite 1 again
|
// 0 can invite 1 again
|
||||||
assertTrue(getSharingManager0()
|
assertEquals(SHAREABLE, getSharingManager0().getSharingStatus(
|
||||||
.canBeShared(getShareable().getId(), contact1From0));
|
getShareable().getId(), contact1From0));
|
||||||
|
|
||||||
// Before 1's timer elapses, 1 should still see the auto-decline message
|
// Before 1's timer elapses, 1 should still see the auto-decline message
|
||||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||||
@@ -183,8 +184,8 @@ public abstract class AbstractAutoDeleteIntegrationTest
|
|||||||
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
||||||
|
|
||||||
// 0 can invite 1 again and really does invite
|
// 0 can invite 1 again and really does invite
|
||||||
assertTrue(getSharingManager0()
|
assertEquals(SHAREABLE, getSharingManager0()
|
||||||
.canBeShared(getShareable().getId(), contact1From0));
|
.getSharingStatus(getShareable().getId(), contact1From0));
|
||||||
// Send invitation
|
// Send invitation
|
||||||
getSharingManager0()
|
getSharingManager0()
|
||||||
.sendInvitation(getShareable().getId(), contactId1From0,
|
.sendInvitation(getShareable().getId(), contactId1From0,
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ import java.util.Collection;
|
|||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
|
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -106,14 +108,18 @@ public class BlogSharingIntegrationTest
|
|||||||
public void testPersonalBlogCannotBeSharedWithOwner() throws Exception {
|
public void testPersonalBlogCannotBeSharedWithOwner() throws Exception {
|
||||||
listenToEvents(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog1.getId(),
|
assertEquals(SHARING,
|
||||||
contact1From0));
|
blogSharingManager0.getSharingStatus(blog1.getId(),
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
contact1From0));
|
||||||
contact2From0));
|
assertEquals(SHARING,
|
||||||
assertFalse(blogSharingManager1.canBeShared(blog0.getId(),
|
blogSharingManager0.getSharingStatus(blog2.getId(),
|
||||||
contact0From1));
|
contact2From0));
|
||||||
assertFalse(blogSharingManager2.canBeShared(blog0.getId(),
|
assertEquals(SHARING,
|
||||||
contact0From2));
|
blogSharingManager1.getSharingStatus(blog0.getId(),
|
||||||
|
contact0From1));
|
||||||
|
assertEquals(SHARING,
|
||||||
|
blogSharingManager2.getSharingStatus(blog0.getId(),
|
||||||
|
contact0From2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -191,13 +197,13 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, db0.transactionWithResult(true, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can not be shared again
|
// blog can not be shared again
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
assertEquals(SHARING, blogSharingManager0.getSharingStatus(
|
||||||
contact1From0));
|
blog2.getId(), contact1From0));
|
||||||
assertFalse(blogSharingManager1.canBeShared(blog2.getId(),
|
assertEquals(SHARING, blogSharingManager1.getSharingStatus(
|
||||||
contact0From1));
|
blog2.getId(), contact0From1));
|
||||||
|
|
||||||
// group message count is still correct
|
// group message count is still correct
|
||||||
assertGroupCount(messageTracker0, g, 2, 1);
|
assertGroupCount(messageTracker0, g, 2, 1);
|
||||||
@@ -300,13 +306,13 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, db0.transactionWithResult(true, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can not be shared again
|
// blog can not be shared again
|
||||||
assertFalse(blogSharingManager0.canBeShared(rssBlog.getId(),
|
assertEquals(SHARING, blogSharingManager0.getSharingStatus(
|
||||||
contact1From0));
|
rssBlog.getId(), contact1From0));
|
||||||
assertFalse(blogSharingManager1.canBeShared(rssBlog.getId(),
|
assertEquals(SHARING, blogSharingManager1.getSharingStatus(
|
||||||
contact0From1));
|
rssBlog.getId(), contact0From1));
|
||||||
|
|
||||||
// group message count is still correct
|
// group message count is still correct
|
||||||
assertGroupCount(messageTracker0, g, 2, 1);
|
assertGroupCount(messageTracker0, g, 2, 1);
|
||||||
@@ -361,11 +367,11 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, db0.transactionWithResult(true, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can be shared again
|
// blog can be shared again
|
||||||
assertTrue(
|
assertEquals(SHAREABLE, blogSharingManager0.getSharingStatus(
|
||||||
blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
blog2.getId(), contact1From0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -416,8 +422,8 @@ public class BlogSharingIntegrationTest
|
|||||||
assertEquals(0,
|
assertEquals(0,
|
||||||
blogSharingManager1.getSharedWith(blog2.getId()).size());
|
blogSharingManager1.getSharedWith(blog2.getId()).size());
|
||||||
// blog can be shared again by sharer
|
// blog can be shared again by sharer
|
||||||
assertTrue(
|
assertEquals(SHAREABLE, blogSharingManager0.getSharingStatus(
|
||||||
blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
blog2.getId(), contact1From0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -534,8 +540,8 @@ public class BlogSharingIntegrationTest
|
|||||||
.contains(contact0From1));
|
.contains(contact0From1));
|
||||||
|
|
||||||
// 1 can again share blog 1 with 0
|
// 1 can again share blog 1 with 0
|
||||||
assertTrue(
|
assertEquals(SHAREABLE, blogSharingManager1.getSharingStatus(
|
||||||
blogSharingManager1.canBeShared(blog1.getId(), contact0From1));
|
blog1.getId(), contact0From1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -592,8 +598,8 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0 can share blog2 again with 1
|
// 0 can share blog2 again with 1
|
||||||
assertTrue(
|
assertEquals(SHAREABLE, blogSharingManager0.getSharingStatus(
|
||||||
blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
blog2.getId(), contact1From0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
|||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID;
|
import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID;
|
||||||
import static org.briarproject.briar.api.forum.ForumSharingManager.MAJOR_VERSION;
|
import static org.briarproject.briar.api.forum.ForumSharingManager.MAJOR_VERSION;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.INVITED;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHAREABLE;
|
||||||
|
import static org.briarproject.briar.api.sharing.SharingManager.SharingStatus.SHARING;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -183,9 +186,11 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(2, getMessages1From0().size());
|
assertEquals(2, getMessages1From0().size());
|
||||||
// forum can not be shared again
|
// forum can not be shared again
|
||||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
assertFalse(forumSharingManager0.canBeShared(forum.getId(), c1));
|
assertEquals(SHARING,
|
||||||
|
forumSharingManager0.getSharingStatus(forum.getId(), c1));
|
||||||
Contact c0 = contactManager1.getContact(contactId0From1);
|
Contact c0 = contactManager1.getContact(contactId0From1);
|
||||||
assertFalse(forumSharingManager1.canBeShared(forum.getId(), c0));
|
assertEquals(SHARING,
|
||||||
|
forumSharingManager1.getSharingStatus(forum.getId(), c0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -271,7 +276,8 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(2, getMessages1From0().size());
|
assertEquals(2, getMessages1From0().size());
|
||||||
// forum can be shared again
|
// forum can be shared again
|
||||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
assertTrue(forumSharingManager0.canBeShared(forum.getId(), c1));
|
assertEquals(SHAREABLE,
|
||||||
|
forumSharingManager0.getSharingStatus(forum.getId(), c1));
|
||||||
|
|
||||||
// sharer un-subscribes from forum
|
// sharer un-subscribes from forum
|
||||||
forumManager0.removeForum(forum);
|
forumManager0.removeForum(forum);
|
||||||
@@ -340,18 +346,18 @@ public class ForumSharingIntegrationTest
|
|||||||
assertFalse(forumSharingManager1.getSharedWith(forum.getId())
|
assertFalse(forumSharingManager1.getSharedWith(forum.getId())
|
||||||
.contains(contact0));
|
.contains(contact0));
|
||||||
// forum can be shared again by sharer
|
// forum can be shared again by sharer
|
||||||
assertTrue(forumSharingManager0
|
assertEquals(SHAREABLE, forumSharingManager0
|
||||||
.canBeShared(forum.getId(), contact1From0));
|
.getSharingStatus(forum.getId(), contact1From0));
|
||||||
// invitee that left can not yet share again
|
// invitee that left can not yet share again
|
||||||
assertFalse(forumSharingManager1
|
assertEquals(INVITED, forumSharingManager1
|
||||||
.canBeShared(forum.getId(), contact0From1));
|
.getSharingStatus(forum.getId(), contact0From1));
|
||||||
|
|
||||||
// sharer responds with leave message
|
// sharer responds with leave message
|
||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
|
|
||||||
// invitee that left can now share again
|
// invitee that left can now share again
|
||||||
assertTrue(forumSharingManager1
|
assertEquals(SHAREABLE, forumSharingManager1
|
||||||
.canBeShared(forum.getId(), contact0From1));
|
.getSharingStatus(forum.getId(), contact0From1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -405,13 +411,15 @@ public class ForumSharingIntegrationTest
|
|||||||
assertFalse(forumSharingManager1.getSharedWith(forum.getId())
|
assertFalse(forumSharingManager1.getSharedWith(forum.getId())
|
||||||
.contains(contact0));
|
.contains(contact0));
|
||||||
// forum can be re-shared by invitee now
|
// forum can be re-shared by invitee now
|
||||||
assertTrue(forumSharingManager1.canBeShared(forum.getId(), c0));
|
assertEquals(SHAREABLE,
|
||||||
|
forumSharingManager1.getSharingStatus(forum.getId(), c0));
|
||||||
|
|
||||||
// invitee responds with LEAVE message
|
// invitee responds with LEAVE message
|
||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
// sharer can share forum again as well now
|
// sharer can share forum again as well now
|
||||||
assertTrue(forumSharingManager0.canBeShared(forum.getId(), c1));
|
assertEquals(SHAREABLE,
|
||||||
|
forumSharingManager0.getSharingStatus(forum.getId(), c1));
|
||||||
|
|
||||||
// invitee also un-subscribes forum without effect
|
// invitee also un-subscribes forum without effect
|
||||||
forumManager1.removeForum(forum);
|
forumManager1.removeForum(forum);
|
||||||
@@ -621,10 +629,10 @@ public class ForumSharingIntegrationTest
|
|||||||
addContacts1And2();
|
addContacts1And2();
|
||||||
|
|
||||||
// forum can be shared with contacts again
|
// forum can be shared with contacts again
|
||||||
assertTrue(forumSharingManager0
|
assertEquals(SHAREABLE, forumSharingManager0
|
||||||
.canBeShared(forum.getId(), contact1From0));
|
.getSharingStatus(forum.getId(), contact1From0));
|
||||||
assertTrue(forumSharingManager0
|
assertEquals(SHAREABLE, forumSharingManager0
|
||||||
.canBeShared(forum.getId(), contact2From0));
|
.getSharingStatus(forum.getId(), contact2From0));
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
forumSharingManager0
|
forumSharingManager0
|
||||||
|
|||||||
Reference in New Issue
Block a user