mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Refactored IntroductionSucceededEvent into more generic ContactAddedRemotelyEvent
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
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.contact.Contact;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
@@ -8,11 +8,11 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IntroductionSucceededEvent extends Event {
|
public class ContactAddedRemotelyEvent extends Event {
|
||||||
|
|
||||||
private final Contact contact;
|
private final Contact contact;
|
||||||
|
|
||||||
public IntroductionSucceededEvent(Contact contact) {
|
public ContactAddedRemotelyEvent(Contact contact) {
|
||||||
this.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.blog.event.BlogPostAddedEvent;
|
||||||
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
||||||
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
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 org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -99,7 +99,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
private final Multiset<GroupId> groupCounts = new Multiset<>();
|
private final Multiset<GroupId> groupCounts = new Multiset<>();
|
||||||
private final Multiset<GroupId> forumCounts = new Multiset<>();
|
private final Multiset<GroupId> forumCounts = new Multiset<>();
|
||||||
private final Multiset<GroupId> blogCounts = new Multiset<>();
|
private final Multiset<GroupId> blogCounts = new Multiset<>();
|
||||||
private int introductionTotal = 0;
|
private int contactAddedTotal = 0;
|
||||||
private int nextRequestId = 0;
|
private int nextRequestId = 0;
|
||||||
private ContactId blockedContact = null;
|
private ContactId blockedContact = null;
|
||||||
private GroupId blockedGroup = null;
|
private GroupId blockedGroup = null;
|
||||||
@@ -171,7 +171,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
clearGroupMessageNotification();
|
clearGroupMessageNotification();
|
||||||
clearForumPostNotification();
|
clearForumPostNotification();
|
||||||
clearBlogPostNotification();
|
clearBlogPostNotification();
|
||||||
clearIntroductionSuccessNotification();
|
clearContactAddedNotification();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
@@ -206,9 +206,9 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void clearIntroductionSuccessNotification() {
|
private void clearContactAddedNotification() {
|
||||||
introductionTotal = 0;
|
contactAddedTotal = 0;
|
||||||
notificationManager.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
|
notificationManager.cancel(CONTACT_ADDED_NOTIFICATION_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -230,8 +230,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
} else if (e instanceof BlogPostAddedEvent) {
|
} else if (e instanceof BlogPostAddedEvent) {
|
||||||
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
||||||
if (!b.isLocal()) showBlogPostNotification(b.getGroupId());
|
if (!b.isLocal()) showBlogPostNotification(b.getGroupId());
|
||||||
} else if (e instanceof IntroductionSucceededEvent) {
|
} else if (e instanceof ContactAddedRemotelyEvent) {
|
||||||
showIntroductionNotification();
|
showContactAddedNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,24 +563,24 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void showIntroductionNotification() {
|
private void showContactAddedNotification() {
|
||||||
introductionTotal++;
|
contactAddedTotal++;
|
||||||
updateIntroductionNotification();
|
updateContactAddedNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void updateIntroductionNotification() {
|
private void updateContactAddedNotification() {
|
||||||
BriarNotificationBuilder b =
|
BriarNotificationBuilder b =
|
||||||
new BriarNotificationBuilder(appContext, CONTACT_CHANNEL_ID);
|
new BriarNotificationBuilder(appContext, CONTACT_CHANNEL_ID);
|
||||||
b.setSmallIcon(R.drawable.notification_introduction);
|
b.setSmallIcon(R.drawable.notification_introduction);
|
||||||
b.setColorRes(R.color.briar_primary);
|
b.setColorRes(R.color.briar_primary);
|
||||||
b.setContentTitle(appContext.getText(R.string.app_name));
|
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||||
b.setContentText(appContext.getResources().getQuantityString(
|
b.setContentText(appContext.getResources().getQuantityString(
|
||||||
R.plurals.introduction_notification_text, introductionTotal,
|
R.plurals.introduction_notification_text, contactAddedTotal,
|
||||||
introductionTotal));
|
contactAddedTotal));
|
||||||
b.setNotificationCategory(CATEGORY_MESSAGE);
|
b.setNotificationCategory(CATEGORY_MESSAGE);
|
||||||
setAlertProperties(b);
|
setAlertProperties(b);
|
||||||
setDeleteIntent(b, INTRODUCTION_URI);
|
setDeleteIntent(b, CONTACT_ADDED_URI);
|
||||||
// Touching the notification shows the contact list
|
// Touching the notification shows the contact list
|
||||||
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
||||||
i.putExtra(INTENT_CONTACTS, true);
|
i.putExtra(INTENT_CONTACTS, true);
|
||||||
@@ -591,14 +591,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
||||||
|
|
||||||
notificationManager.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID,
|
notificationManager.notify(CONTACT_ADDED_NOTIFICATION_ID,
|
||||||
b.build());
|
b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearAllIntroductionNotifications() {
|
public void clearAllContactAddedNotifications() {
|
||||||
androidExecutor.runOnUiThread(
|
androidExecutor.runOnUiThread(this::clearContactAddedNotification);
|
||||||
this::clearIntroductionSuccessNotification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.CONTACT_URI;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FORUM_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.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 {
|
public class NotificationCleanupService extends IntentService {
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ public class NotificationCleanupService extends IntentService {
|
|||||||
notificationManager.clearAllForumPostNotifications();
|
notificationManager.clearAllForumPostNotifications();
|
||||||
} else if (uri.equals(BLOG_URI)) {
|
} else if (uri.equals(BLOG_URI)) {
|
||||||
notificationManager.clearAllBlogPostNotifications();
|
notificationManager.clearAllBlogPostNotifications();
|
||||||
} else if (uri.equals(INTRODUCTION_URI)) {
|
} else if (uri.equals(CONTACT_ADDED_URI)) {
|
||||||
notificationManager.clearAllIntroductionNotifications();
|
notificationManager.clearAllContactAddedNotifications();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
super.onStart();
|
super.onStart();
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
notificationManager.clearAllContactNotifications();
|
notificationManager.clearAllContactNotifications();
|
||||||
notificationManager.clearAllIntroductionNotifications();
|
notificationManager.clearAllContactAddedNotifications();
|
||||||
loadContacts();
|
loadContacts();
|
||||||
checkForPendingContacts();
|
checkForPendingContacts();
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public interface AndroidNotificationManager {
|
|||||||
int GROUP_MESSAGE_NOTIFICATION_ID = 5;
|
int GROUP_MESSAGE_NOTIFICATION_ID = 5;
|
||||||
int FORUM_POST_NOTIFICATION_ID = 6;
|
int FORUM_POST_NOTIFICATION_ID = 6;
|
||||||
int BLOG_POST_NOTIFICATION_ID = 7;
|
int BLOG_POST_NOTIFICATION_ID = 7;
|
||||||
int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 8;
|
int CONTACT_ADDED_NOTIFICATION_ID = 8;
|
||||||
|
|
||||||
// Channel IDs
|
// Channel IDs
|
||||||
String CONTACT_CHANNEL_ID = "contacts";
|
String CONTACT_CHANNEL_ID = "contacts";
|
||||||
@@ -48,7 +48,7 @@ public interface AndroidNotificationManager {
|
|||||||
String GROUP_URI = "content://org.briarproject.briar/group";
|
String GROUP_URI = "content://org.briarproject.briar/group";
|
||||||
String FORUM_URI = "content://org.briarproject.briar/forum";
|
String FORUM_URI = "content://org.briarproject.briar/forum";
|
||||||
String BLOG_URI = "content://org.briarproject.briar/blog";
|
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
|
// Actions for pending intents
|
||||||
String ACTION_DISMISS_REMINDER = "dismissReminder";
|
String ACTION_DISMISS_REMINDER = "dismissReminder";
|
||||||
@@ -73,7 +73,7 @@ public interface AndroidNotificationManager {
|
|||||||
|
|
||||||
void clearAllBlogPostNotifications();
|
void clearAllBlogPostNotifications();
|
||||||
|
|
||||||
void clearAllIntroductionNotifications();
|
void clearAllContactAddedNotifications();
|
||||||
|
|
||||||
void showSignInNotification();
|
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.IntroductionRequest;
|
||||||
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
|
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
|
||||||
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
|
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.security.GeneralSecurityException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -453,7 +453,7 @@ class IntroduceeProtocolEngine
|
|||||||
s.getRemote().transportProperties);
|
s.getRemote().transportProperties);
|
||||||
|
|
||||||
// Broadcast IntroductionSucceededEvent, because contact got added
|
// Broadcast IntroductionSucceededEvent, because contact got added
|
||||||
IntroductionSucceededEvent e = new IntroductionSucceededEvent(c);
|
ContactAddedRemotelyEvent e = new ContactAddedRemotelyEvent(c);
|
||||||
txn.attach(e);
|
txn.attach(e);
|
||||||
} catch (ContactExistsException e) {
|
} catch (ContactExistsException e) {
|
||||||
// Ignore this, because the other introducee might have deleted us.
|
// 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.IntroductionAbortedEvent;
|
||||||
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
|
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
|
||||||
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
|
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.briarproject.briar.test.BriarIntegrationTest;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -1275,10 +1275,10 @@ public class IntroductionIntegrationTest
|
|||||||
// only broadcast for DECLINE messages in introducee role
|
// only broadcast for DECLINE messages in introducee role
|
||||||
latestEvent = e;
|
latestEvent = e;
|
||||||
eventWaiter.resume();
|
eventWaiter.resume();
|
||||||
} else if (e instanceof IntroductionSucceededEvent) {
|
} else if (e instanceof ContactAddedRemotelyEvent) {
|
||||||
latestEvent = e;
|
latestEvent = e;
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
Contact contact = ((IntroductionSucceededEvent) e).getContact();
|
Contact contact = ((ContactAddedRemotelyEvent) e).getContact();
|
||||||
eventWaiter
|
eventWaiter
|
||||||
.assertFalse(contact.getId().equals(contactId0From1));
|
.assertFalse(contact.getId().equals(contactId0From1));
|
||||||
eventWaiter.resume();
|
eventWaiter.resume();
|
||||||
|
|||||||
Reference in New Issue
Block a user