From 8a20f330beb22dcd2b5705684ec6b45b8ffab8d6 Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Fri, 19 Feb 2016 12:10:44 +0000
Subject: [PATCH] Broadcast status event when active contact is added.

---
 .../src/org/briarproject/db/DatabaseComponentImpl.java       | 1 +
 .../src/org/briarproject/db/DatabaseComponentImplTest.java   | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
index 0980962b06..a912407513 100644
--- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
+++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java
@@ -145,6 +145,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
 			throw new ContactExistsException();
 		ContactId c = db.addContact(txn, remote, local, active);
 		transaction.attach(new ContactAddedEvent(c));
+		if (active) transaction.attach(new ContactStatusChangedEvent(c, true));
 		return c;
 	}
 
diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java
index 17c27f9541..4049a4091d 100644
--- a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java
+++ b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java
@@ -16,6 +16,7 @@ import org.briarproject.api.db.NoSuchTransportException;
 import org.briarproject.api.db.Transaction;
 import org.briarproject.api.event.ContactAddedEvent;
 import org.briarproject.api.event.ContactRemovedEvent;
+import org.briarproject.api.event.ContactStatusChangedEvent;
 import org.briarproject.api.event.EventBus;
 import org.briarproject.api.event.GroupAddedEvent;
 import org.briarproject.api.event.GroupRemovedEvent;
@@ -146,6 +147,8 @@ public class DatabaseComponentImplTest extends BriarTestCase {
 			oneOf(database).addContact(txn, author, localAuthorId, true);
 			will(returnValue(contactId));
 			oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
+			oneOf(eventBus).broadcast(with(any(
+					ContactStatusChangedEvent.class)));
 			// getContacts()
 			oneOf(database).getContacts(txn);
 			will(returnValue(Collections.singletonList(contact)));
@@ -768,6 +771,8 @@ public class DatabaseComponentImplTest extends BriarTestCase {
 			oneOf(database).addContact(txn, author, localAuthorId, true);
 			will(returnValue(contactId));
 			oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
+			oneOf(eventBus).broadcast(with(any(
+					ContactStatusChangedEvent.class)));
 			// endTransaction()
 			oneOf(database).commitTransaction(txn);
 			// Check whether the transport is in the DB (which it's not)
-- 
GitLab