@Test public void receivesMessagesForAllIdentities() throws Exception { Identity otherIdentity = identityBuilderFactory.factory().withAlias("tester2").build(); Contact otherIdentitiesContact = getContact(otherIdentity); identityRepository.save(otherIdentity); contactRepository.save(sender, otherIdentity); send(otherIdentitiesContact, senderIdentity); dd.receiveMessages(); assertThat(dropMessageRepository.loadConversation(sender, otherIdentity), is(not(empty()))); }
void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } }
DropDaemon implements Runnable { void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } } }
DropDaemon implements Runnable { void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } } DropDaemon(ChatService chatService,
                      DropMessageRepository dropMessageRepository,
                      ContactRepository contactRepository,
                      IdentityRepository identityRepository,
                      EventSink events
    ); }
DropDaemon implements Runnable { void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } } DropDaemon(ChatService chatService,
                      DropMessageRepository dropMessageRepository,
                      ContactRepository contactRepository,
                      IdentityRepository identityRepository,
                      EventSink events
    ); @Override void run(); }
DropDaemon implements Runnable { void receiveMessages() { try { Map<String, List<ChatDropMessage>> identityListMap = chatService.refreshMessages(); for (Map.Entry<String, List<ChatDropMessage>> messages: identityListMap.entrySet()) { String identityKeyId = messages.getKey(); Identity identity = identityRepository.find(identityKeyId); for (ChatDropMessage msg: messages.getValue()) { Contact contact = contactRepository.find(msg.getContactId()); DropMessage dropMessage = new DropMessage(contact, msg.getPayload().toString(), msg.getMessageType().getType()); boolean incoming = msg.getDirection().equals(ChatDropMessage.Direction.INCOMING); Entity sender = incoming ? contact : identity; Entity receiver = incoming ? identity : contact; PersistenceDropMessage message = new PersistenceDropMessage(dropMessage, sender, receiver, !incoming, false); dropMessageRepository.save(message); events.push(new MessageReceivedEvent(message)); } } } catch (Exception e) { logger.error("Unexpected error while polling drops: " + e.getMessage(), e); } } DropDaemon(ChatService chatService,
                      DropMessageRepository dropMessageRepository,
                      ContactRepository contactRepository,
                      IdentityRepository identityRepository,
                      EventSink events
    ); @Override void run();  }