Facades for private messaging. #173

This commit is contained in:
akwizgran
2015-12-17 15:29:20 +00:00
parent 4450ab171a
commit 87689855da
10 changed files with 144 additions and 62 deletions

View File

@@ -142,9 +142,9 @@ EventListener {
try {
ContactId id = c.getId();
GroupId inbox =
messagingManager.getInboxGroupId(id);
messagingManager.getConversationId(id);
Collection<MessageHeader> headers =
messagingManager.getInboxMessageHeaders(id);
messagingManager.getMessageHeaders(id);
displayContact(c, inbox, headers);
} catch (NoSuchContactException e) {
// Continue
@@ -294,7 +294,7 @@ EventListener {
try {
long now = System.currentTimeMillis();
Collection<MessageHeader> headers =
messagingManager.getInboxMessageHeaders(c);
messagingManager.getMessageHeaders(c);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Partial load took " + duration + " ms");

View File

@@ -39,11 +39,11 @@ import org.briarproject.api.event.MessagesAckedEvent;
import org.briarproject.api.event.MessagesSentEvent;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateConversation;
import org.briarproject.api.messaging.PrivateMessageFactory;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.sync.MessageHeader.State;
import org.briarproject.api.sync.MessageId;
@@ -93,11 +93,11 @@ implements EventListener, OnClickListener, OnItemClickListener {
@Inject private volatile ContactManager contactManager;
@Inject private volatile MessagingManager messagingManager;
@Inject private volatile EventBus eventBus;
@Inject private volatile MessageFactory messageFactory;
@Inject private volatile PrivateMessageFactory privateMessageFactory;
private volatile ContactId contactId = null;
private volatile String contactName = null;
private volatile GroupId groupId = null;
private volatile Group group = null;
private volatile PrivateConversation conversation = null;
private volatile AuthorId localAuthorId = null;
private volatile boolean connected;
@@ -147,7 +147,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
content = (EditText) findViewById(R.id.contentView);
sendButton = (ImageButton) findViewById(R.id.sendButton);
sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setEnabled(false); // Enabled after loading the conversation
sendButton.setOnClickListener(this);
}
@@ -167,12 +167,12 @@ implements EventListener, OnClickListener, OnItemClickListener {
Contact contact = contactManager.getContact(contactId);
contactName = contact.getAuthor().getName();
localAuthorId = contact.getLocalAuthorId();
groupId = messagingManager.getInboxGroupId(contactId);
group = messagingManager.getGroup(groupId);
groupId = messagingManager.getConversationId(contactId);
conversation = messagingManager.getConversation(groupId);
connected = connectionRegistry.isConnected(contactId);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) {
LOG.info("Loading contact and group took "
LOG.info("Loading contact and conversation took "
+ duration + " ms");
}
displayContactDetails();
@@ -210,7 +210,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
try {
long now = System.currentTimeMillis();
Collection<MessageHeader> headers =
messagingManager.getInboxMessageHeaders(contactId);
messagingManager.getMessageHeaders(contactId);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading headers took " + duration + " ms");
@@ -424,8 +424,8 @@ implements EventListener, OnClickListener, OnItemClickListener {
cryptoExecutor.execute(new Runnable() {
public void run() {
try {
Message m = messageFactory.createAnonymousMessage(null,
group, "text/plain", timestamp, body);
Message m = privateMessageFactory.createPrivateMessage(null,
conversation, "text/plain", timestamp, body);
storeMessage(m);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);

View File

@@ -24,10 +24,10 @@ import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.PrivateConversation;
import org.briarproject.api.messaging.PrivateMessageFactory;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils;
@@ -65,21 +65,20 @@ implements OnClickListener {
// Fields that are accessed from background threads must be volatile
@Inject private volatile IdentityManager identityManager;
@Inject private volatile MessagingManager messagingManager;
@Inject private volatile MessageFactory messageFactory;
private volatile String contactName = null;
@Inject private volatile PrivateMessageFactory privateMessageFactory;
private volatile GroupId groupId = null;
private volatile AuthorId localAuthorId = null;
private volatile MessageId parentId = null;
private volatile long minTimestamp = -1;
private volatile LocalAuthor localAuthor = null;
private volatile Group group = null;
private volatile PrivateConversation conversation = null;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
Intent i = getIntent();
contactName = i.getStringExtra("briar.CONTACT_NAME");
String contactName = i.getStringExtra("briar.CONTACT_NAME");
if (contactName == null) throw new IllegalStateException();
setTitle(contactName);
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
@@ -118,7 +117,7 @@ implements OnClickListener {
sendButton.setId(2);
sendButton.setBackgroundResource(0);
sendButton.setImageResource(R.drawable.social_send_now);
sendButton.setEnabled(false); // Enabled after loading the group
sendButton.setEnabled(false); // Enabled after loading the conversation
sendButton.setOnClickListener(this);
RelativeLayout.LayoutParams right = CommonLayoutParams.relative();
right.addRule(ALIGN_PARENT_RIGHT);
@@ -140,16 +139,17 @@ implements OnClickListener {
@Override
public void onResume() {
super.onResume();
if (localAuthor == null || group == null) loadAuthorAndGroup();
if (localAuthor == null || conversation == null)
loadAuthorAndConversation();
}
private void loadAuthorAndGroup() {
private void loadAuthorAndConversation() {
runOnDbThread(new Runnable() {
public void run() {
try {
long now = System.currentTimeMillis();
localAuthor = identityManager.getLocalAuthor(localAuthorId);
group = messagingManager.getGroup(groupId);
conversation = messagingManager.getConversation(groupId);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Load took " + duration + " ms");
@@ -192,8 +192,9 @@ implements OnClickListener {
long timestamp = System.currentTimeMillis();
timestamp = Math.max(timestamp, minTimestamp);
try {
Message m = messageFactory.createAnonymousMessage(parentId,
group, "text/plain", timestamp, body);
Message m = privateMessageFactory.createPrivateMessage(
parentId, conversation, "text/plain", timestamp,
body);
storeMessage(m);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);