mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use ConversationManager to retrieve messages
This removes the public method for retrieving messages from individual conversation clients and just leaves methods that require a transaction to be used by the ConversationManager only.
This commit is contained in:
@@ -62,8 +62,8 @@ import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||
@@ -159,6 +159,8 @@ public class ConversationActivity extends BriarActivity
|
||||
@Inject
|
||||
volatile MessagingManager messagingManager;
|
||||
@Inject
|
||||
volatile ConversationManager conversationManager;
|
||||
@Inject
|
||||
volatile EventBus eventBus;
|
||||
@Inject
|
||||
volatile SettingsManager settingsManager;
|
||||
@@ -337,23 +339,9 @@ public class ConversationActivity extends BriarActivity
|
||||
try {
|
||||
long start = now();
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> introductions =
|
||||
introductionManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> forumInvitations =
|
||||
forumSharingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> blogInvitations =
|
||||
blogSharingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> groupInvitations =
|
||||
groupInvitationManager.getMessages(contactId);
|
||||
List<PrivateMessageHeader> invitations = new ArrayList<>(
|
||||
forumInvitations.size() + blogInvitations.size() +
|
||||
groupInvitations.size());
|
||||
invitations.addAll(forumInvitations);
|
||||
invitations.addAll(blogInvitations);
|
||||
invitations.addAll(groupInvitations);
|
||||
conversationManager.getMessageHeaders(contactId);
|
||||
logDuration(LOG, "Loading messages", start);
|
||||
displayMessages(revision, headers, introductions, invitations);
|
||||
displayMessages(revision, headers);
|
||||
} catch (NoSuchContactException e) {
|
||||
finishOnUiThread();
|
||||
} catch (DbException e) {
|
||||
@@ -363,15 +351,12 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void displayMessages(int revision,
|
||||
Collection<PrivateMessageHeader> headers,
|
||||
Collection<PrivateMessageHeader> introductions,
|
||||
Collection<PrivateMessageHeader> invitations) {
|
||||
Collection<PrivateMessageHeader> headers) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
textInputView.setSendButtonEnabled(true);
|
||||
List<ConversationItem> items = createItems(headers,
|
||||
introductions, invitations);
|
||||
List<ConversationItem> items = createItems(headers);
|
||||
adapter.addAll(items);
|
||||
list.showData();
|
||||
// Scroll to the bottom
|
||||
@@ -390,38 +375,24 @@ public class ConversationActivity extends BriarActivity
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private List<ConversationItem> createItems(
|
||||
Collection<PrivateMessageHeader> headers,
|
||||
Collection<PrivateMessageHeader> introductions,
|
||||
Collection<PrivateMessageHeader> invitations) {
|
||||
int size =
|
||||
headers.size() + introductions.size() + invitations.size();
|
||||
List<ConversationItem> items = new ArrayList<>(size);
|
||||
Collection<PrivateMessageHeader> headers) {
|
||||
List<ConversationItem> items = new ArrayList<>(headers.size());
|
||||
for (PrivateMessageHeader h : headers) {
|
||||
ConversationItem item = ConversationItem.from(h);
|
||||
String body = bodyCache.get(h.getId());
|
||||
if (body == null) loadMessageBody(h.getId());
|
||||
else item.setBody(body);
|
||||
items.add(item);
|
||||
}
|
||||
for (PrivateMessageHeader m : introductions) {
|
||||
ConversationItem item;
|
||||
if (m instanceof IntroductionRequest) {
|
||||
IntroductionRequest i = (IntroductionRequest) m;
|
||||
if (h instanceof IntroductionResponse) {
|
||||
IntroductionResponse i = (IntroductionResponse) h;
|
||||
item = ConversationItem.from(this, contactName, i);
|
||||
} else {
|
||||
IntroductionResponse i = (IntroductionResponse) m;
|
||||
item = ConversationItem.from(this, contactName, i);
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
for (PrivateMessageHeader i : invitations) {
|
||||
ConversationItem item;
|
||||
if (i instanceof PrivateRequest) {
|
||||
item = ConversationItem
|
||||
.from(this, contactName, (PrivateRequest) i);
|
||||
} else {
|
||||
PrivateResponse r = (PrivateResponse) i;
|
||||
} else if (h instanceof PrivateRequest) {
|
||||
PrivateRequest r = (PrivateRequest) h;
|
||||
item = ConversationItem.from(this, contactName, r);
|
||||
} else if (h instanceof PrivateResponse) {
|
||||
PrivateResponse r = (PrivateResponse) h;
|
||||
item = ConversationItem.from(this, contactName, r);
|
||||
} else {
|
||||
item = ConversationItem.from(h);
|
||||
String body = bodyCache.get(h.getId());
|
||||
if (body == null) loadMessageBody(h.getId());
|
||||
else item.setBody(body);
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
@@ -513,9 +484,9 @@ public class ConversationActivity extends BriarActivity
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
handlePrivateRequestAndResponse(h, contactName);
|
||||
});
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handlePrivateRequestAndResponse(h,
|
||||
contactName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,8 @@ import static org.briarproject.briar.android.contact.ConversationRequestItem.Req
|
||||
@NotNullByDefault
|
||||
abstract class ConversationItem {
|
||||
|
||||
protected @Nullable String body;
|
||||
@Nullable
|
||||
protected String body;
|
||||
private final MessageId id;
|
||||
private final GroupId groupId;
|
||||
private final long time;
|
||||
@@ -105,7 +106,7 @@ abstract class ConversationItem {
|
||||
R.string.groups_invitations_invitation_sent,
|
||||
contactName, ir.getName());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown InvitationRequest");
|
||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||
}
|
||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
||||
text, ir.getMessage(), ir.getTimestamp(), ir.isSent(),
|
||||
@@ -145,7 +146,7 @@ abstract class ConversationItem {
|
||||
contactName, ir.getName());
|
||||
type = GROUP;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown InvitationRequest");
|
||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||
}
|
||||
return new ConversationRequestItem(ir.getId(),
|
||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
||||
@@ -229,22 +230,24 @@ abstract class ConversationItem {
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_accepted_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res = R.string.groups_invitations_response_accepted_received;
|
||||
res =
|
||||
R.string.groups_invitations_response_accepted_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
} else {
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
res = R.string.forum_invitation_response_declined_received;
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_declined_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res = R.string.groups_invitations_response_declined_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
res = R.string.forum_invitation_response_declined_received;
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_declined_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res =
|
||||
R.string.groups_invitations_response_declined_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
}
|
||||
String text = ctx.getString(res, contactName);
|
||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
||||
@@ -258,11 +261,11 @@ abstract class ConversationItem {
|
||||
* PrivateMessageHeader.
|
||||
**/
|
||||
static ConversationItem from(Context ctx, PrivateMessageHeader h) {
|
||||
if(h instanceof IntroductionResponse) {
|
||||
if (h instanceof IntroductionResponse) {
|
||||
return from(ctx, "", (IntroductionResponse) h);
|
||||
} else if(h instanceof PrivateRequest) {
|
||||
} else if (h instanceof PrivateRequest) {
|
||||
return from(ctx, "", (PrivateRequest) h);
|
||||
} else if(h instanceof PrivateResponse) {
|
||||
} else if (h instanceof PrivateResponse) {
|
||||
return from(ctx, "", (PrivateResponse) h);
|
||||
} else {
|
||||
return from(h);
|
||||
|
||||
Reference in New Issue
Block a user