Skip to content
Snippets Groups Projects
Commit 88b194e4 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

conversationmodel: allow bypassing filter/sort operations

Provide container mutation notifiers and an api to access the raw
underlying data.

Change-Id: I4325b6bcd73ab84a734fbf4ba3039022eb0c690a
Gitlab: #467
parent 3fd5a8a3
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,15 @@ public: ...@@ -88,6 +88,15 @@ public:
const api::BehaviorController& behaviorController); const api::BehaviorController& behaviorController);
~ConversationModel(); ~ConversationModel();
/**
* Get unfiltered underlying conversation data. This is intended to
* serve as the underlying data for QAbstractListModel based objects.
* The corresponding data mutation signals will need to be responded
* to with appropriate QAbstractListModel signal forwarding.
* @return raw conversation queue
*/
const ConversationQueue& getConversations() const;
/** /**
* Get conversations which should be shown client side * Get conversations which should be shown client side
* @return conversations filtered with the current filter * @return conversations filtered with the current filter
...@@ -237,8 +246,7 @@ public: ...@@ -237,8 +246,7 @@ public:
* @param convId * @param convId
* @param interactionId * @param interactionId
*/ */
void clearInteractionFromConversation(const QString& convId, void clearInteractionFromConversation(const QString& convId, const uint64_t& interactionId);
const uint64_t& interactionId);
/** /**
* Retry to send a message. In fact, will delete the previous interaction and resend a new one. * Retry to send a message. In fact, will delete the previous interaction and resend a new one.
* @param convId * @param convId
...@@ -264,9 +272,7 @@ public: ...@@ -264,9 +272,7 @@ public:
void acceptTransfer(const QString& convUid, uint64_t interactionId); void acceptTransfer(const QString& convUid, uint64_t interactionId);
void acceptTransfer(const QString& convUid, void acceptTransfer(const QString& convUid, uint64_t interactionId, const QString& path);
uint64_t interactionId,
const QString& path);
void cancelTransfer(const QString& convUid, uint64_t interactionId); void cancelTransfer(const QString& convUid, uint64_t interactionId);
...@@ -378,6 +384,36 @@ Q_SIGNALS: ...@@ -378,6 +384,36 @@ Q_SIGNALS:
*/ */
void searchResultUpdated() const; void searchResultUpdated() const;
/**
* The following signals are intended for QAbtractListModel compatibility
*/
/*!
* Emitted before conversations are inserted into the underlying queue
* @param position The starting row of the insertion
* @param rows The number of items inserted
*/
void beginInsertRows(int position, int rows = 1) const;
//! Emitted once insertion is complete
void endInsertRows() const;
/*!
* Emitted before conversations are removed from the underlying queue
* @param position The starting row of the removal
* @param rows The number of items removed
*/
void beginRemoveRows(int position, int rows = 1) const;
//! Emitted once removal is complete
void endRemoveRows() const;
/**
* Emitted once a conversation has been updated
* @param position
*/
void dataChanged(int position) const;
private: private:
std::unique_ptr<ConversationModelPimpl> pimpl_; std::unique_ptr<ConversationModelPimpl> pimpl_;
}; };
......
...@@ -331,6 +331,12 @@ ConversationModel::ConversationModel(const account::Info& owner, ...@@ -331,6 +331,12 @@ ConversationModel::ConversationModel(const account::Info& owner,
ConversationModel::~ConversationModel() {} ConversationModel::~ConversationModel() {}
const ConversationModel::ConversationQueue&
ConversationModel::getConversations() const
{
return pimpl_->conversations;
}
const ConversationModel::ConversationQueueProxy& const ConversationModel::ConversationQueueProxy&
ConversationModel::allFilteredConversations() const ConversationModel::allFilteredConversations() const
{ {
...@@ -898,6 +904,7 @@ ConversationModel::sendMessage(const QString& uid, const QString& body) ...@@ -898,6 +904,7 @@ ConversationModel::sendMessage(const QString& uid, const QString& body)
// The order has changed, informs the client to redraw the list // The order has changed, informs the client to redraw the list
pimpl_->invalidateModel(); pimpl_->invalidateModel();
emit modelChanged(); emit modelChanged();
Q_EMIT dataChanged(pimpl_->indexOf(convId));
}); });
if (isTemporary) { if (isTemporary) {
...@@ -1013,10 +1020,11 @@ ConversationModel::clearHistory(const QString& uid) ...@@ -1013,10 +1020,11 @@ ConversationModel::clearHistory(const QString& uid)
std::lock_guard<std::mutex> lk(pimpl_->interactionsLocks[uid]); std::lock_guard<std::mutex> lk(pimpl_->interactionsLocks[uid]);
conversation.interactions.clear(); conversation.interactions.clear();
} }
storage::getHistory(pimpl_->db, conversation); // will contains "Conversation started" storage::getHistory(pimpl_->db, conversation); // will contain "Conversation started"
emit modelChanged(); emit modelChanged();
emit conversationCleared(uid); emit conversationCleared(uid);
Q_EMIT dataChanged(conversationIdx);
} }
void void
...@@ -1079,8 +1087,9 @@ ConversationModel::clearInteractionFromConversation(const QString& convId, ...@@ -1079,8 +1087,9 @@ ConversationModel::clearInteractionFromConversation(const QString& convId,
emit interactionRemoved(convId, interactionId); emit interactionRemoved(convId, interactionId);
} }
if (lastInteractionUpdated) { if (lastInteractionUpdated) {
// last interaction as changed, so the order can changes. // last interaction as changed, so the order can change.
emit modelChanged(); emit modelChanged();
Q_EMIT dataChanged(conversationIdx);
} }
} }
...@@ -1242,6 +1251,7 @@ ConversationModel::clearUnreadInteractions(const QString& convId) ...@@ -1242,6 +1251,7 @@ ConversationModel::clearUnreadInteractions(const QString& convId)
pimpl_->conversations[conversationIdx].unreadMessages = 0; pimpl_->conversations[conversationIdx].unreadMessages = 0;
pimpl_->invalidateModel(); pimpl_->invalidateModel();
emit conversationUpdated(convId); emit conversationUpdated(convId);
Q_EMIT dataChanged(conversationIdx);
} }
} }
...@@ -1686,7 +1696,10 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri) ...@@ -1686,7 +1696,10 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri)
// delete temporary conversation if it exists and it has the uri of the added contact as uid // delete temporary conversation if it exists and it has the uri of the added contact as uid
if (indexOf(profileInfo.uri) >= 0) { if (indexOf(profileInfo.uri) >= 0) {
conversations.erase(conversations.begin() + indexOf(profileInfo.uri)); auto position = indexOf(profileInfo.uri);
Q_EMIT linked.beginRemoveRows(position);
conversations.erase(conversations.begin() + position);
Q_EMIT linked.endRemoveRows();
} }
for (unsigned int i = 0; i < searchResults.size(); ++i) { for (unsigned int i = 0; i < searchResults.size(); ++i) {
if (searchResults.at(i).uid == profileInfo.uri) if (searchResults.at(i).uid == profileInfo.uri)
...@@ -1730,6 +1743,7 @@ ConversationModelPimpl::slotPendingContactAccepted(const QString& uri) ...@@ -1730,6 +1743,7 @@ ConversationModelPimpl::slotPendingContactAccepted(const QString& uri)
} }
filteredConversations.invalidate(); filteredConversations.invalidate();
emit linked.newInteraction(convs[0], msgId, interaction); emit linked.newInteraction(convs[0], msgId, interaction);
Q_EMIT linked.dataChanged(convIdx);
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
qDebug() << "ConversationModelPimpl::slotContactAdded can't find contact"; qDebug() << "ConversationModelPimpl::slotContactAdded can't find contact";
} }
...@@ -1745,7 +1759,10 @@ ConversationModelPimpl::slotContactRemoved(const QString& uri) ...@@ -1745,7 +1759,10 @@ ConversationModelPimpl::slotContactRemoved(const QString& uri)
return; // Not a contact return; // Not a contact
} }
auto& conversationUid = conversations[conversationIdx].uid; auto& conversationUid = conversations[conversationIdx].uid;
Q_EMIT linked.beginRemoveRows(conversationIdx);
conversations.erase(conversations.begin() + conversationIdx); conversations.erase(conversations.begin() + conversationIdx);
Q_EMIT linked.endRemoveRows();
invalidateModel(); invalidateModel();
emit linked.modelChanged(); emit linked.modelChanged();
...@@ -1761,6 +1778,7 @@ ConversationModelPimpl::slotContactModelUpdated(const QString& uri, bool needsSo ...@@ -1761,6 +1778,7 @@ ConversationModelPimpl::slotContactModelUpdated(const QString& uri, bool needsSo
auto& conversation = getConversationForPeerUri(uri, true).get(); auto& conversation = getConversationForPeerUri(uri, true).get();
invalidateModel(); invalidateModel();
emit linked.conversationUpdated(conversation.uid); emit linked.conversationUpdated(conversation.uid);
Q_EMIT linked.dataChanged(indexOf(conversation.uid));
} catch (std::out_of_range&) { } catch (std::out_of_range&) {
qDebug() << "contact updated for not existing conversation"; qDebug() << "contact updated for not existing conversation";
} }
...@@ -1834,7 +1852,11 @@ ConversationModelPimpl::addConversationWith(const QString& convId, const QString ...@@ -1834,7 +1852,11 @@ ConversationModelPimpl::addConversationWith(const QString& convId, const QString
} }
conversation.unreadMessages = getNumberOfUnreadMessagesFor(convId); conversation.unreadMessages = getNumberOfUnreadMessagesFor(convId);
Q_EMIT linked.beginInsertRows(conversations.size());
conversations.emplace_back(std::move(conversation)); conversations.emplace_back(std::move(conversation));
Q_EMIT linked.endInsertRows();
invalidateModel(); invalidateModel();
} }
...@@ -1907,7 +1929,6 @@ ConversationModelPimpl::slotIncomingCall(const QString& fromId, const QString& c ...@@ -1907,7 +1929,6 @@ ConversationModelPimpl::slotIncomingCall(const QString& fromId, const QString& c
conversation.callId = callId; conversation.callId = callId;
addOrUpdateCallMessage(callId, fromId); addOrUpdateCallMessage(callId, fromId);
invalidateModel();
emit behaviorController.showIncomingCallView(linked.owner.id, conversation.uid); emit behaviorController.showIncomingCallView(linked.owner.id, conversation.uid);
} }
...@@ -1934,6 +1955,7 @@ ConversationModelPimpl::slotCallStatusChanged(const QString& callId, int code) ...@@ -1934,6 +1955,7 @@ ConversationModelPimpl::slotCallStatusChanged(const QString& callId, int code)
conversation.callId = callId; conversation.callId = callId;
invalidateModel(); invalidateModel();
emit linked.conversationUpdated(conversation.uid); emit linked.conversationUpdated(conversation.uid);
Q_EMIT linked.dataChanged(indexOf(conversation.uid));
} }
} }
} else if (call.status == call::Status::PEER_BUSY) { } else if (call.status == call::Status::PEER_BUSY) {
...@@ -1976,6 +1998,7 @@ ConversationModelPimpl::slotCallEnded(const QString& callId) ...@@ -1976,6 +1998,7 @@ ConversationModelPimpl::slotCallEnded(const QString& callId)
conversation.confId = ""; // The participant is detached conversation.confId = ""; // The participant is detached
invalidateModel(); invalidateModel();
emit linked.conversationUpdated(conversation.uid); emit linked.conversationUpdated(conversation.uid);
Q_EMIT linked.dataChanged(indexOf(conversation.uid));
} }
} catch (std::out_of_range& e) { } catch (std::out_of_range& e) {
qDebug() << "ConversationModelPimpl::slotCallEnded can't end inexistant call"; qDebug() << "ConversationModelPimpl::slotCallEnded can't end inexistant call";
...@@ -2026,6 +2049,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId, ...@@ -2026,6 +2049,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
invalidateModel(); invalidateModel();
emit linked.modelChanged(); emit linked.modelChanged();
Q_EMIT linked.dataChanged(static_cast<int>(std::distance(conversations.begin(), conv_it)));
} }
void void
...@@ -2109,6 +2133,7 @@ ConversationModelPimpl::addIncomingMessage(const QString& from, ...@@ -2109,6 +2133,7 @@ ConversationModelPimpl::addIncomingMessage(const QString& from,
invalidateModel(); invalidateModel();
emit linked.modelChanged(); emit linked.modelChanged();
Q_EMIT linked.dataChanged(conversationIdx);
return msgId; return msgId;
} }
...@@ -2447,6 +2472,7 @@ ConversationModelPimpl::slotTransferStatusCreated(long long dringId, datatransfe ...@@ -2447,6 +2472,7 @@ ConversationModelPimpl::slotTransferStatusCreated(long long dringId, datatransfe
invalidateModel(); invalidateModel();
emit linked.modelChanged(); emit linked.modelChanged();
Q_EMIT linked.dataChanged(conversationIdx);
} }
void void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment