Address review comments

This commit is contained in:
Torsten Grote
2016-10-06 12:03:04 -03:00
parent 784561144a
commit 7f2db71160
41 changed files with 171 additions and 159 deletions

View File

@@ -28,7 +28,7 @@ import org.briarproject.api.event.ForumPostReceivedEvent;
import org.briarproject.api.event.IntroductionRequestReceivedEvent; import org.briarproject.api.event.IntroductionRequestReceivedEvent;
import org.briarproject.api.event.IntroductionResponseReceivedEvent; import org.briarproject.api.event.IntroductionResponseReceivedEvent;
import org.briarproject.api.event.IntroductionSucceededEvent; import org.briarproject.api.event.IntroductionSucceededEvent;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent; import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.event.PrivateMessageReceivedEvent; import org.briarproject.api.event.PrivateMessageReceivedEvent;
import org.briarproject.api.event.SettingsUpdatedEvent; import org.briarproject.api.event.SettingsUpdatedEvent;
@@ -235,8 +235,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} else if (e instanceof IntroductionResponseReceivedEvent) { } else if (e instanceof IntroductionResponseReceivedEvent) {
ContactId c = ((IntroductionResponseReceivedEvent) e).getContactId(); ContactId c = ((IntroductionResponseReceivedEvent) e).getContactId();
showNotificationForPrivateConversation(c); showNotificationForPrivateConversation(c);
} else if (e instanceof InvitationReceivedEvent) { } else if (e instanceof InvitationRequestReceivedEvent) {
ContactId c = ((InvitationReceivedEvent) e).getContactId(); ContactId c = ((InvitationRequestReceivedEvent) e).getContactId();
showNotificationForPrivateConversation(c); showNotificationForPrivateConversation(c);
} else if (e instanceof InvitationResponseReceivedEvent) { } else if (e instanceof InvitationResponseReceivedEvent) {
ContactId c = ((InvitationResponseReceivedEvent) e).getContactId(); ContactId c = ((InvitationResponseReceivedEvent) e).getContactId();

View File

@@ -50,10 +50,8 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
} }
}); });
if (item.getGroupId() != null) { ViewCompat.setTransitionName(ui.avatar, "avatar" +
ViewCompat.setTransitionName(ui.avatar, "avatar" + StringUtils.toHexString(item.getGroupId().getBytes()));
StringUtils.toHexString(item.getGroupId().getBytes()));
}
} }
@Override @Override
@@ -96,8 +94,7 @@ public abstract class BaseContactListAdapter<VH extends BaseContactListAdapter.B
int count = getItemCount(); int count = getItemCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
ContactListItem item = getItemAt(i); ContactListItem item = getItemAt(i);
if (item != null && item.getGroupId() != null && if (item != null && item.getGroupId().equals(g)) {
item.getGroupId().equals(g)) {
return i; return i;
} }
} }

View File

