@Test public void testGetInvitationMessages() 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); long time1 = 1L, time2 = 2L; MessageMetadata messageMetadata1 = new MessageMetadata(INVITE, privateGroup.getId(), time1, true, true, true, false, true); MessageMetadata messageMetadata2 = new MessageMetadata(JOIN, privateGroup.getId(), time2, true, true, true, true, false); InviteMessage invite = new InviteMessage(message.getId(), contactGroup.getId(), privateGroup.getId(), time1, "name", author, new byte[0], null, new byte[0]); PrivateGroup pg = new PrivateGroup(privateGroup, invite.getGroupName(), invite.getCreator(), invite.getSalt()); context.checking(new Expectations() {{ oneOf(db).startTransaction(true); will(returnValue(txn)); oneOf(db).getContact(txn, contactId); will(returnValue(contact)); oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, MAJOR_VERSION, contact); will(returnValue(contactGroup)); oneOf(messageParser).getMessagesVisibleInUiQuery(); will(returnValue(query)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, contactGroup.getId(), query); will(returnValue(results)); oneOf(messageParser).parseMetadata(meta); will(returnValue(messageMetadata1)); oneOf(db).getMessageStatus(txn, contactId, message.getId()); oneOf(messageParser).getInviteMessage(txn, message.getId()); will(returnValue(invite)); oneOf(privateGroupFactory).createPrivateGroup(invite.getGroupName(), invite.getCreator(), invite.getSalt()); will(returnValue(pg)); oneOf(db).containsGroup(txn, privateGroup.getId()); will(returnValue(true)); oneOf(messageParser).parseMetadata(meta2); will(returnValue(messageMetadata2)); oneOf(db).getMessageStatus(txn, contactId, messageId2); oneOf(db).commitTransaction(txn); oneOf(db).endTransaction(txn); }}); Collection<InvitationMessage> messages = groupInvitationManager.getInvitationMessages(contactId); assertEquals(2, messages.size()); for (InvitationMessage m : messages) { assertEquals(contactGroup.getId(), m.getGroupId()); assertEquals(contactId, m.getContactId()); if (m.getId().equals(message.getId())) { assertTrue(m instanceof GroupInvitationRequest); assertEquals(time1, m.getTimestamp()); } else if (m.getId().equals(messageId2)) { assertTrue(m instanceof GroupInvitationResponse); assertEquals(time2, m.getTimestamp()); } else { throw new AssertionError(); } } }
@Override public Collection<InvitationMessage> getInvitationMessages(ContactId c) throws DbException { List<InvitationMessage> messages; Transaction txn = db.startTransaction(true); try { Contact contact = db.getContact(txn, c); GroupId contactGroupId = getContactGroup(contact).getId(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); Map<MessageId, BdfDictionary> results = clientHelper .getMessageMetadataAsDictionary(txn, contactGroupId, query); messages = new ArrayList<>(results.size()); for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { MessageId m = e.getKey(); MessageMetadata meta = messageParser.parseMetadata(e.getValue()); MessageStatus status = db.getMessageStatus(txn, c, m); MessageType type = meta.getMessageType(); if (type == INVITE) { messages.add(parseInvitationRequest(txn, c, contactGroupId, m, meta, status)); } else if (type == JOIN) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, true)); } else if (type == LEAVE) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, false)); } } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return messages; }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public Collection<InvitationMessage> getInvitationMessages(ContactId c) throws DbException { List<InvitationMessage> messages; Transaction txn = db.startTransaction(true); try { Contact contact = db.getContact(txn, c); GroupId contactGroupId = getContactGroup(contact).getId(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); Map<MessageId, BdfDictionary> results = clientHelper .getMessageMetadataAsDictionary(txn, contactGroupId, query); messages = new ArrayList<>(results.size()); for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { MessageId m = e.getKey(); MessageMetadata meta = messageParser.parseMetadata(e.getValue()); MessageStatus status = db.getMessageStatus(txn, c, m); MessageType type = meta.getMessageType(); if (type == INVITE) { messages.add(parseInvitationRequest(txn, c, contactGroupId, m, meta, status)); } else if (type == JOIN) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, true)); } else if (type == LEAVE) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, false)); } } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return messages; } }
GroupInvitationManagerImpl extends ConversationClientImpl implements GroupInvitationManager, Client, ContactHook,
		PrivateGroupHook, ClientVersioningHook { @Override public Collection<InvitationMessage> getInvitationMessages(ContactId c) throws DbException { List<InvitationMessage> messages; Transaction txn = db.startTransaction(true); try { Contact contact = db.getContact(txn, c); GroupId contactGroupId = getContactGroup(contact).getId(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); Map<MessageId, BdfDictionary> results = clientHelper .getMessageMetadataAsDictionary(txn, contactGroupId, query); messages = new ArrayList<>(results.size()); for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { MessageId m = e.getKey(); MessageMetadata meta = messageParser.parseMetadata(e.getValue()); MessageStatus status = db.getMessageStatus(txn, c, m); MessageType type = meta.getMessageType(); if (type == INVITE) { messages.add(parseInvitationRequest(txn, c, contactGroupId, m, meta, status)); } else if (type == JOIN) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, true)); } else if (type == LEAVE) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, false)); } } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return messages; } @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<InvitationMessage> getInvitationMessages(ContactId c) throws DbException { List<InvitationMessage> messages; Transaction txn = db.startTransaction(true); try { Contact contact = db.getContact(txn, c); GroupId contactGroupId = getContactGroup(contact).getId(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); Map<MessageId, BdfDictionary> results = clientHelper .getMessageMetadataAsDictionary(txn, contactGroupId, query); messages = new ArrayList<>(results.size()); for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { MessageId m = e.getKey(); MessageMetadata meta = messageParser.parseMetadata(e.getValue()); MessageStatus status = db.getMessageStatus(txn, c, m); MessageType type = meta.getMessageType(); if (type == INVITE) { messages.add(parseInvitationRequest(txn, c, contactGroupId, m, meta, status)); } else if (type == JOIN) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, true)); } else if (type == LEAVE) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, false)); } } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return messages; } @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<InvitationMessage> getInvitationMessages(ContactId c) throws DbException { List<InvitationMessage> messages; Transaction txn = db.startTransaction(true); try { Contact contact = db.getContact(txn, c); GroupId contactGroupId = getContactGroup(contact).getId(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); Map<MessageId, BdfDictionary> results = clientHelper .getMessageMetadataAsDictionary(txn, contactGroupId, query); messages = new ArrayList<>(results.size()); for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { MessageId m = e.getKey(); MessageMetadata meta = messageParser.parseMetadata(e.getValue()); MessageStatus status = db.getMessageStatus(txn, c, m); MessageType type = meta.getMessageType(); if (type == INVITE) { messages.add(parseInvitationRequest(txn, c, contactGroupId, m, meta, status)); } else if (type == JOIN) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, true)); } else if (type == LEAVE) { messages.add( parseInvitationResponse(c, contactGroupId, m, meta, status, false)); } } db.commitTransaction(txn); } catch (FormatException e) { throw new DbException(e); } finally { db.endTransaction(txn); } return messages; } @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);  }