Commit 5869fd7f authored by Ronan's avatar Ronan

fix(Timeline): update correctly the timeline when the last chat message of one chat room is removed

parent ef1a3f8d
Pipeline #85 failed with stage
in 0 seconds
......@@ -277,6 +277,8 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
if (mEntries.count() == 0)
emit allEntriesRemoved();
else if (limit == mEntries.count())
emit lastEntryRemoved();
return true;
}
......
......@@ -109,6 +109,7 @@ signals:
bool isRemoteComposingChanged (bool status);
void allEntriesRemoved ();
void lastEntryRemoved ();
void messageSent (const std::shared_ptr<linphone::ChatMessage> &message);
void messageReceived (const std::shared_ptr<linphone::ChatMessage> &message);
......
......@@ -238,14 +238,16 @@ void SipAddressesModel::handleChatModelCreated (const shared_ptr<ChatModel> &cha
ChatModel *ptr = chatModel.get();
QObject::connect(ptr, &ChatModel::allEntriesRemoved, this, [this, ptr] {
handleAllEntriesRemoved(ptr->getSipAddress());
handleAllEntriesRemoved(ptr);
});
QObject::connect(ptr, &ChatModel::lastEntryRemoved, this, [this, ptr] {
handleLastEntryRemoved(ptr);
});
QObject::connect(ptr, &ChatModel::messageSent, this, &SipAddressesModel::handleMessageSent);
QObject::connect(ptr, &ChatModel::messagesCountReset, this, [this, ptr] {
handleMessagesCountReset(ptr->getSipAddress());
handleMessagesCountReset(ptr);
});
QObject::connect(ptr, &ChatModel::messageSent, this, &SipAddressesModel::handleMessageSent);
}
void SipAddressesModel::handleContactAdded (ContactModel *contact) {
......@@ -331,12 +333,10 @@ void SipAddressesModel::handlePresenceReceived (
updateObservers(sipAddress, status);
}
void SipAddressesModel::handleAllEntriesRemoved (const QString &sipAddress) {
auto it = mSipAddresses.find(sipAddress);
if (it == mSipAddresses.end()) {
qWarning() << QStringLiteral("Unable to find sip address: `%1`.").arg(sipAddress);
void SipAddressesModel::handleAllEntriesRemoved (ChatModel *chatModel) {
auto it = mSipAddresses.find(chatModel->getSipAddress());
if (it == mSipAddresses.end())
return;
}
int row = mRefs.indexOf(&(*it));
Q_ASSERT(row != -1);
......@@ -347,19 +347,31 @@ void SipAddressesModel::handleAllEntriesRemoved (const QString &sipAddress) {
return;
}
// Signal changes.
it->remove("timestamp");
emit dataChanged(index(row, 0), index(row, 0));
}
void SipAddressesModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &message) {
addOrUpdateSipAddress(
Utils::coreStringToAppString(message->getToAddress()->asStringUriOnly()),
message
);
void SipAddressesModel::handleLastEntryRemoved (ChatModel *chatModel) {
auto it = mSipAddresses.find(chatModel->getSipAddress());
if (it == mSipAddresses.end())
return;
int row = mRefs.indexOf(&(*it));
Q_ASSERT(row != -1);
Q_ASSERT(chatModel->rowCount() > 0);
const QVariantMap map = chatModel->data(
chatModel->index(chatModel->rowCount() - 1, 0),
ChatModel::ChatEntry
).toMap();
// Update the timestamp with the new last chat message timestamp.
(*it)["timestamp"] = map["timestamp"];
emit dataChanged(index(row, 0), index(row, 0));
}
void SipAddressesModel::handleMessagesCountReset (const QString &sipAddress) {
void SipAddressesModel::handleMessagesCountReset (ChatModel *chatModel) {
const QString &sipAddress = chatModel->getSipAddress();
auto it = mSipAddresses.find(sipAddress);
if (it != mSipAddresses.end()) {
(*it)["unreadMessagesCount"] = 0;
......@@ -372,6 +384,13 @@ void SipAddressesModel::handleMessagesCountReset (const QString &sipAddress) {
updateObservers(sipAddress, 0);
}
void SipAddressesModel::handleMessageSent (const shared_ptr<linphone::ChatMessage> &message) {
addOrUpdateSipAddress(
Utils::coreStringToAppString(message->getToAddress()->asStringUriOnly()),
message
);
}
void SipAddressesModel::handlerIsComposingChanged (const shared_ptr<linphone::ChatRoom> &chatRoom) {
auto it = mSipAddresses.find(Utils::coreStringToAppString(chatRoom->getPeerAddress()->asStringUriOnly()));
if (it != mSipAddresses.end()) {
......
......@@ -84,9 +84,11 @@ private:
void handleCallStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
void handlePresenceReceived (const QString &sipAddress, const std::shared_ptr<const linphone::PresenceModel> &presenceModel);
void handleAllEntriesRemoved (const QString &sipAddress);
void handleAllEntriesRemoved (ChatModel *chatModel);
void handleLastEntryRemoved (ChatModel *chatModel);
void handleMessagesCountReset (ChatModel *chatModel);
void handleMessageSent (const std::shared_ptr<linphone::ChatMessage> &message);
void handleMessagesCountReset (const QString &sipAddress);
void handlerIsComposingChanged (const std::shared_ptr<linphone::ChatRoom> &chatRoom);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment