Removed extraneous information from DB events.

This commit is contained in:
akwizgran
2013-03-18 22:10:16 +00:00
parent 935b82a8f4
commit b280e4cbcd
3 changed files with 15 additions and 20 deletions

View File

@@ -1,20 +1,20 @@
package net.sf.briar.api.db.event; package net.sf.briar.api.db.event;
import net.sf.briar.api.messaging.Message; import net.sf.briar.api.messaging.GroupId;
/** An event that is broadcast when a group message is added to the database. */ /** An event that is broadcast when a group message is added to the database. */
public class GroupMessageAddedEvent extends DatabaseEvent { public class GroupMessageAddedEvent extends DatabaseEvent {
private final Message message; private final GroupId groupId;
private final boolean incoming; private final boolean incoming;
public GroupMessageAddedEvent(Message message, boolean incoming) { public GroupMessageAddedEvent(GroupId groupId, boolean incoming) {
this.message = message; this.groupId = groupId;
this.incoming = incoming; this.incoming = incoming;
} }
public Message getMessage() { public GroupId getGroupId() {
return message; return groupId;
} }
public boolean isIncoming() { public boolean isIncoming() {

View File

@@ -1,28 +1,20 @@
package net.sf.briar.api.db.event; package net.sf.briar.api.db.event;
import net.sf.briar.api.ContactId; 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. * An event that is broadcast when a private message is added to the database.
*/ */
public class PrivateMessageAddedEvent extends DatabaseEvent { public class PrivateMessageAddedEvent extends DatabaseEvent {
private final Message message;
private final ContactId contactId; private final ContactId contactId;
private final boolean incoming; private final boolean incoming;
public PrivateMessageAddedEvent(Message message, ContactId contactId, public PrivateMessageAddedEvent(ContactId contactId, boolean incoming) {
boolean incoming) {
this.message = message;
this.contactId = contactId; this.contactId = contactId;
this.incoming = incoming; this.incoming = incoming;
} }
public Message getMessage() {
return message;
}
public ContactId getContactId() { public ContactId getContactId() {
return contactId; return contactId;
} }

View File

@@ -287,7 +287,10 @@ DatabaseCleaner.Callback {
} finally { } finally {
contactLock.readLock().unlock(); contactLock.readLock().unlock();
} }
if(added) callListeners(new GroupMessageAddedEvent(m, false)); if(added) {
GroupId g = m.getGroup().getId();
callListeners(new GroupMessageAddedEvent(g, false));
}
} }
/** /**
@@ -400,7 +403,7 @@ DatabaseCleaner.Callback {
} finally { } finally {
contactLock.readLock().unlock(); contactLock.readLock().unlock();
} }
if(added) callListeners(new PrivateMessageAddedEvent(m, c, false)); if(added) callListeners(new PrivateMessageAddedEvent(c, false));
} }
public void addSecrets(Collection<TemporarySecret> secrets) public void addSecrets(Collection<TemporarySecret> secrets)
@@ -1352,9 +1355,9 @@ DatabaseCleaner.Callback {
} }
callListeners(new MessageReceivedEvent(c)); callListeners(new MessageReceivedEvent(c));
if(added) { if(added) {
if(m.getGroup() == null) Group g = m.getGroup();
callListeners(new PrivateMessageAddedEvent(m, c, true)); if(g == null) callListeners(new PrivateMessageAddedEvent(c, true));
else callListeners(new GroupMessageAddedEvent(m, true)); else callListeners(new GroupMessageAddedEvent(g.getId(), true));
} }
} }