mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
make message status persistent and initialize it from database
This commit is contained in:
@@ -8,7 +8,6 @@ import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.HORIZONTAL;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
|
||||
@@ -45,6 +44,7 @@ import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.api.db.MessageHeader.State;
|
||||
import org.briarproject.api.db.NoSuchContactException;
|
||||
import org.briarproject.api.db.NoSuchMessageException;
|
||||
import org.briarproject.api.db.NoSuchSubscriptionException;
|
||||
@@ -77,7 +77,6 @@ import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ConversationActivity extends BriarActivity
|
||||
implements EventListener, OnClickListener, OnItemClickListener {
|
||||
@@ -389,18 +388,18 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
MessagesSentEvent m = (MessagesSentEvent) e;
|
||||
if (m.getContactId().equals(contactId)) {
|
||||
LOG.info("Messages sent");
|
||||
markMessages(m.getMessageIds(), ConversationItem.State.SENT);
|
||||
markMessages(m.getMessageIds(), State.SENT);
|
||||
}
|
||||
} else if (e instanceof MessagesAckedEvent) {
|
||||
MessagesAckedEvent m = (MessagesAckedEvent) e;
|
||||
if (m.getContactId().equals(contactId)) {
|
||||
LOG.info("Messages acked");
|
||||
markMessages(m.getMessageIds(), ConversationItem.State.DELIVERED);
|
||||
markMessages(m.getMessageIds(), State.DELIVERED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void markMessages(final Collection<MessageId> messageIds, final ConversationItem.State state) {
|
||||
private void markMessages(final Collection<MessageId> messageIds, final State state) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
Set<MessageId> messages = new HashSet<MessageId>(messageIds);
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.R;
|
||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.api.db.MessageHeader.State;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -81,9 +82,9 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
|
||||
ImageView status = new ImageView(ctx);
|
||||
status.setPadding(0, 0, pad, 0);
|
||||
if (item.getStatus() == ConversationItem.State.DELIVERED) {
|
||||
if (item.getStatus() == State.DELIVERED) {
|
||||
status.setImageResource(R.drawable.message_delivered);
|
||||
} else if (item.getStatus() == ConversationItem.State.SENT) {
|
||||
} else if (item.getStatus() == State.SENT) {
|
||||
status.setImageResource(R.drawable.message_sent);
|
||||
} else {
|
||||
status.setImageResource(R.drawable.message_stored);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.api.db.MessageHeader.State;
|
||||
|
||||
// This class is not thread-safe
|
||||
class ConversationItem {
|
||||
|
||||
public enum State { STORED, SENT, DELIVERED };
|
||||
|
||||
private final MessageHeader header;
|
||||
private byte[] body;
|
||||
private State status;
|
||||
@@ -14,7 +13,7 @@ class ConversationItem {
|
||||
ConversationItem(MessageHeader header) {
|
||||
this.header = header;
|
||||
body = null;
|
||||
status = header.isDelivered() ? State.DELIVERED : State.STORED;
|
||||
status = header.getStatus();
|
||||
}
|
||||
|
||||
MessageHeader getHeader() {
|
||||
|
||||
@@ -6,17 +6,20 @@ import org.briarproject.api.messaging.MessageId;
|
||||
|
||||
public class MessageHeader {
|
||||
|
||||
public enum State { STORED, SENT, DELIVERED };
|
||||
|
||||
private final MessageId id, parent;
|
||||
private final GroupId groupId;
|
||||
private final Author author;
|
||||
private final Author.Status authorStatus;
|
||||
private final String contentType;
|
||||
private final long timestamp;
|
||||
private final boolean local, read, delivered;
|
||||
private final boolean local, read;
|
||||
private final State status;
|
||||
|
||||
public MessageHeader(MessageId id, MessageId parent, GroupId groupId,
|
||||
Author author, Author.Status authorStatus, String contentType,
|
||||
long timestamp, boolean local, boolean read, boolean delivered) {
|
||||
long timestamp, boolean local, boolean read, State status) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
this.groupId = groupId;
|
||||
@@ -26,7 +29,7 @@ public class MessageHeader {
|
||||
this.timestamp = timestamp;
|
||||
this.local = local;
|
||||
this.read = read;
|
||||
this.delivered = delivered;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/** Returns the message's unique identifier. */
|
||||
@@ -82,10 +85,9 @@ public class MessageHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the message has been delivered. (This only applies to
|
||||
* locally generated private messages.)
|
||||
* Returns message status. (This only applies to locally generated private messages.)
|
||||
*/
|
||||
public boolean isDelivered() {
|
||||
return delivered;
|
||||
public State getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ import org.briarproject.api.messaging.MessageId;
|
||||
public class MessagesSentEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final Collection<MessageId> acked;
|
||||
private final Collection<MessageId> messageIds;
|
||||
|
||||
public MessagesSentEvent(ContactId contactId,
|
||||
Collection<MessageId> acked) {
|
||||
Collection<MessageId> messageIds) {
|
||||
this.contactId = contactId;
|
||||
this.acked = acked;
|
||||
this.messageIds = messageIds;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
@@ -22,6 +22,6 @@ public class MessagesSentEvent extends Event {
|
||||
}
|
||||
|
||||
public Collection<MessageId> getMessageIds() {
|
||||
return acked;
|
||||
return messageIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.db.DbClosedException;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.api.db.MessageHeader.State;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupId;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
@@ -1452,7 +1453,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
if (rs.next()) throw new DbException();
|
||||
// Get the message headers
|
||||
sql = "SELECT m.messageId, parentId, m.groupId, contentType,"
|
||||
+ " timestamp, local, read, seen"
|
||||
+ " timestamp, local, read, seen, s.txCount"
|
||||
+ " FROM messages AS m"
|
||||
+ " JOIN groups AS g"
|
||||
+ " ON m.groupId = g.groupId"
|
||||
@@ -1478,8 +1479,15 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
boolean read = rs.getBoolean(7);
|
||||
boolean seen = rs.getBoolean(8);
|
||||
Author author = local ? localAuthor : remoteAuthor;
|
||||
|
||||
// initialize message status
|
||||
State status;
|
||||
if (seen) status = State.DELIVERED;
|
||||
else if (rs.getInt(9) > 0) status = State.SENT;
|
||||
else status = State.STORED;
|
||||
|
||||
headers.add(new MessageHeader(id, parent, groupId, author,
|
||||
VERIFIED, contentType, timestamp, local, read, seen));
|
||||
VERIFIED, contentType, timestamp, local, read, status));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1631,6 +1639,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get group messages.
|
||||
* The message status won't be used.
|
||||
*/
|
||||
public Collection<MessageHeader> getMessageHeaders(Connection txn,
|
||||
GroupId g) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
@@ -1669,12 +1681,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
boolean read = rs.getBoolean(9);
|
||||
boolean isSelf = rs.getBoolean(10);
|
||||
boolean isContact = rs.getBoolean(11);
|
||||
|
||||
Author.Status status;
|
||||
if (author == null) status = ANONYMOUS;
|
||||
else if (isSelf || isContact) status = VERIFIED;
|
||||
else status = UNKNOWN;
|
||||
|
||||
headers.add(new MessageHeader(id, parent, g, author, status,
|
||||
contentType, timestamp, local, read, false));
|
||||
contentType, timestamp, local, read, State.STORED));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
Reference in New Issue
Block a user