@Test public void testRemovingGroupEndsSessions() throws Exception { Contact contact2 = new Contact(new ContactId(2), author, author.getId(), true, true); Contact contact3 = new Contact(new ContactId(3), author, author.getId(), true, true); Collection<Contact> contacts = Arrays.asList(contact, contact2, contact3); Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION); MessageId storageId2 = new MessageId(getRandomId()); MessageId storageId3 = new MessageId(getRandomId()); BdfDictionary bdfSession2 = BdfDictionary.of(new BdfEntry("f2", "o")); BdfDictionary bdfSession3 = BdfDictionary.of(new BdfEntry("f3", "o")); expectGetSession(oneResult, sessionId, contactGroup.getId()); expectGetSession(Collections.singletonMap(storageId2, bdfSession2), sessionId, contactGroup2.getId()); expectGetSession(Collections.singletonMap(storageId3, bdfSession3), sessionId, contactGroup3.getId()); context.checking(new Expectations() {{ oneOf(db).getContacts(txn); will(returnValue(contacts)); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact); will(returnValue(contactGroup)); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact2); will(returnValue(contactGroup2)); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact3); will(returnValue(contactGroup3)); oneOf(sessionParser).getRole(bdfSession); will(returnValue(Role.CREATOR)); oneOf(sessionParser) .parseCreatorSession(contactGroup.getId(), bdfSession); will(returnValue(creatorSession)); oneOf(creatorEngine).onLeaveAction(txn, creatorSession); will(returnValue(creatorSession)); oneOf(sessionParser).getRole(bdfSession2); will(returnValue(Role.INVITEE)); oneOf(sessionParser) .parseInviteeSession(contactGroup2.getId(), bdfSession2); will(returnValue(inviteeSession)); oneOf(inviteeEngine).onLeaveAction(txn, inviteeSession); will(returnValue(inviteeSession)); oneOf(sessionParser).getRole(bdfSession3); will(returnValue(Role.PEER)); oneOf(sessionParser) .parsePeerSession(contactGroup3.getId(), bdfSession3); will(returnValue(peerSession)); oneOf(peerEngine).onLeaveAction(txn, peerSession); will(returnValue(peerSession)); }}); expectStoreSession(creatorSession, storageMessage.getId()); expectStoreSession(inviteeSession, storageId2); expectStoreSession(peerSession, storageId3); groupInvitationManager.removingGroup(txn, privateGroup.getId()); }
@Override public void removingGroup(Transaction txn, GroupId privateGroupId) throws DbException { SessionId sessionId = getSessionId(privateGroupId); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); if (ss == null) continue; Session session = handleAction(txn, LocalAction.LEAVE, contactGroupId, ss.bdfSession); storeSession(txn, ss.storageId, session); } } catch (FormatException e) { throw new DbException(e); } }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public void removingGroup(Transaction txn, GroupId privateGroupId) throws DbException { SessionId sessionId = getSessionId(privateGroupId); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); if (ss == null) continue; Session session = handleAction(txn, LocalAction.LEAVE, contactGroupId, ss.bdfSession); storeSession(txn, ss.storageId, session); } } catch (FormatException e) { throw new DbException(e); } } }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public void removingGroup(Transaction txn, GroupId privateGroupId) throws DbException { SessionId sessionId = getSessionId(privateGroupId); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); if (ss == null) continue; Session session = handleAction(txn, LocalAction.LEAVE, contactGroupId, ss.bdfSession); storeSession(txn, ss.storageId, session); } } catch (FormatException e) { throw new DbException(e); } } @Inject  GroupInvitationManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser, MessageTracker messageTracker,
			ContactGroupFactory contactGroupFactory,
			PrivateGroupFactory privateGroupFactory,
			PrivateGroupManager privateGroupManager,
			MessageParser messageParser, SessionParser sessionParser,
			SessionEncoder sessionEncoder,
			ProtocolEngineFactory engineFactory); }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public void removingGroup(Transaction txn, GroupId privateGroupId) throws DbException { SessionId sessionId = getSessionId(privateGroupId); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); if (ss == null) continue; Session session = handleAction(txn, LocalAction.LEAVE, contactGroupId, ss.bdfSession); storeSession(txn, ss.storageId, session); } } catch (FormatException e) { throw new DbException(e); } } @Inject  GroupInvitationManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser, MessageTracker messageTracker,
			ContactGroupFactory contactGroupFactory,
			PrivateGroupFactory privateGroupFactory,
			PrivateGroupManager privateGroupManager,
			MessageParser messageParser, SessionParser sessionParser,
			SessionEncoder sessionEncoder,
			ProtocolEngineFactory engineFactory); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override Group getContactGroup(Contact c); @Override void sendInvitation(GroupId privateGroupId, ContactId c,
			@Nullable String message, long timestamp, byte[] signature); @Override void respondToInvitation(ContactId c, PrivateGroup g, boolean accept); @Override void respondToInvitation(ContactId c, SessionId sessionId,
			boolean accept); @Override void revealRelationship(ContactId c, GroupId g); @Override Collection<InvitationMessage> getInvitationMessages(ContactId c); @Override Collection<GroupInvitationItem> getInvitations(); @Override boolean isInvitationAllowed(Contact c, GroupId privateGroupId); @Override void addingMember(Transaction txn, GroupId privateGroupId, Author a); @Override void removingGroup(Transaction txn, GroupId privateGroupId); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public void removingGroup(Transaction txn, GroupId privateGroupId) throws DbException { SessionId sessionId = getSessionId(privateGroupId); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); if (ss == null) continue; Session session = handleAction(txn, LocalAction.LEAVE, contactGroupId, ss.bdfSession); storeSession(txn, ss.storageId, session); } } catch (FormatException e) { throw new DbException(e); } } @Inject  GroupInvitationManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser, MessageTracker messageTracker,
			ContactGroupFactory contactGroupFactory,
			PrivateGroupFactory privateGroupFactory,
			PrivateGroupManager privateGroupManager,
			MessageParser messageParser, SessionParser sessionParser,
			SessionEncoder sessionEncoder,
			ProtocolEngineFactory engineFactory); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override Group getContactGroup(Contact c); @Override void sendInvitation(GroupId privateGroupId, ContactId c,
			@Nullable String message, long timestamp, byte[] signature); @Override void respondToInvitation(ContactId c, PrivateGroup g, boolean accept); @Override void respondToInvitation(ContactId c, SessionId sessionId,
			boolean accept); @Override void revealRelationship(ContactId c, GroupId g); @Override Collection<InvitationMessage> getInvitationMessages(ContactId c); @Override Collection<GroupInvitationItem> getInvitations(); @Override boolean isInvitationAllowed(Contact c, GroupId privateGroupId); @Override void addingMember(Transaction txn, GroupId privateGroupId, Author a); @Override void removingGroup(Transaction txn, GroupId privateGroupId); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v);  }