mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Refactor SharingManager so its events provide message header
This commit is contained in:
@@ -13,6 +13,7 @@ import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
|
||||
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
|
||||
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
|
||||
public interface BlogSharingMessage {
|
||||
|
||||
@@ -25,9 +26,9 @@ public interface BlogSharingMessage {
|
||||
|
||||
public BlogInvitation(GroupId groupId, SessionId sessionId,
|
||||
String blogTitle, String blogDesc, String blogAuthorName,
|
||||
byte[] blogPublicKey, String message) {
|
||||
byte[] blogPublicKey, long time, String message) {
|
||||
|
||||
super(groupId, sessionId, message);
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
this.blogTitle = blogTitle;
|
||||
this.blogDesc = blogDesc;
|
||||
@@ -65,9 +66,10 @@ public interface BlogSharingMessage {
|
||||
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
|
||||
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
|
||||
String message = d.getOptionalString(INVITATION_MSG);
|
||||
long time = d.getLong(TIME);
|
||||
|
||||
return new BlogInvitation(groupId, sessionId, blogTitle,
|
||||
blogDesc, blogAuthorName, blogPublicKey, message);
|
||||
blogDesc, blogAuthorName, blogPublicKey, time, message);
|
||||
}
|
||||
|
||||
public String getBlogTitle() {
|
||||
|
||||
@@ -2,13 +2,15 @@ package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.blogs.Blog;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
|
||||
public class BlogInvitationReceivedEvent extends InvitationReceivedEvent {
|
||||
|
||||
private final Blog blog;
|
||||
|
||||
public BlogInvitationReceivedEvent(Blog blog, ContactId contactId) {
|
||||
super(contactId);
|
||||
public BlogInvitationReceivedEvent(Blog blog, ContactId contactId,
|
||||
InvitationRequest request) {
|
||||
super(contactId, request);
|
||||
this.blog = blog;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.blogs.BlogInvitationResponse;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
|
||||
public class BlogInvitationResponseReceivedEvent extends InvitationResponseReceivedEvent {
|
||||
@@ -7,8 +8,8 @@ public class BlogInvitationResponseReceivedEvent extends InvitationResponseRecei
|
||||
private final String blogTitle;
|
||||
|
||||
public BlogInvitationResponseReceivedEvent(String blogTitle,
|
||||
ContactId contactId) {
|
||||
super(contactId);
|
||||
ContactId contactId, BlogInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
this.blogTitle = blogTitle;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,20 @@ package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
public class ForumInvitationReceivedEvent extends InvitationReceivedEvent {
|
||||
|
||||
private final Forum forum;
|
||||
|
||||
public ForumInvitationReceivedEvent(Forum forum, ContactId contactId) {
|
||||
super(contactId);
|
||||
public ForumInvitationReceivedEvent(Forum forum, ContactId contactId,
|
||||
ForumInvitationRequest request) {
|
||||
super(contactId, request);
|
||||
this.forum = forum;
|
||||
}
|
||||
|
||||
public Forum getForum() {
|
||||
return forum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
|
||||
public class ForumInvitationResponseReceivedEvent extends InvitationResponseReceivedEvent {
|
||||
|
||||
private final String forumName;
|
||||
|
||||
public ForumInvitationResponseReceivedEvent(String forumName,
|
||||
ContactId contactId) {
|
||||
super(contactId);
|
||||
ContactId contactId, ForumInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
this.forumName = forumName;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
|
||||
public abstract class InvitationReceivedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final InvitationRequest request;
|
||||
|
||||
InvitationReceivedEvent(ContactId contactId) {
|
||||
InvitationReceivedEvent(ContactId contactId, InvitationRequest request) {
|
||||
this.contactId = contactId;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public InvitationRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
|
||||
public abstract class InvitationResponseReceivedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final InvitationResponse response;
|
||||
|
||||
public InvitationResponseReceivedEvent(ContactId contactId) {
|
||||
public InvitationResponseReceivedEvent(ContactId contactId,
|
||||
InvitationResponse response) {
|
||||
this.contactId = contactId;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public InvitationResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForumInvitationRequest extends InvitationRequest {
|
||||
|
||||
private final String forumName;
|
||||
|
||||
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
||||
public ForumInvitationRequest(@Nullable MessageId id, SessionId sessionId,
|
||||
ContactId contactId, String forumName, String message,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
@@ -4,10 +4,11 @@ import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForumInvitationResponse extends InvitationResponse {
|
||||
|
||||
public ForumInvitationResponse(MessageId id, SessionId sessionId,
|
||||
public ForumInvitationResponse(@Nullable MessageId id, SessionId sessionId,
|
||||
ContactId contactId, boolean accept, long time, boolean local,
|
||||
boolean sent, boolean seen, boolean read) {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
|
||||
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
|
||||
public interface ForumSharingMessage {
|
||||
|
||||
@@ -20,9 +21,9 @@ public interface ForumSharingMessage {
|
||||
private final byte[] forumSalt;
|
||||
|
||||
public ForumInvitation(GroupId groupId, SessionId sessionId,
|
||||
String forumName, byte[] forumSalt, String message) {
|
||||
String forumName, byte[] forumSalt, long time, String message) {
|
||||
|
||||
super(groupId, sessionId, message);
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
this.forumName = forumName;
|
||||
this.forumSalt = forumSalt;
|
||||
@@ -53,9 +54,10 @@ public interface ForumSharingMessage {
|
||||
String forumName = d.getString(FORUM_NAME);
|
||||
byte[] forumSalt = d.getRaw(FORUM_SALT);
|
||||
String message = d.getOptionalString(INVITATION_MSG);
|
||||
long time = d.getLong(TIME);
|
||||
|
||||
return new ForumInvitation(groupId, sessionId, forumName, forumSalt,
|
||||
message);
|
||||
time, message);
|
||||
}
|
||||
|
||||
public String getForumName() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.api.sharing;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class InvitationRequest extends InvitationMessage {
|
||||
|
||||
@@ -19,6 +20,7 @@ public abstract class InvitationRequest extends InvitationMessage {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public interface SharingConstants {
|
||||
String IS_SHARER = "isSharer";
|
||||
String SHAREABLE_ID = "shareableId";
|
||||
String INVITATION_MSG = "invitationMsg";
|
||||
String INVITATION_ID = "invitationId";
|
||||
String RESPONSE_ID = "responseId";
|
||||
int SHARE_MSG_TYPE_INVITATION = 1;
|
||||
int SHARE_MSG_TYPE_ACCEPT = 2;
|
||||
int SHARE_MSG_TYPE_DECLINE = 3;
|
||||
|
||||
@@ -14,6 +14,7 @@ import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ACCEP
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_DECLINE;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_LEAVE;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TYPE;
|
||||
|
||||
public interface SharingMessage {
|
||||
@@ -21,10 +22,12 @@ public interface SharingMessage {
|
||||
abstract class BaseMessage {
|
||||
private final GroupId groupId;
|
||||
private final SessionId sessionId;
|
||||
private final long time;
|
||||
|
||||
BaseMessage(GroupId groupId, SessionId sessionId) {
|
||||
BaseMessage(GroupId groupId, SessionId sessionId, long time) {
|
||||
this.groupId = groupId;
|
||||
this.sessionId = sessionId;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public BdfList toBdfList() {
|
||||
@@ -62,16 +65,20 @@ public interface SharingMessage {
|
||||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Invitation extends BaseMessage {
|
||||
|
||||
protected final String message;
|
||||
|
||||
public Invitation(GroupId groupId, SessionId sessionId,
|
||||
public Invitation(GroupId groupId, SessionId sessionId, long time,
|
||||
String message) {
|
||||
|
||||
super(groupId, sessionId);
|
||||
super(groupId, sessionId, time);
|
||||
|
||||
this.message = message;
|
||||
}
|
||||
@@ -90,8 +97,9 @@ public interface SharingMessage {
|
||||
|
||||
private final long type;
|
||||
|
||||
public SimpleMessage(long type, GroupId groupId, SessionId sessionId) {
|
||||
super(groupId, sessionId);
|
||||
public SimpleMessage(long type, GroupId groupId, SessionId sessionId,
|
||||
long time) {
|
||||
super(groupId, sessionId, time);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -114,7 +122,8 @@ public interface SharingMessage {
|
||||
type != SHARE_MSG_TYPE_ABORT) throw new FormatException();
|
||||
|
||||
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
|
||||
return new SimpleMessage(type, groupId, sessionId);
|
||||
long time = d.getLong(TIME);
|
||||
return new SimpleMessage(type, groupId, sessionId, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user