Commit 66cdf4f5 authored by Torsten Grote's avatar Torsten Grote

Refactored IntroductionSucceededEvent into more generic ContactAddedRemotelyEvent

parent 33844774
package org.briarproject.briar.api.introduction.event;
package org.briarproject.bramble.api.contact.event;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.event.Event;
......@@ -8,11 +8,11 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class IntroductionSucceededEvent extends Event {
public class ContactAddedRemotelyEvent extends Event {
private final Contact contact;
public IntroductionSucceededEvent(Contact contact) {
public ContactAddedRemotelyEvent(Contact contact) {
this.contact = contact;
}
......
......@@ -42,7 +42,7 @@ import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
import java.util.Set;
......@@ -99,7 +99,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private final Multiset<GroupId> groupCounts = new Multiset<>();
private final Multiset<GroupId> forumCounts = new Multiset<>();
private final Multiset<GroupId> blogCounts = new Multiset<>();
private int introductionTotal = 0;
private int contactAddedTotal = 0;
private int nextRequestId = 0;
private ContactId blockedContact = null;
private GroupId blockedGroup = null;
......@@ -171,7 +171,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
clearGroupMessageNotification();
clearForumPostNotification();
clearBlogPostNotification();
clearIntroductionSuccessNotification();
clearContactAddedNotification();
return null;
});
try {
......@@ -206,9 +206,9 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
}
@UiThread
private void clearIntroductionSuccessNotification() {
introductionTotal = 0;
notificationManager.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
private void clearContactAddedNotification() {
contactAddedTotal = 0;
notificationManager.cancel(CONTACT_ADDED_NOTIFICATION_ID);
}
@Override
......@@ -230,8 +230,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} else if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
if (!b.isLocal()) showBlogPostNotification(b.getGroupId());
} else if (e instanceof IntroductionSucceededEvent) {
showIntroductionNotification();
} else if (e instanceof ContactAddedRemotelyEvent) {
showContactAddedNotification();
}
}
......@@ -563,24 +563,24 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
}
@UiThread
private void showIntroductionNotification() {
introductionTotal++;
updateIntroductionNotification();
private void showContactAddedNotification() {
contactAddedTotal++;
updateContactAddedNotification();
}
@UiThread
private void updateIntroductionNotification() {
private void updateContactAddedNotification() {
BriarNotificationBuilder b =
new BriarNotificationBuilder(appContext, CONTACT_CHANNEL_ID);
b.setSmallIcon(R.drawable.notification_introduction);
b.setColorRes(R.color.briar_primary);
b.setContentTitle(appContext.getText(R.string.app_name));
b.setContentText(appContext.getResources().getQuantityString(
R.plurals.introduction_notification_text, introductionTotal,
introductionTotal));
R.plurals.introduction_notification_text, contactAddedTotal,
contactAddedTotal));
b.setNotificationCategory(CATEGORY_MESSAGE);
setAlertProperties(b);
setDeleteIntent(b, INTRODUCTION_URI);
setDeleteIntent(b, CONTACT_ADDED_URI);
// Touching the notification shows the contact list
Intent i = new Intent(appContext, NavDrawerActivity.class);
i.putExtra(INTENT_CONTACTS, true);
......@@ -591,14 +591,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
notificationManager.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID,
notificationManager.notify(CONTACT_ADDED_NOTIFICATION_ID,
b.build());
}
@Override
public void clearAllIntroductionNotifications() {
androidExecutor.runOnUiThread(
this::clearIntroductionSuccessNotification);
public void clearAllContactAddedNotifications() {
androidExecutor.runOnUiThread(this::clearContactAddedNotification);
}
@Override
......
......@@ -12,7 +12,7 @@ import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG
import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_URI;
import static org.briarproject.briar.api.android.AndroidNotificationManager.FORUM_URI;
import static org.briarproject.briar.api.android.AndroidNotificationManager.GROUP_URI;
import static org.briarproject.briar.api.android.AndroidNotificationManager.INTRODUCTION_URI;
import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_ADDED_URI;
public class NotificationCleanupService extends IntentService {
......@@ -46,8 +46,8 @@ public class NotificationCleanupService extends IntentService {
notificationManager.clearAllForumPostNotifications();
} else if (uri.equals(BLOG_URI)) {
notificationManager.clearAllBlogPostNotifications();
} else if (uri.equals(INTRODUCTION_URI)) {
notificationManager.clearAllIntroductionNotifications();
} else if (uri.equals(CONTACT_ADDED_URI)) {
notificationManager.clearAllContactAddedNotifications();
}
}
}
......@@ -192,7 +192,7 @@ public class ContactListFragment extends BaseFragment implements EventListener,
super.onStart();
eventBus.addListener(this);
notificationManager.clearAllContactNotifications();
notificationManager.clearAllIntroductionNotifications();
notificationManager.clearAllContactAddedNotifications();
loadContacts();
checkForPendingContacts();
list.startPeriodicUpdate();
......
......@@ -30,7 +30,7 @@ public interface AndroidNotificationManager {
int GROUP_MESSAGE_NOTIFICATION_ID = 5;
int FORUM_POST_NOTIFICATION_ID = 6;
int BLOG_POST_NOTIFICATION_ID = 7;
int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 8;
int CONTACT_ADDED_NOTIFICATION_ID = 8;
// Channel IDs
String CONTACT_CHANNEL_ID = "contacts";
......@@ -48,7 +48,7 @@ public interface AndroidNotificationManager {
String GROUP_URI = "content://org.briarproject.briar/group";
String FORUM_URI = "content://org.briarproject.briar/forum";
String BLOG_URI = "content://org.briarproject.briar/blog";
String INTRODUCTION_URI = "content://org.briarproject.briar/introduction";
String CONTACT_ADDED_URI = "content://org.briarproject.briar/contact/added";
// Actions for pending intents
String ACTION_DISMISS_REMINDER = "dismissReminder";
......@@ -73,7 +73,7 @@ public interface AndroidNotificationManager {
void clearAllBlogPostNotifications();
void clearAllIntroductionNotifications();
void clearAllContactAddedNotifications();
void showSignInNotification();
......
......@@ -30,7 +30,7 @@ import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.introduction.IntroductionRequest;
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import java.security.GeneralSecurityException;
import java.util.Map;
......@@ -453,7 +453,7 @@ class IntroduceeProtocolEngine
s.getRemote().transportProperties);
// Broadcast IntroductionSucceededEvent, because contact got added
IntroductionSucceededEvent e = new IntroductionSucceededEvent(c);
ContactAddedRemotelyEvent e = new ContactAddedRemotelyEvent(c);
txn.attach(e);
} catch (ContactExistsException e) {
// Ignore this, because the other introducee might have deleted us.
......
......@@ -32,7 +32,7 @@ import org.briarproject.briar.api.introduction.IntroductionResponse;
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
import org.briarproject.briar.test.BriarIntegrationTest;
import org.junit.Before;
import org.junit.Test;
......@@ -1275,10 +1275,10 @@ public class IntroductionIntegrationTest
// only broadcast for DECLINE messages in introducee role
latestEvent = e;
eventWaiter.resume();
} else if (e instanceof IntroductionSucceededEvent) {
} else if (e instanceof ContactAddedRemotelyEvent) {
latestEvent = e;
succeeded = true;
Contact contact = ((IntroductionSucceededEvent) e).getContact();
Contact contact = ((ContactAddedRemotelyEvent) e).getContact();
eventWaiter
.assertFalse(contact.getId().equals(contactId0From1));
eventWaiter.resume();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment