From f0a682d1a2a640eaa78016b01d3c88d63d0e8a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Tue, 1 Mar 2022 16:45:30 -0500 Subject: [PATCH] interaction: support unbanned contacts Because admins are able to re-add banned contact (after a vote), interactions must be shown. https://git.jami.net/savoirfairelinux/jami-product-backlog/-/issues/51 Change-Id: I9350a26e9ada6528f08065f9a55b842cd6848d5f --- src/api/interaction.h | 8 +++++++- src/conversationmodel.cpp | 17 ++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/api/interaction.h b/src/api/interaction.h index 8156db71..3b32df01 100644 --- a/src/api/interaction.h +++ b/src/api/interaction.h @@ -176,7 +176,7 @@ to_status(const QString& status) return Status::INVALID; } -enum class ContactAction { ADD, JOIN, LEAVE, BANNED, INVALID }; +enum class ContactAction { ADD, JOIN, LEAVE, BANNED, UNBANNED, INVALID }; Q_ENUM_NS(ContactAction) static inline const QString @@ -191,6 +191,8 @@ to_string(const ContactAction& action) return "LEAVE"; case ContactAction::BANNED: return "BANNED"; + case ContactAction::UNBANNED: + return "UNBANNED"; case ContactAction::INVALID: return {}; } @@ -208,6 +210,8 @@ to_action(const QString& action) return ContactAction::LEAVE; else if (action == "ban") return ContactAction::BANNED; + else if (action == "unban") + return ContactAction::UNBANNED; return ContactAction::INVALID; } @@ -226,6 +230,8 @@ getContactInteractionString(const QString& authorUri, const ContactAction& actio return QObject::tr("%1 left").arg(authorUri); case ContactAction::BANNED: return QObject::tr("%1 was kicked").arg(authorUri); + case ContactAction::UNBANNED: + return QObject::tr("%1 was re-added").arg(authorUri); case ContactAction::INVALID: return {}; } diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index c191ce59..e73d589d 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -2374,6 +2374,13 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId, linked.owner.dataTransferModel->registerTransferId(fileId, msgId); } else if (msg.type == interaction::Type::CALL) { msg.body = storage::getCallInteractionString(msg.authorUri, msg.duration); + } else if (msg.type == interaction::Type::CONTACT) { + auto bestName = msg.authorUri == linked.owner.profileInfo.uri + ? linked.owner.accountModel->bestNameForAccount(linked.owner.id) + : linked.owner.contactModel->bestNameForContact(msg.authorUri); + msg.body = interaction::getContactInteractionString(bestName, + interaction::to_action( + message["action"])); } else if (msg.type == interaction::Type::TEXT && msg.authorUri != linked.owner.profileInfo.uri) { conversation.unreadMessages++; @@ -2584,20 +2591,12 @@ ConversationModelPimpl::slotConversationMemberEvent(const QString& accountId, if (accountId != linked.owner.id || indexOf(conversationId) < 0) { return; } - switch (event) { - case 0: // add + if (event == 0 /* add */) { // clear search result for (unsigned int i = 0; i < searchResults.size(); ++i) { if (searchResults.at(i).uid == memberUri) searchResults.erase(searchResults.begin() + i); } - break; - case 1: // joins - break; - case 2: // leave - break; - case 3: // banned - break; } // update participants auto& conversation = getConversationForUid(conversationId).get(); -- GitLab