@@ -35,7 +35,7 @@ public class ContactListAdapter
if (item == null) return; if (item == null) return;
// unread count // unread count
long unread = item.getUnreadCount(); int unread = item.getUnreadCount();
if (unread > 0) { if (unread > 0) {
ui.unread.setText(String.valueOf(unread)); ui.unread.setText(String.valueOf(unread));
ui.unread.setVisibility(View.VISIBLE); ui.unread.setVisibility(View.VISIBLE);

View File

@@ -36,7 +36,7 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.IntroductionRequestReceivedEvent; import org.briarproject.api.event.IntroductionRequestReceivedEvent;
import org.briarproject.api.event.IntroductionResponseReceivedEvent; import org.briarproject.api.event.IntroductionResponseReceivedEvent;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent; import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.event.PrivateMessageReceivedEvent; import org.briarproject.api.event.PrivateMessageReceivedEvent;
import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.IdentityManager;
@@ -121,7 +121,6 @@ public class ContactListFragment extends BaseFragment implements EventListener {
@Override @Override
public void onItemClick(View view, ContactListItem item) { public void onItemClick(View view, ContactListItem item) {
GroupId groupId = item.getGroupId(); GroupId groupId = item.getGroupId();
if (groupId == null) return;
Intent i = new Intent(getActivity(), Intent i = new Intent(getActivity(),
ConversationActivity.class); ConversationActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes()); i.putExtra(GROUP_ID, groupId.getBytes());
@@ -270,9 +269,9 @@ public class ContactListFragment extends BaseFragment implements EventListener {
(IntroductionResponseReceivedEvent) e; (IntroductionResponseReceivedEvent) e;
IntroductionResponse ir = m.getIntroductionResponse(); IntroductionResponse ir = m.getIntroductionResponse();
updateItem(m.getContactId(), ConversationItem.from(ir)); updateItem(m.getContactId(), ConversationItem.from(ir));
} else if (e instanceof InvitationReceivedEvent) { } else if (e instanceof InvitationRequestReceivedEvent) {
LOG.info("Invitation Request received, update contact"); LOG.info("Invitation Request received, update contact");
InvitationReceivedEvent m = (InvitationReceivedEvent) e; InvitationRequestReceivedEvent m = (InvitationRequestReceivedEvent) e;
InvitationRequest ir = m.getRequest(); InvitationRequest ir = m.getRequest();
updateItem(m.getContactId(), ConversationItem.from(ir)); updateItem(m.getContactId(), ConversationItem.from(ir));
} else if (e instanceof InvitationResponseReceivedEvent) { } else if (e instanceof InvitationResponseReceivedEvent) {

View File

@@ -1,11 +1,10 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import android.support.annotation.Nullable;
import org.briarproject.api.clients.MessageTracker.GroupCount; import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.jetbrains.annotations.NotNull;
import static org.briarproject.android.contact.ConversationItem.IncomingItem; import static org.briarproject.android.contact.ConversationItem.IncomingItem;
@@ -17,10 +16,11 @@ public class ContactListItem {
private final GroupId groupId; private final GroupId groupId;
private boolean connected, empty; private boolean connected, empty;
private long timestamp; private long timestamp;
private long unread; private int unread;
public ContactListItem(Contact contact, LocalAuthor localAuthor, public ContactListItem(@NotNull Contact contact,
boolean connected, @Nullable GroupId groupId, GroupCount count) { @NotNull LocalAuthor localAuthor, boolean connected,
@NotNull GroupId groupId, @NotNull GroupCount count) {
this.contact = contact; this.contact = contact;
this.localAuthor = localAuthor; this.localAuthor = localAuthor;
this.groupId = groupId; this.groupId = groupId;
@@ -48,7 +48,6 @@ public class ContactListItem {
return localAuthor; return localAuthor;
} }
@Nullable
GroupId getGroupId() { GroupId getGroupId() {
return groupId; return groupId;
} }
@@ -69,7 +68,7 @@ public class ContactListItem {
return timestamp; return timestamp;
} }
long getUnreadCount() { int getUnreadCount() {
return unread; return unread;
} }
} }

View File

@@ -51,7 +51,7 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.IntroductionRequestReceivedEvent; import org.briarproject.api.event.IntroductionRequestReceivedEvent;
import org.briarproject.api.event.IntroductionResponseReceivedEvent; import org.briarproject.api.event.IntroductionResponseReceivedEvent;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent; import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.event.MessagesAckedEvent; import org.briarproject.api.event.MessagesAckedEvent;
import org.briarproject.api.event.MessagesSentEvent; import org.briarproject.api.event.MessagesSentEvent;
@@ -77,7 +77,7 @@ import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -481,12 +481,13 @@ public class ConversationActivity extends BriarActivity
SparseArray<IncomingItem> list = adapter.getIncomingMessages(); SparseArray<IncomingItem> list = adapter.getIncomingMessages();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
IncomingItem item = list.valueAt(i); IncomingItem item = list.valueAt(i);
if (!item.isRead()) unread.put(item.getId(), item.getGroupId()); if (!item.isRead())
unread.put(item.getId(), item.getGroupId());
} }
if (unread.isEmpty()) return; if (unread.isEmpty()) return;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Marking " + unread.size() + " messages read"); LOG.info("Marking " + unread.size() + " messages read");
markMessagesRead(Collections.unmodifiableMap(unread)); markMessagesRead(unread);
} }
private void markMessagesRead(final Map<MessageId, GroupId> unread) { private void markMessagesRead(final Map<MessageId, GroupId> unread) {
@@ -573,9 +574,9 @@ public class ConversationActivity extends BriarActivity
addConversationItem(item); addConversationItem(item);
markMessageReadIfNew(ir); markMessageReadIfNew(ir);
} }
} else if (e instanceof InvitationReceivedEvent) { } else if (e instanceof InvitationRequestReceivedEvent) {
InvitationReceivedEvent event = InvitationRequestReceivedEvent event =
(InvitationReceivedEvent) e; (InvitationRequestReceivedEvent) e;
if (event.getContactId().equals(contactId)) { if (event.getContactId().equals(contactId)) {
LOG.info("Invitation received, adding..."); LOG.info("Invitation received, adding...");
InvitationRequest ir = event.getRequest(); InvitationRequest ir = event.getRequest();

View File

@@ -1,14 +1,16 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import org.briarproject.android.contact.ConversationItem.IncomingItem;
import org.briarproject.api.introduction.IntroductionRequest; import org.briarproject.api.introduction.IntroductionRequest;
import org.jetbrains.annotations.NotNull;
// This class is not thread-safe // This class is not thread-safe
class ConversationIntroductionInItem extends ConversationIntroductionItem class ConversationIntroductionInItem extends ConversationIntroductionItem
implements ConversationItem.IncomingItem { implements IncomingItem {
private boolean read; private boolean read;
ConversationIntroductionInItem(IntroductionRequest ir) { ConversationIntroductionInItem(@NotNull IntroductionRequest ir) {
super(ir); super(ir);
this.read = ir.isRead(); this.read = ir.isRead();

View File

@@ -1,6 +1,7 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import org.briarproject.api.introduction.IntroductionRequest; import org.briarproject.api.introduction.IntroductionRequest;
import org.jetbrains.annotations.NotNull;
// This class is not thread-safe // This class is not thread-safe
abstract class ConversationIntroductionItem extends ConversationItem { abstract class ConversationIntroductionItem extends ConversationItem {
@@ -8,13 +9,14 @@ abstract class ConversationIntroductionItem extends ConversationItem {
private final IntroductionRequest ir; private final IntroductionRequest ir;
private boolean answered; private boolean answered;
ConversationIntroductionItem(IntroductionRequest ir) { ConversationIntroductionItem(@NotNull IntroductionRequest ir) {
super(ir.getMessageId(), ir.getGroupId(), ir.getTimestamp()); super(ir.getMessageId(), ir.getGroupId(), ir.getTimestamp());
this.ir = ir; this.ir = ir;
this.answered = ir.wasAnswered(); this.answered = ir.wasAnswered();
} }
@NotNull
IntroductionRequest getIntroductionRequest() { IntroductionRequest getIntroductionRequest() {
return ir; return ir;
} }

View File

@@ -14,6 +14,7 @@ import org.briarproject.api.sharing.InvitationRequest;
import org.briarproject.api.sharing.InvitationResponse; import org.briarproject.api.sharing.InvitationResponse;
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.NotNull;
// This class is not thread-safe // This class is not thread-safe
public abstract class ConversationItem { public abstract class ConversationItem {
@@ -31,11 +32,12 @@ public abstract class ConversationItem {
final static int BLOG_INVITATION_IN = 9; final static int BLOG_INVITATION_IN = 9;
final static int BLOG_INVITATION_OUT = 10; final static int BLOG_INVITATION_OUT = 10;
private MessageId id; final private MessageId id;
private GroupId groupId; final private GroupId groupId;
private long time; final private long time;
public ConversationItem(MessageId id, GroupId groupId, long time) { public ConversationItem(@NotNull MessageId id, @NotNull GroupId groupId,
long time) {
this.id = id; this.id = id;
this.groupId = groupId; this.groupId = groupId;
this.time = time; this.time = time;
@@ -43,10 +45,12 @@ public abstract class ConversationItem {
abstract int getType(); abstract int getType();
@NotNull
public MessageId getId() { public MessageId getId() {
return id; return id;
} }
@NotNull
public GroupId getGroupId() { public GroupId getGroupId() {
return groupId; return groupId;
} }
@@ -221,6 +225,7 @@ public abstract class ConversationItem {
interface OutgoingItem { interface OutgoingItem {
@NotNull
MessageId getId(); MessageId getId();
boolean isSent(); boolean isSent();
@@ -234,8 +239,10 @@ public abstract class ConversationItem {
interface IncomingItem { interface IncomingItem {
@NotNull
MessageId getId(); MessageId getId();
@NotNull
GroupId getGroupId(); GroupId getGroupId();
boolean isRead(); boolean isRead();

View File

@@ -51,7 +51,7 @@ class ForumListAdapter
ui.name.setText(item.getForum().getName()); ui.name.setText(item.getForum().getName());
// Post Count // Post Count
int postCount = (int) item.getPostCount(); int postCount = item.getPostCount();
if (postCount > 0) { if (postCount > 0) {
ui.avatar.setProblem(false); ui.avatar.setProblem(false);
ui.postCount.setText(ctx.getResources() ui.postCount.setText(ctx.getResources()

View File

@@ -8,7 +8,8 @@ import org.briarproject.api.forum.ForumPostHeader;
class ForumListItem { class ForumListItem {
private final Forum forum; private final Forum forum;
private long postCount, unread, timestamp; private int postCount, unread;
private long timestamp;
ForumListItem(Forum forum, GroupCount count) { ForumListItem(Forum forum, GroupCount count) {
this.forum = forum; this.forum = forum;
@@ -31,7 +32,7 @@ class ForumListItem {
return postCount == 0; return postCount == 0;
} }
long getPostCount() { int getPostCount() {
return postCount; return postCount;
} }
@@ -39,7 +40,7 @@ class ForumListItem {
return timestamp; return timestamp;
} }
long getUnreadCount() { int getUnreadCount() {
return unread; return unread;
} }
} }

View File

@@ -9,7 +9,6 @@ import org.briarproject.R;
import org.briarproject.android.BriarActivity; import org.briarproject.android.BriarActivity;
import org.briarproject.android.contact.ContactListItem; import org.briarproject.android.contact.ContactListItem;
import org.briarproject.android.view.BriarRecyclerView; import org.briarproject.android.view.BriarRecyclerView;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.MessageTracker.GroupCount; import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
@@ -107,8 +106,8 @@ abstract class SharingStatusActivity extends BriarActivity {
LocalAuthor localAuthor = identityManager LocalAuthor localAuthor = identityManager
.getLocalAuthor(c.getLocalAuthorId()); .getLocalAuthor(c.getLocalAuthorId());
ContactListItem item = ContactListItem item =
new ContactListItem(c, localAuthor, false, null, new ContactListItem(c, localAuthor, false,
new GroupCount(0, 0, 0)); groupId, new GroupCount(0, 0, 0));
contactItems.add(item); contactItems.add(item);
} }
} catch (DbException e) { } catch (DbException e) {
@@ -143,8 +142,8 @@ abstract class SharingStatusActivity extends BriarActivity {
LocalAuthor localAuthor = identityManager LocalAuthor localAuthor = identityManager
.getLocalAuthor(c.getLocalAuthorId()); .getLocalAuthor(c.getLocalAuthorId());
ContactListItem item = ContactListItem item =
new ContactListItem(c, localAuthor, false, null, new ContactListItem(c, localAuthor, false,
new GroupCount(0, 0, 0)); groupId, new GroupCount(0, 0, 0));
contactItems.add(item); contactItems.add(item);
} }
} catch (DbException e) { } catch (DbException e) {

View File

@@ -24,7 +24,7 @@ public class TextAvatarView extends FrameLayout {
final private AppCompatTextView character; final private AppCompatTextView character;
final private CircleImageView background; final private CircleImageView background;
final private TextView badge; final private TextView badge;
private long unreadCount; private int unreadCount;
public TextAvatarView(Context context, @Nullable AttributeSet attrs) { public TextAvatarView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@@ -48,11 +48,7 @@ public class TextAvatarView extends FrameLayout {
} }
public void setUnreadCount(int count) { public void setUnreadCount(int count) {
setUnreadCount((long) count); unreadCount = count;
}
public void setUnreadCount(long count) {
this.unreadCount = count;
if (count > 0) { if (count > 0) {
badge.setBackgroundResource(R.drawable.bubble); badge.setBackgroundResource(R.drawable.bubble);
badge.setText(String.valueOf(count)); badge.setText(String.valueOf(count));
@@ -60,7 +56,6 @@ public class TextAvatarView extends FrameLayout {
R.color.briar_text_primary_inverse)); R.color.briar_text_primary_inverse));
badge.setVisibility(VISIBLE); badge.setVisibility(VISIBLE);
} else { } else {
badge.setText("");
badge.setVisibility(INVISIBLE); badge.setVisibility(INVISIBLE);
} }
} }
@@ -72,11 +67,8 @@ public class TextAvatarView extends FrameLayout {
badge.setTextColor(ContextCompat badge.setTextColor(ContextCompat
.getColor(getContext(), R.color.briar_primary)); .getColor(getContext(), R.color.briar_primary));
badge.setVisibility(VISIBLE); badge.setVisibility(VISIBLE);
} else if (unreadCount > 0) {
setUnreadCount(unreadCount);
} else { } else {
badge.setText(""); setUnreadCount(unreadCount);
badge.setVisibility(INVISIBLE);
} }
} }

View File

@@ -9,18 +9,13 @@ import android.support.annotation.CallSuper;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.support.v7.widget.AppCompatImageButton;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import org.briarproject.R; import org.briarproject.R;
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout; import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
@@ -32,7 +27,6 @@ import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import java.util.logging.Logger; import java.util.logging.Logger;
import static android.content.Context.INPUT_METHOD_SERVICE; import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
@UiThread @UiThread
public class TextInputView extends KeyboardAwareLinearLayout public class TextInputView extends KeyboardAwareLinearLayout

View File

@@ -5,10 +5,11 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.sharing.InvitationResponse; import org.briarproject.api.sharing.InvitationResponse;
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.NotNull;
public class BlogInvitationResponse extends InvitationResponse { public class BlogInvitationResponse extends InvitationResponse {
public BlogInvitationResponse(MessageId id, SessionId sessionId, public BlogInvitationResponse(@NotNull MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time, GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) { boolean local, boolean sent, boolean seen, boolean read) {

View File

@@ -2,6 +2,7 @@ package org.briarproject.api.clients;
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.NotNull;
public abstract class BaseMessageHeader { public abstract class BaseMessageHeader {
@@ -10,8 +11,9 @@ public abstract class BaseMessageHeader {
private final long timestamp; private final long timestamp;
private final boolean local, read, sent, seen; private final boolean local, read, sent, seen;
public BaseMessageHeader(MessageId id, GroupId groupId, long timestamp, public BaseMessageHeader(@NotNull MessageId id, @NotNull GroupId groupId,
boolean local, boolean read, boolean sent, boolean seen) { long timestamp, boolean local, boolean read, boolean sent,
boolean seen) {
this.id = id; this.id = id;
this.groupId = groupId; this.groupId = groupId;
@@ -22,10 +24,12 @@ public abstract class BaseMessageHeader {
this.seen = seen; this.seen = seen;
} }
@NotNull
public MessageId getId() { public MessageId getId() {
return id; return id;
} }
@NotNull
public GroupId getGroupId() { public GroupId getGroupId() {
return groupId; return groupId;
} }

View File

@@ -1,9 +1,7 @@
package org.briarproject.api.clients; package org.briarproject.api.clients;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
public interface MessageTracker { public interface MessageTracker {
@@ -20,19 +18,20 @@ public interface MessageTracker {
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException; void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
class GroupCount { class GroupCount {
private final long msgCount, unreadCount, latestMsgTime; private final int msgCount, unreadCount;
private final long latestMsgTime;
public GroupCount(long msgCount, long unreadCount, long latestMsgTime) { public GroupCount(int msgCount, int unreadCount, long latestMsgTime) {
this.msgCount = msgCount; this.msgCount = msgCount;
this.unreadCount = unreadCount; this.unreadCount = unreadCount;
this.latestMsgTime = latestMsgTime; this.latestMsgTime = latestMsgTime;
} }
public long getMsgCount() { public int getMsgCount() {
return msgCount; return msgCount;
} }
public long getUnreadCount() { public int getUnreadCount() {
return unreadCount; return unreadCount;
} }

View File

@@ -4,7 +4,8 @@ import org.briarproject.api.blogs.Blog;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.sharing.InvitationRequest; import org.briarproject.api.sharing.InvitationRequest;
public class BlogInvitationReceivedEvent extends InvitationReceivedEvent { public class BlogInvitationReceivedEvent extends
InvitationRequestReceivedEvent {
private final Blog blog; private final Blog blog;

View File

@@ -4,7 +4,8 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.forum.Forum; import org.briarproject.api.forum.Forum;
import org.briarproject.api.forum.ForumInvitationRequest; import org.briarproject.api.forum.ForumInvitationRequest;
public class ForumInvitationReceivedEvent extends InvitationReceivedEvent { public class ForumInvitationReceivedEvent extends
InvitationRequestReceivedEvent {
private final Forum forum; private final Forum forum;

View File

@@ -3,12 +3,13 @@ package org.briarproject.api.event;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.sharing.InvitationRequest; import org.briarproject.api.sharing.InvitationRequest;
public abstract class InvitationReceivedEvent extends Event { public abstract class InvitationRequestReceivedEvent extends Event {
private final ContactId contactId; private final ContactId contactId;
private final InvitationRequest request; private final InvitationRequest request;
InvitationReceivedEvent(ContactId contactId, InvitationRequest request) { InvitationRequestReceivedEvent(ContactId contactId,
InvitationRequest request) {
this.contactId = contactId; this.contactId = contactId;
this.request = request; this.request = request;
} }

View File

@@ -5,11 +5,12 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.sharing.InvitationResponse; import org.briarproject.api.sharing.InvitationResponse;
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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class ForumInvitationResponse extends InvitationResponse { public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, SessionId sessionId, public ForumInvitationResponse(@NotNull MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time, boolean local, GroupId groupId, ContactId contactId, boolean accept, long time, boolean local,
boolean sent, boolean seen, boolean read) { boolean sent, boolean seen, boolean read) {

View File

@@ -1,22 +1,23 @@
package org.briarproject.api.introduction; package org.briarproject.api.introduction;
import org.briarproject.api.clients.SessionId;
import org.briarproject.api.clients.BaseMessageHeader; import org.briarproject.api.clients.BaseMessageHeader;
import org.briarproject.api.clients.SessionId;
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.NotNull;
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCEE;
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCER; import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCER;
public class IntroductionMessage extends BaseMessageHeader { public class IntroductionMessage extends BaseMessageHeader {
private final SessionId sessionId; private final SessionId sessionId;
private final MessageId messageId; private final MessageId messageId;
private final int role; private final int role;
public IntroductionMessage(SessionId sessionId, MessageId messageId, public IntroductionMessage(@NotNull SessionId sessionId,
GroupId groupId, int role, long time, boolean local, boolean sent, @NotNull MessageId messageId, @NotNull GroupId groupId, int role,
boolean seen, boolean read) { long time, boolean local, boolean sent, boolean seen,
boolean read) {
super(messageId, groupId, time, local, read, sent, seen); super(messageId, groupId, time, local, read, sent, seen);
this.sessionId = sessionId; this.sessionId = sessionId;
@@ -24,10 +25,12 @@ import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRO
this.role = role; this.role = role;
} }
@NotNull
public SessionId getSessionId() { public SessionId getSessionId() {
return sessionId; return sessionId;
} }
@NotNull
public MessageId getMessageId() { public MessageId getMessageId() {
return messageId; return messageId;
} }
@@ -36,9 +39,4 @@ import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRO
return role == ROLE_INTRODUCER; return role == ROLE_INTRODUCER;
} }
public boolean isIntroducee() {
return role == ROLE_INTRODUCEE;
}
} }

View File

@@ -4,16 +4,19 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.AuthorId;
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.NotNull;
import org.jetbrains.annotations.Nullable;
public class IntroductionRequest extends IntroductionResponse { public class IntroductionRequest extends IntroductionResponse {
private final String message; private final String message;
private final boolean answered, exists, introducesOtherIdentity; private final boolean answered, exists, introducesOtherIdentity;
public IntroductionRequest(SessionId sessionId, MessageId messageId, public IntroductionRequest(@NotNull SessionId sessionId,
GroupId groupId, int role, long time, boolean local, boolean sent, @NotNull MessageId messageId, @NotNull GroupId groupId, int role,
boolean seen, boolean read, AuthorId authorId, String name, long time, boolean local, boolean sent, boolean seen, boolean read,
boolean accepted, String message, boolean answered, boolean exists, AuthorId authorId, String name, boolean accepted,
@Nullable String message, boolean answered, boolean exists,
boolean introducesOtherIdentity) { boolean introducesOtherIdentity) {
super(sessionId, messageId, groupId, role, time, local, sent, seen, super(sessionId, messageId, groupId, role, time, local, sent, seen,
@@ -25,6 +28,7 @@ public class IntroductionRequest extends IntroductionResponse {
this.introducesOtherIdentity = introducesOtherIdentity; this.introducesOtherIdentity = introducesOtherIdentity;
} }
@Nullable
public String getMessage() { public String getMessage() {
return message; return message;
} }

View File

@@ -4,6 +4,7 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.AuthorId;
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.NotNull;
public class IntroductionResponse extends IntroductionMessage { public class IntroductionResponse extends IntroductionMessage {
@@ -11,10 +12,10 @@ public class IntroductionResponse extends IntroductionMessage {
private final String name; private final String name;
private final boolean accepted; private final boolean accepted;
public IntroductionResponse(SessionId sessionId, MessageId messageId, public IntroductionResponse(@NotNull SessionId sessionId,
GroupId groupId, int role, long time, boolean local, boolean sent, @NotNull MessageId messageId, @NotNull GroupId groupId, int role,
boolean seen, boolean read, AuthorId remoteAuthorId, String name, long time, boolean local, boolean sent, boolean seen, boolean read,
boolean accepted) { AuthorId remoteAuthorId, String name, boolean accepted) {
super(sessionId, messageId, groupId, role, time, local, sent, seen, super(sessionId, messageId, groupId, role, time, local, sent, seen,
read); read);

View File

@@ -5,25 +5,29 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
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.NotNull;
public abstract class InvitationMessage extends BaseMessageHeader { public abstract class InvitationMessage extends BaseMessageHeader {
private final SessionId sessionId; private final SessionId sessionId;
private final ContactId contactId; private final ContactId contactId;
public InvitationMessage(MessageId id, SessionId sessionId, GroupId groupId, public InvitationMessage(@NotNull MessageId id,
ContactId contactId, long time, boolean local, boolean sent, @NotNull SessionId sessionId, @NotNull GroupId groupId,
boolean seen, boolean read) { @NotNull ContactId contactId, long time, boolean local,
boolean sent, boolean seen, boolean read) {
super(id, groupId, time, local, read, sent, seen); super(id, groupId, time, local, read, sent, seen);
this.sessionId = sessionId; this.sessionId = sessionId;
this.contactId = contactId; this.contactId = contactId;
} }
@NotNull
public SessionId getSessionId() { public SessionId getSessionId() {
return sessionId; return sessionId;
} }
@NotNull
public ContactId getContactId() { public ContactId getContactId() {
return contactId; return contactId;
} }

View File

@@ -4,6 +4,7 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public abstract class InvitationRequest extends InvitationMessage { public abstract class InvitationRequest extends InvitationMessage {
@@ -11,8 +12,9 @@ public abstract class InvitationRequest extends InvitationMessage {
private final String message; private final String message;
private final boolean available; private final boolean available;
public InvitationRequest(MessageId id, SessionId sessionId, GroupId groupId, public InvitationRequest(@NotNull MessageId id,
ContactId contactId, String message, @NotNull SessionId sessionId, @NotNull GroupId groupId,
@NotNull ContactId contactId, @Nullable String message,
boolean available, long time, boolean local, boolean sent, boolean available, long time, boolean local, boolean sent,
boolean seen, boolean read) { boolean seen, boolean read) {

View File

@@ -4,12 +4,13 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
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.NotNull;
public abstract class InvitationResponse extends InvitationMessage { public abstract class InvitationResponse extends InvitationMessage {
private final boolean accept; private final boolean accept;
public InvitationResponse(MessageId id, SessionId sessionId, public InvitationResponse(@NotNull MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time, GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) { boolean local, boolean sent, boolean seen, boolean read) {

View File

@@ -81,8 +81,8 @@ public abstract class BdfIncomingMessageHook implements IncomingMessageHook,
protected void trackMessage(Transaction txn, GroupId g, long time, protected void trackMessage(Transaction txn, GroupId g, long time,
boolean read) throws DbException { boolean read) throws DbException {
GroupCount c = getGroupCount(txn, g); GroupCount c = getGroupCount(txn, g);
long msgCount = c.getMsgCount() + 1; int msgCount = c.getMsgCount() + 1;
long unreadCount = c.getUnreadCount() + (read ? 0 : 1); int unreadCount = c.getUnreadCount() + (read ? 0 : 1);
long latestTime = long latestTime =
time > c.getLatestMsgTime() ? time : c.getLatestMsgTime(); time > c.getLatestMsgTime() ? time : c.getLatestMsgTime();
storeGroupCount(txn, g, storeGroupCount(txn, g,
@@ -109,8 +109,8 @@ public abstract class BdfIncomingMessageHook implements IncomingMessageHook,
try { try {
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g); BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g);
count = new GroupCount( count = new GroupCount(
d.getLong(GROUP_KEY_MSG_COUNT, 0L), d.getLong(GROUP_KEY_MSG_COUNT, 0L).intValue(),
d.getLong(GROUP_KEY_UNREAD_COUNT, 0L), d.getLong(GROUP_KEY_UNREAD_COUNT, 0L).intValue(),
d.getLong(GROUP_KEY_LATEST_MSG, 0L) d.getLong(GROUP_KEY_LATEST_MSG, 0L)
); );
} catch (FormatException e) { } catch (FormatException e) {

View File

@@ -8,19 +8,18 @@ import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction; import org.briarproject.api.db.Transaction;
import org.briarproject.api.messaging.ConversationManager; import org.briarproject.api.messaging.ConversationManager;
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
public abstract class ConversationClient extends BdfIncomingMessageHook public abstract class ConversationClientImpl extends BdfIncomingMessageHook
implements ConversationManager.ConversationClient { implements ConversationClient {
protected ConversationClient(DatabaseComponent db, protected ConversationClientImpl(DatabaseComponent db,
ClientHelper clientHelper, MetadataParser metadataParser) { ClientHelper clientHelper, MetadataParser metadataParser) {
super(db, clientHelper, metadataParser); super(db, clientHelper, metadataParser);
} }
// TODO overwrite super methods to store GroupCount data in a single group
protected abstract Group getContactGroup(Contact contact); protected abstract Group getContactGroup(Contact contact);
@Override @Override

View File

@@ -29,7 +29,7 @@ import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageStatus; import org.briarproject.api.sync.MessageStatus;
import org.briarproject.clients.ConversationClient; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.io.IOException; import java.io.IOException;
@@ -76,7 +76,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUE
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE; import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE;
import static org.briarproject.clients.BdfConstants.MSG_KEY_READ; import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
class IntroductionManagerImpl extends ConversationClient class IntroductionManagerImpl extends ConversationClientImpl
implements IntroductionManager, Client, AddContactHook, implements IntroductionManager, Client, AddContactHook,
RemoveContactHook { RemoveContactHook {

View File

@@ -32,7 +32,10 @@ class ConversationManagerImpl implements ConversationManager {
@Override @Override
public void registerConversationClient(ConversationClient client) { public void registerConversationClient(ConversationClient client) {
clients.add(client); if (!clients.add(client)) {
throw new IllegalStateException(
"This client is already registered");
}
} }
@Override @Override
@@ -56,7 +59,8 @@ class ConversationManagerImpl implements ConversationManager {
public GroupCount getGroupCount(ContactId contactId) public GroupCount getGroupCount(ContactId contactId)
throws DbException { throws DbException {
long msgCount = 0, unreadCount = 0, latestTime = 0; int msgCount = 0, unreadCount = 0;
long latestTime = 0;
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
for (ConversationClient client : clients) { for (ConversationClient client : clients) {

View File

@@ -24,7 +24,7 @@ import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageStatus; import org.briarproject.api.sync.MessageStatus;
import org.briarproject.clients.ConversationClient; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -35,7 +35,7 @@ import javax.inject.Inject;
import static org.briarproject.clients.BdfConstants.MSG_KEY_READ; import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
class MessagingManagerImpl extends ConversationClient class MessagingManagerImpl extends ConversationClientImpl
implements MessagingManager, Client, AddContactHook, RemoveContactHook { implements MessagingManager, Client, AddContactHook, RemoveContactHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString( static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(

View File

@@ -5,6 +5,7 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
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.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
@@ -22,7 +23,7 @@ public class BlogInviteeSessionState extends InviteeSessionState {
public BlogInviteeSessionState(SessionId sessionId, MessageId storageId, public BlogInviteeSessionState(SessionId sessionId, MessageId storageId,
GroupId groupId, State state, ContactId contactId, GroupId blogId, GroupId groupId, State state, ContactId contactId, GroupId blogId,
String blogTitle, String blogDesc, String blogAuthorName, String blogTitle, String blogDesc, String blogAuthorName,
byte[] blogPublicKey, @Nullable MessageId invitationId) { byte[] blogPublicKey, @NotNull MessageId invitationId) {
super(sessionId, storageId, groupId, state, contactId, blogId, super(sessionId, storageId, groupId, state, contactId, blogId,
invitationId); invitationId);

View File

@@ -44,6 +44,7 @@ import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE; import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID;
import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID;
class BlogSharingManagerImpl extends class BlogSharingManagerImpl extends
SharingManagerImpl<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent> SharingManagerImpl<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent>
@@ -253,10 +254,7 @@ class BlogSharingManagerImpl extends
String blogDesc = d.getString(BLOG_DESC); String blogDesc = d.getString(BLOG_DESC);
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME); String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY); byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
MessageId invitationId = null; MessageId invitationId = new MessageId(d.getRaw(INVITATION_ID));
byte[] invitationIdBytes = d.getOptionalRaw(INVITATION_ID);
if (invitationIdBytes != null)
invitationId = new MessageId(invitationIdBytes);
return new BlogInviteeSessionState(sessionId, storageId, return new BlogInviteeSessionState(sessionId, storageId,
groupId, state, contactId, blogId, blogTitle, blogDesc, groupId, state, contactId, blogId, blogTitle, blogDesc,
blogAuthorName, blogPublicKey, invitationId); blogAuthorName, blogPublicKey, invitationId);
@@ -286,7 +284,7 @@ class BlogSharingManagerImpl extends
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME); String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY); byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
MessageId responseId = null; MessageId responseId = null;
byte[] responseIdBytes = d.getOptionalRaw(INVITATION_ID); byte[] responseIdBytes = d.getOptionalRaw(RESPONSE_ID);
if (responseIdBytes != null) if (responseIdBytes != null)
responseId = new MessageId(responseIdBytes); responseId = new MessageId(responseIdBytes);
return new BlogSharerSessionState(sessionId, storageId, return new BlogSharerSessionState(sessionId, storageId,
@@ -336,8 +334,11 @@ class BlogSharingManagerImpl extends
BlogSharerSessionState localState, boolean accept, long time) { BlogSharerSessionState localState, boolean accept, long time) {
String title = localState.getBlogTitle(); String title = localState.getBlogTitle();
ContactId c = localState.getContactId(); ContactId c = localState.getContactId();
MessageId responseId = localState.getResponseId();
if (responseId == null)
throw new IllegalStateException("No responseId");
BlogInvitationResponse response = BlogInvitationResponse response =
new BlogInvitationResponse(localState.getResponseId(), new BlogInvitationResponse(responseId,
localState.getSessionId(), localState.getGroupId(), localState.getSessionId(), localState.getGroupId(),
localState.getContactId(), accept, time, false, localState.getContactId(), accept, time, false,
false, false, false); false, false, false);

View File

@@ -5,7 +5,7 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
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; import org.jetbrains.annotations.NotNull;
import static org.briarproject.api.forum.ForumConstants.FORUM_NAME; import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT; import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
@@ -18,7 +18,7 @@ public class ForumInviteeSessionState extends InviteeSessionState {
public ForumInviteeSessionState(SessionId sessionId, MessageId storageId, public ForumInviteeSessionState(SessionId sessionId, MessageId storageId,
GroupId groupId, State state, ContactId contactId, GroupId forumId, GroupId groupId, State state, ContactId contactId, GroupId forumId,
String forumName, byte[] forumSalt, String forumName, byte[] forumSalt,
@Nullable MessageId invitationId) { @NotNull MessageId invitationId) {
super(sessionId, storageId, groupId, state, contactId, forumId, super(sessionId, storageId, groupId, state, contactId, forumId,
invitationId); invitationId);

View File

@@ -36,6 +36,7 @@ import javax.inject.Inject;
import static org.briarproject.api.forum.ForumConstants.FORUM_NAME; import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT; import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID;
import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID;
class ForumSharingManagerImpl extends class ForumSharingManagerImpl extends
SharingManagerImpl<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent> SharingManagerImpl<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent>
@@ -204,10 +205,7 @@ class ForumSharingManagerImpl extends
GroupId forumId, BdfDictionary d) throws FormatException { GroupId forumId, BdfDictionary d) throws FormatException {
String forumName = d.getString(FORUM_NAME); String forumName = d.getString(FORUM_NAME);
byte[] forumSalt = d.getRaw(FORUM_SALT); byte[] forumSalt = d.getRaw(FORUM_SALT);
MessageId invitationId = null; MessageId invitationId = new MessageId(d.getRaw(INVITATION_ID));
byte[] invitationIdBytes = d.getOptionalRaw(INVITATION_ID);
if (invitationIdBytes != null)
invitationId = new MessageId(invitationIdBytes);
return new ForumInviteeSessionState(sessionId, storageId, return new ForumInviteeSessionState(sessionId, storageId,
groupId, state, contactId, forumId, forumName, forumSalt, groupId, state, contactId, forumId, forumName, forumSalt,
invitationId); invitationId);
@@ -234,7 +232,7 @@ class ForumSharingManagerImpl extends
String forumName = d.getString(FORUM_NAME); String forumName = d.getString(FORUM_NAME);
byte[] forumSalt = d.getRaw(FORUM_SALT); byte[] forumSalt = d.getRaw(FORUM_SALT);
MessageId responseId = null; MessageId responseId = null;
byte[] responseIdBytes = d.getOptionalRaw(INVITATION_ID); byte[] responseIdBytes = d.getOptionalRaw(RESPONSE_ID);
if (responseIdBytes != null) if (responseIdBytes != null)
responseId = new MessageId(responseIdBytes); responseId = new MessageId(responseIdBytes);
return new ForumSharerSessionState(sessionId, storageId, return new ForumSharerSessionState(sessionId, storageId,
@@ -282,8 +280,11 @@ class ForumSharingManagerImpl extends
ForumSharerSessionState localState, boolean accept, long time) { ForumSharerSessionState localState, boolean accept, long time) {
String name = localState.getForumName(); String name = localState.getForumName();
ContactId c = localState.getContactId(); ContactId c = localState.getContactId();
MessageId responseId = localState.getResponseId();
if (responseId == null)
throw new IllegalStateException("No responseId");
ForumInvitationResponse response = new ForumInvitationResponse( ForumInvitationResponse response = new ForumInvitationResponse(
localState.getResponseId(), localState.getSessionId(), responseId, localState.getSessionId(),
localState.getGroupId(), localState.getContactId(), accept, localState.getGroupId(), localState.getContactId(), accept,
time, false, false, false, false); time, false, false, false, false);
return new ForumInvitationResponseReceivedEvent(name, c, response); return new ForumInvitationResponseReceivedEvent(name, c, response);

View File

@@ -1,8 +1,8 @@
package org.briarproject.sharing; package org.briarproject.sharing;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
public interface InvitationReceivedEventFactory<IS extends InviteeSessionState, IR extends InvitationReceivedEvent> { public interface InvitationReceivedEventFactory<IS extends InviteeSessionState, IR extends InvitationRequestReceivedEvent> {
IR build(IS localState, long time, String msg); IR build(IS localState, long time, String msg);
} }

View File

@@ -3,7 +3,7 @@ package org.briarproject.sharing;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
import org.briarproject.api.clients.ProtocolEngine; import org.briarproject.api.clients.ProtocolEngine;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.sharing.SharingMessage.Invitation; import org.briarproject.api.sharing.SharingMessage.Invitation;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
@@ -25,7 +25,7 @@ import static org.briarproject.api.sharing.SharingConstants.TASK_UNSHARE_SHAREAB
import static org.briarproject.api.sharing.SharingMessage.BaseMessage; import static org.briarproject.api.sharing.SharingMessage.BaseMessage;
import static org.briarproject.api.sharing.SharingMessage.SimpleMessage; import static org.briarproject.api.sharing.SharingMessage.SimpleMessage;
class InviteeEngine<IS extends InviteeSessionState, IR extends InvitationReceivedEvent> class InviteeEngine<IS extends InviteeSessionState, IR extends InvitationRequestReceivedEvent>
implements ProtocolEngine<InviteeSessionState.Action, IS, BaseMessage> { implements ProtocolEngine<InviteeSessionState.Action, IS, BaseMessage> {
private static final Logger LOG = private static final Logger LOG =

View File

@@ -5,7 +5,7 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfDictionary;
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; import org.jetbrains.annotations.NotNull;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID;
import static org.briarproject.api.sharing.SharingConstants.IS_SHARER; import static org.briarproject.api.sharing.SharingConstants.IS_SHARER;
@@ -23,11 +23,12 @@ import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_LEAVE;
public abstract class InviteeSessionState extends SharingSessionState { public abstract class InviteeSessionState extends SharingSessionState {
private State state; private State state;
@NotNull
private final MessageId invitationId; private final MessageId invitationId;
public InviteeSessionState(SessionId sessionId, MessageId storageId, public InviteeSessionState(SessionId sessionId, MessageId storageId,
GroupId groupId, State state, ContactId contactId, GroupId groupId, State state, ContactId contactId,
GroupId shareableId, MessageId invitationId) { GroupId shareableId, @NotNull MessageId invitationId) {
super(sessionId, storageId, groupId, contactId, shareableId); super(sessionId, storageId, groupId, contactId, shareableId);
this.state = state; this.state = state;
@@ -38,7 +39,7 @@ public abstract class InviteeSessionState extends SharingSessionState {
BdfDictionary d = super.toBdfDictionary(); BdfDictionary d = super.toBdfDictionary();
d.put(STATE, getState().getValue()); d.put(STATE, getState().getValue());
d.put(IS_SHARER, false); d.put(IS_SHARER, false);
if (invitationId != null) d.put(INVITATION_ID, invitationId); d.put(INVITATION_ID, invitationId);
return d; return d;
} }
@@ -50,7 +51,7 @@ public abstract class InviteeSessionState extends SharingSessionState {
return state; return state;
} }
@Nullable @NotNull
public MessageId getInvitationId() { public MessageId getInvitationId() {
return invitationId; return invitationId;
} }

View File

@@ -22,7 +22,7 @@ import org.briarproject.api.db.Metadata;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.Transaction; import org.briarproject.api.db.Transaction;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
import org.briarproject.api.event.InvitationReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent; import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sharing.InvitationItem; import org.briarproject.api.sharing.InvitationItem;
@@ -36,7 +36,7 @@ import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageStatus; import org.briarproject.api.sync.MessageStatus;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.clients.ConversationClient; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.io.IOException; import java.io.IOException;
@@ -85,8 +85,8 @@ import static org.briarproject.api.sharing.SharingMessage.Invitation;
import static org.briarproject.clients.BdfConstants.MSG_KEY_READ; import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
import static org.briarproject.sharing.InviteeSessionState.State.AWAIT_LOCAL_RESPONSE; import static org.briarproject.sharing.InviteeSessionState.State.AWAIT_LOCAL_RESPONSE;
abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS extends InviteeSessionState, SS extends SharerSessionState, IR extends InvitationReceivedEvent, IRR extends InvitationResponseReceivedEvent> abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS extends InviteeSessionState, SS extends SharerSessionState, IR extends InvitationRequestReceivedEvent, IRR extends InvitationResponseReceivedEvent>
extends ConversationClient extends ConversationClientImpl
implements SharingManager<S>, Client, AddContactHook, implements SharingManager<S>, Client, AddContactHook,
RemoveContactHook { RemoveContactHook {
@@ -212,7 +212,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
if (stateExists) throw new FormatException(); if (stateExists) throw new FormatException();
// check if shareable can be shared // check if shareable can be shared
@SuppressWarnings("unchecked")
I invitation = (I) msg; I invitation = (I) msg;
S f = getSFactory().parse(invitation); S f = getSFactory().parse(invitation);
ContactId contactId = getContactId(txn, m.getGroupId()); ContactId contactId = getContactId(txn, m.getGroupId());
@@ -249,7 +248,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
SharingSessionState s = getSessionState(txn, sessionId, true); SharingSessionState s = getSessionState(txn, sessionId, true);
if (s instanceof SharerSessionState) { if (s instanceof SharerSessionState) {
// we are a sharer and the invitee wants to leave or abort // we are a sharer and the invitee wants to leave or abort
@SuppressWarnings("unchecked")
SS state = (SS) s; SS state = (SS) s;
SharerEngine<I, SS, IRR> engine = SharerEngine<I, SS, IRR> engine =
new SharerEngine<I, SS, IRR>(getIFactory(), new SharerEngine<I, SS, IRR>(getIFactory(),
@@ -258,7 +256,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
engine.onMessageReceived(state, msg)); engine.onMessageReceived(state, msg));
} else { } else {
// we are an invitee and the sharer wants to leave or abort // we are an invitee and the sharer wants to leave or abort
@SuppressWarnings("unchecked")
IS state = (IS) s; IS state = (IS) s;
InviteeEngine<IS, IR> engine = InviteeEngine<IS, IR> engine =
new InviteeEngine<IS, IR>(getIRFactory(), clock); new InviteeEngine<IS, IR>(getIRFactory(), clock);
@@ -298,6 +295,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
processSharerStateUpdate(txn, null, update); processSharerStateUpdate(txn, null, update);
// track message // track message
// TODO handle this properly without engine hacks (#376)
long time = update.toSend.get(0).getTime(); long time = update.toSend.get(0).getTime();
trackMessage(txn, localState.getGroupId(), time, true); trackMessage(txn, localState.getGroupId(), time, true);
@@ -334,6 +332,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
processInviteeStateUpdate(txn, null, update); processInviteeStateUpdate(txn, null, update);
// track message // track message
// TODO handle this properly without engine hacks (#376)
long time = update.toSend.get(0).getTime(); long time = update.toSend.get(0).getTime();
trackMessage(txn, localState.getGroupId(), time, true); trackMessage(txn, localState.getGroupId(), time, true);
@@ -475,7 +474,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
BdfDictionary d = m.getValue(); BdfDictionary d = m.getValue();
try { try {
I msg = getIFactory().build(group.getId(), d); I msg = getIFactory().build(group.getId(), d);
@SuppressWarnings("unchecked")
IS iss = (IS) getSessionState(txn, msg.getSessionId(), true); IS iss = (IS) getSessionState(txn, msg.getSessionId(), true);
// get and add the shareable if the invitation is unanswered // get and add the shareable if the invitation is unanswered
if (iss.getState().equals(AWAIT_LOCAL_RESPONSE)) { if (iss.getState().equals(AWAIT_LOCAL_RESPONSE)) {
@@ -733,7 +731,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
if (!d.getBoolean(IS_SHARER)) throw new FormatException(); if (!d.getBoolean(IS_SHARER)) throw new FormatException();
//noinspection unchecked
return (SS) SharingSessionState return (SS) SharingSessionState
.fromBdfDictionary(getISFactory(), getSSFactory(), d); .fromBdfDictionary(getISFactory(), getSSFactory(), d);
} }
@@ -768,7 +765,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
} }
throw new DbException(); throw new DbException();
} }
//noinspection unchecked
return (IS) SharingSessionState return (IS) SharingSessionState
.fromBdfDictionary(getISFactory(), getSSFactory(), .fromBdfDictionary(getISFactory(), getSSFactory(),
map.values().iterator().next()); map.values().iterator().next());
@@ -954,7 +950,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
SharerEngine<I, SS, IRR> engine = SharerEngine<I, SS, IRR> engine =
new SharerEngine<I, SS, IRR>(getIFactory(), new SharerEngine<I, SS, IRR>(getIFactory(),
getIRRFactory(), clock); getIRRFactory(), clock);
//noinspection unchecked
processSharerStateUpdate(txn, null, processSharerStateUpdate(txn, null,
engine.onLocalAction((SS) state, action)); engine.onLocalAction((SS) state, action));
} else { } else {
@@ -962,7 +957,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
InviteeSessionState.Action.LOCAL_LEAVE; InviteeSessionState.Action.LOCAL_LEAVE;
InviteeEngine<IS, IR> engine = InviteeEngine<IS, IR> engine =
new InviteeEngine<IS, IR>(getIRFactory(), clock); new InviteeEngine<IS, IR>(getIRFactory(), clock);
//noinspection unchecked
processInviteeStateUpdate(txn, null, processInviteeStateUpdate(txn, null,
engine.onLocalAction((IS) state, action)); engine.onLocalAction((IS) state, action));
} }

View File

@@ -96,13 +96,13 @@ public class IntroductionManagerImplTest extends BriarTestCase {
TestUtils.getRandomBytes(MESSAGE_HEADER_LENGTH + 1) TestUtils.getRandomBytes(MESSAGE_HEADER_LENGTH + 1)
); );
metadataBefore = BdfDictionary.of( metadataBefore = BdfDictionary.of(
new BdfEntry(GROUP_KEY_MSG_COUNT, 41L), new BdfEntry(GROUP_KEY_MSG_COUNT, 41),
new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0L), new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0),
new BdfEntry(GROUP_KEY_LATEST_MSG, 0L) new BdfEntry(GROUP_KEY_LATEST_MSG, 0)
); );
metadataAfter = BdfDictionary.of( metadataAfter = BdfDictionary.of(
new BdfEntry(GROUP_KEY_MSG_COUNT, 42L), new BdfEntry(GROUP_KEY_MSG_COUNT, 42),
new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0L), new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0),
new BdfEntry(GROUP_KEY_LATEST_MSG, time) new BdfEntry(GROUP_KEY_LATEST_MSG, time)
); );
@@ -273,8 +273,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
final BdfDictionary state = new BdfDictionary(); final BdfDictionary state = new BdfDictionary();
txn = new Transaction(null, false); txn = new Transaction(null, false);
metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 1L); metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 1);
metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 2L); metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 2);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(introduceeManager) oneOf(introduceeManager)
@@ -314,8 +314,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
txn = new Transaction(null, false); txn = new Transaction(null, false);
metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 41L); metadataBefore.put(GROUP_KEY_UNREAD_COUNT, 41);
metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 42L); metadataAfter.put(GROUP_KEY_UNREAD_COUNT, 42);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, sessionId); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, sessionId);