mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Attached data to DB events to avoid DB lookups; refactored UI code.
Fields in Android UI objects that are accessed from background threads must be declared volatile. UI objects use data attached to DB events to avoid DB lookups, which complicates the UI code but should improve performance.
This commit is contained in:
@@ -157,9 +157,15 @@ public interface DatabaseComponent {
|
||||
/** Returns the configuration for the given transport. */
|
||||
TransportConfig getConfig(TransportId t) throws DbException;
|
||||
|
||||
/** Returns the contact with the given ID. */
|
||||
Contact getContact(ContactId c) throws DbException;
|
||||
|
||||
/** Returns all contacts. */
|
||||
Collection<Contact> getContacts() throws DbException;
|
||||
|
||||
/** Returns the group with the given ID, if the user subscribes to it. */
|
||||
Group getGroup(GroupId g) throws DbException;
|
||||
|
||||
/** Returns the local transport properties for the given transport. */
|
||||
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
||||
|
||||
|
||||
@@ -1,20 +1,31 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
|
||||
public class GroupMessageHeader extends MessageHeader {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final Author author;
|
||||
private final Rating rating;
|
||||
|
||||
public GroupMessageHeader(MessageId id, MessageId parent,
|
||||
String contentType, String subject, long timestamp, boolean read,
|
||||
boolean starred, GroupId groupId, Author author) {
|
||||
boolean starred, GroupId groupId, Author author, Rating rating) {
|
||||
super(id, parent, contentType, subject, timestamp, read, starred);
|
||||
this.groupId = groupId;
|
||||
this.author = author;
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public GroupMessageHeader(Message m, boolean read, boolean starred,
|
||||
Rating rating) {
|
||||
this(m.getId(), m.getParent(), m.getContentType(), m.getSubject(),
|
||||
m.getTimestamp(), read, starred, m.getGroup().getId(),
|
||||
m.getAuthor(), rating);
|
||||
}
|
||||
|
||||
/** Returns the ID of the group to which the message belongs. */
|
||||
@@ -28,4 +39,12 @@ public class GroupMessageHeader extends MessageHeader {
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rating for the message's author, or Rating.UNRATED if this
|
||||
* is an anonymous message.
|
||||
*/
|
||||
public Rating getRating() {
|
||||
return rating;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
|
||||
public class PrivateMessageHeader extends MessageHeader {
|
||||
@@ -16,6 +17,12 @@ public class PrivateMessageHeader extends MessageHeader {
|
||||
this.incoming = incoming;
|
||||
}
|
||||
|
||||
public PrivateMessageHeader(Message m, boolean read, boolean starred,
|
||||
ContactId contactId, boolean incoming) {
|
||||
this(m.getId(), m.getParent(), m.getContentType(), m.getSubject(),
|
||||
m.getTimestamp(), read, starred, contactId, incoming);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the contact who is the sender (if incoming) or
|
||||
* recipient (if outgoing) of this message.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
|
||||
/** An event that is broadcast when a group message is added to the database. */
|
||||
public class GroupMessageAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final Message message;
|
||||
private final boolean incoming;
|
||||
|
||||
public GroupMessageAddedEvent(Message message, boolean incoming) {
|
||||
this.message = message;
|
||||
this.incoming = incoming;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isIncoming() {
|
||||
return incoming;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when one or more messages are added to the
|
||||
* database.
|
||||
*/
|
||||
public class MessageAddedEvent extends DatabaseEvent {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
|
||||
/** An event that is broadcast when a message is received. */
|
||||
public class MessageReceivedEvent extends DatabaseEvent {
|
||||
|
||||
private final ContactId contactId;
|
||||
|
||||
public MessageReceivedEvent(ContactId contactId) {
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a private message is added to the database.
|
||||
*/
|
||||
public class PrivateMessageAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final Message message;
|
||||
private final ContactId contactId;
|
||||
private final boolean incoming;
|
||||
|
||||
public PrivateMessageAddedEvent(Message message, ContactId contactId,
|
||||
boolean incoming) {
|
||||
this.message = message;
|
||||
this.contactId = contactId;
|
||||
this.incoming = incoming;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public boolean isIncoming() {
|
||||
return incoming;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
|
||||
/** An event that is broadcast when the user subscribes to a group. */
|
||||
public class SubscriptionAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final Group group;
|
||||
|
||||
public SubscriptionAddedEvent(GroupId groupId) {
|
||||
this.groupId = groupId;
|
||||
public SubscriptionAddedEvent(Group group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user