mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Unify all private message responses in one PrivateResponse class
This also adds `Shareable`s to invitation response which is a precondition for #561
This commit is contained in:
@@ -25,7 +25,7 @@ import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||
import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent;
|
||||
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -107,8 +107,8 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||
BlogInvitationResponseReceivedEvent b =
|
||||
(BlogInvitationResponseReceivedEvent) e;
|
||||
InvitationResponse r = b.getResponse();
|
||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
||||
PrivateResponse<Blog> r = b.getResponse();
|
||||
if (r.getObject().getId().equals(groupId) && r.wasAccepted()) {
|
||||
LOG.info("Blog invitation accepted");
|
||||
onBlogInvitationAccepted(b.getContactId());
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ import org.briarproject.briar.api.introduction.event.IntroductionResponseReceive
|
||||
import org.briarproject.briar.api.messaging.ConversationManager;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
|
||||
|
||||
@@ -277,7 +277,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
LOG.info("Invitation response received, updating item");
|
||||
InvitationResponseReceivedEvent m =
|
||||
(InvitationResponseReceivedEvent) e;
|
||||
InvitationResponse ir = m.getResponse();
|
||||
PrivateResponse ir = m.getResponse();
|
||||
updateItem(m.getContactId(), ir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
|
||||
import org.thoughtcrime.securesms.components.util.FutureTaskListener;
|
||||
@@ -424,7 +424,7 @@ public class ConversationActivity extends BriarActivity
|
||||
item = ConversationItem
|
||||
.from(this, contactName, (PrivateRequest) i);
|
||||
} else {
|
||||
InvitationResponse r = (InvitationResponse) i;
|
||||
PrivateResponse r = (PrivateResponse) i;
|
||||
item = ConversationItem.from(this, contactName, r);
|
||||
}
|
||||
items.add(item);
|
||||
@@ -507,16 +507,16 @@ public class ConversationActivity extends BriarActivity
|
||||
(IntroductionRequestReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Introduction request received, adding...");
|
||||
IntroductionRequest ir = event.getIntroductionRequest();
|
||||
handleIntroductionRequest(ir);
|
||||
PrivateRequest ir = event.getIntroductionRequest();
|
||||
handlePrivateRequest(ir);
|
||||
}
|
||||
} else if (e instanceof IntroductionResponseReceivedEvent) {
|
||||
IntroductionResponseReceivedEvent event =
|
||||
(IntroductionResponseReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Introduction response received, adding...");
|
||||
IntroductionResponse ir = event.getIntroductionResponse();
|
||||
handleIntroductionResponse(ir);
|
||||
PrivateResponse ir = event.getIntroductionResponse();
|
||||
handlePrivateResponse(ir);
|
||||
}
|
||||
} else if (e instanceof InvitationRequestReceivedEvent) {
|
||||
InvitationRequestReceivedEvent event =
|
||||
@@ -524,15 +524,15 @@ public class ConversationActivity extends BriarActivity
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Invitation received, adding...");
|
||||
PrivateRequest ir = event.getRequest();
|
||||
handleInvitationRequest(ir);
|
||||
handlePrivateRequest(ir);
|
||||
}
|
||||
} else if (e instanceof InvitationResponseReceivedEvent) {
|
||||
InvitationResponseReceivedEvent event =
|
||||
(InvitationResponseReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Invitation response received, adding...");
|
||||
InvitationResponse ir = event.getResponse();
|
||||
handleInvitationResponse(ir);
|
||||
PrivateResponse ir = event.getResponse();
|
||||
handlePrivateResponse(ir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,7 +546,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void handleIntroductionRequest(IntroductionRequest m) {
|
||||
private void handlePrivateRequest(PrivateRequest m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
@@ -565,7 +565,7 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void handleIntroductionResponse(IntroductionResponse m) {
|
||||
private void handlePrivateResponse(PrivateResponse m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
@@ -584,46 +584,8 @@ public class ConversationActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void handleInvitationRequest(PrivateRequest m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
addConversationItem(item);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleInvitationResponse(InvitationResponse m) {
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
ConversationItem item = ConversationItem
|
||||
.from(ConversationActivity.this, contactName, m);
|
||||
addConversationItem(item);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable exception) {
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handleDbException((DbException) exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void markMessages(Collection<MessageId> messageIds,
|
||||
boolean sent, boolean seen) {
|
||||
private void markMessages(Collection<MessageId> messageIds, boolean sent,
|
||||
boolean seen) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
adapter.incrementRevision();
|
||||
Set<MessageId> messages = new HashSet<>(messageIds);
|
||||
|
||||
@@ -17,9 +17,9 @@ import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -87,46 +87,6 @@ abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
static ConversationItem from(Context ctx, String contactName,
|
||||
IntroductionResponse ir) {
|
||||
if (ir.isLocal()) {
|
||||
String text;
|
||||
if (ir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_accepted_sent,
|
||||
ir.getName());
|
||||
text += "\n\n" + ctx.getString(
|
||||
R.string.introduction_response_accepted_sent_info,
|
||||
ir.getName());
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_declined_sent,
|
||||
ir.getName());
|
||||
}
|
||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
||||
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
|
||||
} else {
|
||||
String text;
|
||||
if (ir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_accepted_received,
|
||||
contactName, ir.getName());
|
||||
} else {
|
||||
if (ir.isIntroducer()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_declined_received,
|
||||
contactName, ir.getName());
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_declined_received_by_introducee,
|
||||
contactName, ir.getName());
|
||||
}
|
||||
}
|
||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
||||
text, null, ir.getTimestamp(), ir.isRead());
|
||||
}
|
||||
}
|
||||
|
||||
static ConversationItem from(Context ctx, String contactName,
|
||||
PrivateRequest ir) {
|
||||
if (ir.isLocal()) {
|
||||
@@ -196,7 +156,44 @@ abstract class ConversationItem {
|
||||
}
|
||||
|
||||
static ConversationItem from(Context ctx, String contactName,
|
||||
InvitationResponse ir) {
|
||||
IntroductionResponse ir) {
|
||||
if (ir.isLocal()) {
|
||||
String text;
|
||||
if (ir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_accepted_sent,
|
||||
ir.getObject().getName());
|
||||
text += "\n\n" + ctx.getString(
|
||||
R.string.introduction_response_accepted_sent_info,
|
||||
ir.getObject().getName());
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_response_declined_sent,
|
||||
ir.getObject().getName());
|
||||
}
|
||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
||||
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
|
||||
} else {
|
||||
@StringRes int res;
|
||||
if (ir.wasAccepted()) {
|
||||
res = R.string.introduction_response_accepted_received;
|
||||
} else {
|
||||
if (ir.getObject().isIntroducer()) {
|
||||
res = R.string.introduction_response_declined_received;
|
||||
} else {
|
||||
res =
|
||||
R.string.introduction_response_declined_received_by_introducee;
|
||||
}
|
||||
}
|
||||
String text =
|
||||
ctx.getString(res, contactName, ir.getObject().getName());
|
||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
||||
text, null, ir.getTimestamp(), ir.isRead());
|
||||
}
|
||||
}
|
||||
|
||||
static ConversationItem from(Context ctx, String contactName,
|
||||
PrivateResponse ir) {
|
||||
@StringRes int res;
|
||||
if (ir.isLocal()) {
|
||||
if (ir.wasAccepted()) {
|
||||
@@ -208,7 +205,7 @@ abstract class ConversationItem {
|
||||
res = R.string.groups_invitations_response_accepted_sent;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown InvitationResponse");
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
} else {
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
@@ -219,7 +216,7 @@ abstract class ConversationItem {
|
||||
res = R.string.groups_invitations_response_declined_sent;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown InvitationResponse");
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
}
|
||||
String text = ctx.getString(res, contactName);
|
||||
@@ -235,7 +232,7 @@ abstract class ConversationItem {
|
||||
res = R.string.groups_invitations_response_accepted_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown InvitationResponse");
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
} else {
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
@@ -246,7 +243,7 @@ abstract class ConversationItem {
|
||||
res = R.string.groups_invitations_response_declined_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown InvitationResponse");
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
}
|
||||
String text = ctx.getString(res, contactName);
|
||||
@@ -261,14 +258,12 @@ abstract class ConversationItem {
|
||||
* PrivateMessageHeader.
|
||||
**/
|
||||
static ConversationItem from(Context ctx, PrivateMessageHeader h) {
|
||||
if(h instanceof IntroductionRequest) {
|
||||
return from(ctx, "", (IntroductionRequest) h);
|
||||
} else if(h instanceof IntroductionResponse) {
|
||||
if(h instanceof IntroductionResponse) {
|
||||
return from(ctx, "", (IntroductionResponse) h);
|
||||
} else if(h instanceof PrivateRequest) {
|
||||
return from(ctx, "", (PrivateRequest) h);
|
||||
} else if(h instanceof InvitationResponse) {
|
||||
return from(ctx, "", (InvitationResponse) h);
|
||||
} else if(h instanceof PrivateResponse) {
|
||||
return from(ctx, "", (PrivateResponse) h);
|
||||
} else {
|
||||
return from(h);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class ForumControllerImpl extends
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
ForumInvitationResponse r =
|
||||
(ForumInvitationResponse) f.getResponse();
|
||||
if (r.getShareableId().equals(getGroupId()) && r.wasAccepted()) {
|
||||
if (r.getObject().getId().equals(getGroupId()) && r.wasAccepted()) {
|
||||
LOG.info("Forum invitation was accepted");
|
||||
onForumInvitationAccepted(f.getContactId());
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ class GroupControllerImpl extends
|
||||
(GroupInvitationResponseReceivedEvent) e;
|
||||
GroupInvitationResponse r =
|
||||
(GroupInvitationResponse) g.getResponse();
|
||||
if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
|
||||
if (getGroupId().equals(r.getObject().getId()) && r.wasAccepted()) {
|
||||
listener.runOnUiThreadUnlessDestroyed(
|
||||
() -> listener.onInvitationAccepted(g.getContactId()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user