mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
swarm: add reaction support
This is a pretty trivial patch as all the necessary logics are already supported by the deamon. A client can use sendMessage with flag = 2 to add a reaction. This only adds a "react-to" in the body of the message that the client can interpret. To remove a reaction, the client can use editMessage (and set the body to "" for the id of the reaction), also there is no limit on the content of the reaction and multiple reactions can be added to the same message. For non compatible clients, it will be shown as a simple text message as it's the same type. Change-Id: I7b13d32771109118b94ed17d0b918e66487e94bb
This commit is contained in:
@ -178,6 +178,8 @@ sendMessage(const std::string& accountId,
|
||||
convModule->sendMessage(conversationId, message, commitId);
|
||||
} else if (flag == 1 /* message edition */) {
|
||||
convModule->editMessage(conversationId, message, commitId);
|
||||
} else if (flag == 2 /* reaction */) {
|
||||
convModule->reactToMessage(conversationId, message, commitId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1368,6 +1368,19 @@ ConversationModule::editMessage(const std::string& conversationId,
|
||||
pimpl_->editMessage(conversationId, newBody, editedId);
|
||||
}
|
||||
|
||||
void
|
||||
ConversationModule::reactToMessage(const std::string& conversationId,
|
||||
const std::string& newBody,
|
||||
const std::string& reactToId)
|
||||
{
|
||||
// Commit message edition
|
||||
Json::Value json;
|
||||
json["body"] = newBody;
|
||||
json["react-to"] = reactToId;
|
||||
json["type"] = "text/plain";
|
||||
pimpl_->sendMessage(conversationId, std::move(json));
|
||||
}
|
||||
|
||||
void
|
||||
ConversationModule::addCallHistoryMessage(const std::string& uri, uint64_t duration_ms)
|
||||
{
|
||||
|
@ -167,6 +167,9 @@ public:
|
||||
void editMessage(const std::string& conversationId,
|
||||
const std::string& newBody,
|
||||
const std::string& editedId);
|
||||
void reactToMessage(const std::string& conversationId,
|
||||
const std::string& newBody,
|
||||
const std::string& reactToId);
|
||||
|
||||
/**
|
||||
* Add to the related conversation the call history message
|
||||
|
@ -117,6 +117,7 @@ private:
|
||||
void testFixContactDetails();
|
||||
void testRemoveOneToOneNotInDetails();
|
||||
void testMessageEdition();
|
||||
void testMessageReaction();
|
||||
|
||||
CPPUNIT_TEST_SUITE(ConversationTest);
|
||||
CPPUNIT_TEST(testCreateConversation);
|
||||
@ -164,6 +165,7 @@ private:
|
||||
CPPUNIT_TEST(testFixContactDetails);
|
||||
CPPUNIT_TEST(testRemoveOneToOneNotInDetails);
|
||||
CPPUNIT_TEST(testMessageEdition);
|
||||
CPPUNIT_TEST(testMessageReaction);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
|
||||
@ -3518,6 +3520,50 @@ ConversationTest::testMessageEdition()
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return errorDetected; }));
|
||||
}
|
||||
|
||||
void
|
||||
ConversationTest::testMessageReaction()
|
||||
{
|
||||
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
|
||||
auto bobAccount = Manager::instance().getAccount<JamiAccount>(bobId);
|
||||
auto bobUri = bobAccount->getUsername();
|
||||
std::mutex mtx;
|
||||
std::unique_lock<std::mutex> lk {mtx};
|
||||
std::condition_variable cv;
|
||||
std::map<std::string, std::shared_ptr<libjami::CallbackWrapperBase>> confHandlers;
|
||||
std::vector<std::map<std::string, std::string>> messageAliceReceived;
|
||||
bool conversationReady = false;
|
||||
confHandlers.insert(libjami::exportable_callback<libjami::ConversationSignal::MessageReceived>(
|
||||
[&](const std::string& accountId,
|
||||
const std::string& /* conversationId */,
|
||||
std::map<std::string, std::string> message) {
|
||||
if (accountId == aliceId)
|
||||
messageAliceReceived.emplace_back(message);
|
||||
cv.notify_one();
|
||||
}));
|
||||
confHandlers.insert(libjami::exportable_callback<libjami::ConversationSignal::ConversationReady>(
|
||||
[&](const std::string& accountId, const std::string& /* conversationId */) {
|
||||
if (accountId == aliceId)
|
||||
conversationReady = true;
|
||||
cv.notify_one();
|
||||
}));
|
||||
libjami::registerSignalHandlers(confHandlers);
|
||||
auto convId = libjami::startConversation(aliceId);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return conversationReady; }));
|
||||
auto msgSize = messageAliceReceived.size();
|
||||
libjami::sendMessage(aliceId, convId, "hi"s, "");
|
||||
CPPUNIT_ASSERT(
|
||||
cv.wait_for(lk, 30s, [&]() { return messageAliceReceived.size() == msgSize + 1; }));
|
||||
msgSize = messageAliceReceived.size();
|
||||
|
||||
auto reactId = messageAliceReceived.rbegin()->at("id");
|
||||
|
||||
libjami::sendMessage(aliceId, convId, "👋"s, reactId, 2);
|
||||
CPPUNIT_ASSERT(
|
||||
cv.wait_for(lk, 10s, [&]() { return messageAliceReceived.size() == msgSize + 1; }));
|
||||
CPPUNIT_ASSERT(messageAliceReceived.rbegin()->at("react-to") == reactId);
|
||||
CPPUNIT_ASSERT(messageAliceReceived.rbegin()->at("body") == "👋");
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace jami
|
||||
|
||||
|
Reference in New Issue
Block a user