Skip to content
Snippets Groups Projects
Commit 0d1693b1 authored by Hugo Lefeuvre's avatar Hugo Lefeuvre Committed by Andreas Traczyk
Browse files

Do not erase contact when banned


Stop erasing banned accounts / removing from the database when
contactRemoved signal is received from the daemon. Instead mark the
account as banned and force the client to refresh its filters.

Also: Fix the default account filter so it filters out banned accounts
unless regex is a perfect match.

Change-Id: I75d1aea5271d88b13f1850d47b33c279b89a5a05
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent e329a07e
No related branches found
No related tags found
No related merge requests found
...@@ -78,13 +78,18 @@ public: ...@@ -78,13 +78,18 @@ public:
* Get a custom filtered set of conversations * Get a custom filtered set of conversations
* @return conversations filtered * @return conversations filtered
*/ */
const ConversationQueue& getFilteredConversations(const profile::Type& filter = profile::Type::INVALID, bool forceUpdate = false) const; const ConversationQueue& getFilteredConversations(const profile::Type& filter = profile::Type::INVALID, bool forceUpdate = false, const bool includeBanned = false) const;
/** /**
* Get the conversation at row in the filtered conversations * Get the conversation at row in the filtered conversations
* @param row * @param row
* @return a copy of the conversation * @return a copy of the conversation
*/ */
conversation::Info filteredConversation(unsigned int row) const; conversation::Info filteredConversation(unsigned int row) const;
/**
* Emit a filterChanged signal to force the client to refresh the filter. For instance
* this is required when a contact was banned or un-banned.
*/
void refreshFilter();
/** /**
* Make permanent a temporary contact or a pending request. * Make permanent a temporary contact or a pending request.
* Ensure that given conversation is stored permanently into the system. * Ensure that given conversation is stored permanently into the system.
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "api/contact.h" #include "api/contact.h"
#include "api/interaction.h" #include "api/interaction.h"
#include "api/newcallmodel.h" #include "api/newcallmodel.h"
#include "api/conversationmodel.h"
#include "callbackshandler.h" #include "callbackshandler.h"
#include "accountmodel.h" #include "accountmodel.h"
...@@ -521,19 +522,38 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str ...@@ -521,19 +522,38 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str
void void
ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::string& contactUri, bool banned) ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::string& contactUri, bool banned)
{ {
Q_UNUSED(banned)
if (accountId != linked.owner.id) if (accountId != linked.owner.id)
return; return;
{ {
std::lock_guard<std::mutex> lk(contactsMtx_); std::lock_guard<std::mutex> lk(contactsMtx_);
if (contacts.find(contactUri) != contacts.end()) {
auto contact = contacts.find(contactUri);
if (contact == contacts.end()) return;
if (banned) {
contact->second.isBanned = true;
auto* account = AccountModel::instance().getById(linked.owner.id.c_str());
if (not account) {
qDebug() << "ContactModel::slotContactsAdded(), nullptr";
return;
}
auto* cm = PhoneDirectoryModel::instance().getNumber(QString(contactUri.c_str()), account);
account->bannedContactModel()->add(cm);
} else {
database::removeContact(db, linked.owner.profileInfo.uri, contactUri); database::removeContact(db, linked.owner.profileInfo.uri, contactUri);
contacts.erase(contactUri); contacts.erase(contactUri);
} else
return;
} }
}
if (banned) {
// Update the smartlist
linked.owner.conversationModel->refreshFilter();
} else {
emit linked.contactRemoved(contactUri); emit linked.contactRemoved(contactUri);
} }
}
void void
ContactModelPimpl::addToContacts(ContactMethod* cm, const profile::Type& type) ContactModelPimpl::addToContacts(ContactMethod* cm, const profile::Type& type)
......
...@@ -281,7 +281,17 @@ ConversationModel::allFilteredConversations() const ...@@ -281,7 +281,17 @@ ConversationModel::allFilteredConversations() const
pimpl_->filteredConversations.begin(), pimpl_->filteredConversations.begin(),
[this] (const conversation::Info& entry) { [this] (const conversation::Info& entry) {
auto contactInfo = owner.contactModel->getContact(entry.participants.front()); auto contactInfo = owner.contactModel->getContact(entry.participants.front());
// Check type
/* Check contact */
// If contact is banned, only match if filter is a perfect match
if (contactInfo.isBanned) {
if (pimpl_->filter == "") return false;
return contactInfo.profileInfo.uri == pimpl_->filter
|| contactInfo.profileInfo.alias == pimpl_->filter
|| contactInfo.registeredName == pimpl_->filter;
}
/* Check type */
if (pimpl_->typeFilter != profile::Type::PENDING) { if (pimpl_->typeFilter != profile::Type::PENDING) {
// Remove pending contacts and get the temporary item if filter is not empty // Remove pending contacts and get the temporary item if filter is not empty
if (contactInfo.profileInfo.type == profile::Type::PENDING) if (contactInfo.profileInfo.type == profile::Type::PENDING)
...@@ -294,7 +304,7 @@ ConversationModel::allFilteredConversations() const ...@@ -294,7 +304,7 @@ ConversationModel::allFilteredConversations() const
return false; return false;
} }
// Check contact // Otherwise perform usual regex search
try { try {
auto regexFilter = std::regex(pimpl_->filter, std::regex_constants::icase); auto regexFilter = std::regex(pimpl_->filter, std::regex_constants::icase);
bool result = std::regex_search(contactInfo.profileInfo.uri, regexFilter) bool result = std::regex_search(contactInfo.profileInfo.uri, regexFilter)
...@@ -315,7 +325,7 @@ ConversationModel::allFilteredConversations() const ...@@ -315,7 +325,7 @@ ConversationModel::allFilteredConversations() const
} }
const ConversationModel::ConversationQueue& const ConversationModel::ConversationQueue&
ConversationModel::getFilteredConversations(const profile::Type& filter, bool forceUpdate) const ConversationModel::getFilteredConversations(const profile::Type& filter, bool forceUpdate, const bool includeBanned) const
{ {
if (pimpl_->customTypeFilter == filter && !pimpl_->dirtyConversations.second && !forceUpdate) if (pimpl_->customTypeFilter == filter && !pimpl_->dirtyConversations.second && !forceUpdate)
return pimpl_->customFilteredConversations; return pimpl_->customFilteredConversations;
...@@ -326,8 +336,9 @@ ConversationModel::getFilteredConversations(const profile::Type& filter, bool fo ...@@ -326,8 +336,9 @@ ConversationModel::getFilteredConversations(const profile::Type& filter, bool fo
auto it = std::copy_if( auto it = std::copy_if(
pimpl_->conversations.begin(), pimpl_->conversations.end(), pimpl_->conversations.begin(), pimpl_->conversations.end(),
pimpl_->customFilteredConversations.begin(), pimpl_->customFilteredConversations.begin(),
[this] (const conversation::Info& entry) { [this, &includeBanned] (const conversation::Info& entry) {
auto contactInfo = owner.contactModel->getContact(entry.participants.front()); auto contactInfo = owner.contactModel->getContact(entry.participants.front());
if (!includeBanned && contactInfo.isBanned) return false;
return (contactInfo.profileInfo.type == pimpl_->customTypeFilter); return (contactInfo.profileInfo.type == pimpl_->customTypeFilter);
}); });
pimpl_->customFilteredConversations.resize(std::distance(pimpl_->customFilteredConversations.begin(), it)); pimpl_->customFilteredConversations.resize(std::distance(pimpl_->customFilteredConversations.begin(), it));
...@@ -625,6 +636,13 @@ ConversationModel::sendMessage(const std::string& uid, const std::string& body) ...@@ -625,6 +636,13 @@ ConversationModel::sendMessage(const std::string& uid, const std::string& body)
emit modelSorted(); emit modelSorted();
} }
void
ConversationModel::refreshFilter()
{
pimpl_->dirtyConversations = {true, true};
emit filterChanged();
}
void void
ConversationModel::setFilter(const std::string& filter) ConversationModel::setFilter(const std::string& filter)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment