Message::ptr_t MessageManager::receivedMessage(Conversation &conversation, MessageData data) { auto message = make_shared<Message>(*this, data, Message::INCOMING, conversation.getId()); assert(conversation.getIdentity()); assert(conversation.getFirstParticipant()); auto cert = conversation.getFirstParticipant()->getCert(); if (!message->validate(*cert)) { LFLOG_WARN << "Incoming message from " << conversation.getFirstParticipant()->getName() << " to " << conversation.getIdentity()->getName() << " failed validation. Rejecting."; return {}; } // See if we already have received this message if (auto existing = getMessage(data.messageId, conversation.getId())) { return existing; } message->addToDb(); registry_.add(message->getId(), message); touch(message); emit messageAdded(message); return message; }
Message::ptr_t MessageManager::sendMessage(Conversation &conversation, MessageData data) { auto message = make_shared<Message>(*this, data, Message::OUTGOING, conversation.getId()); assert(conversation.getIdentity()); auto cert = conversation.getIdentity()->getCert(); message->sign(*cert); message->addToDb(); registry_.add(message->getId(), message); touch(message); emit messageAdded(message); if (auto contact = conversation.getFirstParticipant()) { contact->queueMessage(message); } return message; }