@Test public void testGetInvitations() throws Exception { BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u")); MessageId messageId2 = new MessageId(TestUtils.getRandomId()); BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e")); Map<MessageId, BdfDictionary> results = new HashMap<>(); results.put(message.getId(), meta); results.put(messageId2, meta2); Message message2 = new Message(messageId2, contactGroup.getId(), 0L, getRandomBytes(MESSAGE_HEADER_LENGTH + 1)); long time1 = 1L, time2 = 2L; String groupName = getRandomString(MAX_GROUP_NAME_LENGTH); byte[] salt = getRandomBytes(GROUP_SALT_LENGTH); InviteMessage inviteMessage1 = new InviteMessage(message.getId(), contactGroup.getId(), privateGroup.getId(), time1, groupName, author, salt, null, getRandomBytes(5)); InviteMessage inviteMessage2 = new InviteMessage(message2.getId(), contactGroup.getId(), privateGroup.getId(), time2, groupName, author, salt, null, getRandomBytes(5)); PrivateGroup pg = new PrivateGroup(privateGroup, groupName, author, salt); context.checking(new Expectations() {{ oneOf(messageParser).getInvitesAvailableToAnswerQuery(); will(returnValue(query)); oneOf(db).startTransaction(true); will(returnValue(txn)); oneOf(db).getContacts(txn); will(returnValue(Collections.singletonList(contact))); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact); will(returnValue(contactGroup)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, contactGroup.getId(), query); will(returnValue(results)); oneOf(messageParser).getInviteMessage(txn, message.getId()); will(returnValue(inviteMessage1)); oneOf(privateGroupFactory).createPrivateGroup(groupName, author, salt); will(returnValue(pg)); oneOf(messageParser).getInviteMessage(txn, messageId2); will(returnValue(inviteMessage2)); oneOf(privateGroupFactory).createPrivateGroup(groupName, author, salt); will(returnValue(pg)); oneOf(db).commitTransaction(txn); oneOf(db).endTransaction(txn); }}); Collection<GroupInvitationItem> items = groupInvitationManager.getInvitations(); assertEquals(2, items.size()); for (GroupInvitationItem i : items) { assertEquals(contact, i.getCreator()); assertEquals(author, i.getCreator().getAuthor()); assertEquals(privateGroup.getId(), i.getId()); assertEquals(groupName, i.getName()); } }
@Override public Collection<GroupInvitationItem> getInvitations() throws DbException { List<GroupInvitationItem> items = new ArrayList<>(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query); for (MessageId m : results.keySet()) items.add(parseGroupInvitationItem(txn, c, m)); } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return items; }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public Collection<GroupInvitationItem> getInvitations() throws DbException { List<GroupInvitationItem> items = new ArrayList<>(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query); for (MessageId m : results.keySet()) items.add(parseGroupInvitationItem(txn, c, m)); } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return items; } }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public Collection<GroupInvitationItem> getInvitations() throws DbException { List<GroupInvitationItem> items = new ArrayList<>(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query); for (MessageId m : results.keySet()) items.add(parseGroupInvitationItem(txn, c, m)); } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return items; } @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 Collection<GroupInvitationItem> getInvitations() throws DbException { List<GroupInvitationItem> items = new ArrayList<>(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query); for (MessageId m : results.keySet()) items.add(parseGroupInvitationItem(txn, c, m)); } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return items; } @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 Collection<GroupInvitationItem> getInvitations() throws DbException { List<GroupInvitationItem> items = new ArrayList<>(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); Transaction txn = db.startTransaction(true); try { for (Contact c : db.getContacts(txn)) { GroupId contactGroupId = getContactGroup(c).getId(); Map<MessageId, BdfDictionary> results = clientHelper.getMessageMetadataAsDictionary(txn, contactGroupId, query); for (MessageId m : results.keySet()) items.add(parseGroupInvitationItem(txn, c, m)); } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return items; } @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);  }