diff --git a/core/handlers/messagehandler.cpp b/core/handlers/messagehandler.cpp index 7644982..171a424 100644 --- a/core/handlers/messagehandler.cpp +++ b/core/handlers/messagehandler.cpp @@ -253,7 +253,9 @@ void Core::MessageHandler::performSending(Shared::Message data) { QString jid = data.getPenPalJid(); QString id = data.getId(); + QString oob = data.getOutOfBandUrl(); RosterItem* ri = acc->rh->getRosterItem(jid); + QMap changes; if (acc->state == Shared::ConnectionState::connected) { QXmppMessage msg(acc->getFullJid(), data.getTo(), data.getBody(), data.getThread()); @@ -262,7 +264,7 @@ void Core::MessageHandler::performSending(Shared::Message data) #endif msg.setId(id); msg.setType(static_cast(data.getType())); //it is safe here, my type is compatible - msg.setOutOfBandUrl(data.getOutOfBandUrl()); + msg.setOutOfBandUrl(oob); msg.setReceiptRequested(true); bool sent = acc->client.sendPacket(msg); @@ -286,10 +288,16 @@ void Core::MessageHandler::performSending(Shared::Message data) data.setErrorText("You are is offline or reconnecting"); } - emit acc->changeMessage(jid, id, { - {"state", static_cast(data.getState())}, - {"errorText", data.getErrorText()} - }); + Shared::Message::State mstate = data.getState(); + changes.insert("state", static_cast(mstate)); + if (mstate == Shared::Message::State::error) { + changes.insert("errorText", data.getErrorText()); + } + if (oob.size() > 0) { + changes.insert("outOfBandUrl", oob); + } + + emit acc->changeMessage(jid, id, changes); } void Core::MessageHandler::prepareUpload(const Shared::Message& data) diff --git a/core/networkaccess.cpp b/core/networkaccess.cpp index f178068..d771dc6 100644 --- a/core/networkaccess.cpp +++ b/core/networkaccess.cpp @@ -373,7 +373,7 @@ QString Core::NetworkAccess::getFileRemoteUrl(const QString& path) QString p; try { - QString p = storage.getUrl(path); + p = storage.getUrl(path); } catch (const Archive::NotFound& err) { } catch (...) { diff --git a/shared/message.h b/shared/message.h index c2766b3..aa91af6 100644 --- a/shared/message.h +++ b/shared/message.h @@ -46,6 +46,7 @@ public: delivered, error }; + static const State StateHighest = State::error; static const State StateLowest = State::pending; diff --git a/ui/models/messagefeed.cpp b/ui/models/messagefeed.cpp index a591657..c3a7923 100644 --- a/ui/models/messagefeed.cpp +++ b/ui/models/messagefeed.cpp @@ -86,7 +86,7 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap changeRoles = detectChanges(*msg, data); + std::set changeRoles = detectChanges(*msg, data); QModelIndex index = modelIndexByTime(id, msg->getTime()); Shared::Message::Change functor(data); bool success = indexById.modify(itr, functor); @@ -96,55 +96,69 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap 0 || changeRoles.count(MessageRoles::Error); if (dItr != downloads.end()) { - if (dItr->second == 1) { + if (attachOrError) { downloads.erase(dItr); + } else if (changeRoles.count(MessageRoles::Id) > 0) { + qreal progress = dItr->second; + downloads.erase(dItr); + downloads.insert(std::make_pair(msg->getId(), progress)); } } else { dItr = uploads.find(id); if (dItr != uploads.end()) { - if (dItr->second == 1) { + if (attachOrError) { uploads.erase(dItr); + } else if (changeRoles.count(MessageRoles::Id) > 0) { + qreal progress = dItr->second; + uploads.erase(dItr); + uploads.insert(std::make_pair(msg->getId(), progress)); } } } - emit dataChanged(index, index, changeRoles); + QVector cr; + for (MessageRoles role : changeRoles) { + cr.push_back(role); + } + + emit dataChanged(index, index, cr); } -QVector Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap& data) const +std::set Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap& data) const { - QVector roles; + std::set roles; Shared::Message::State state = msg.getState(); QMap::const_iterator itr = data.find("state"); if (itr != data.end() && static_cast(itr.value().toUInt()) != state) { - roles.push_back(MessageRoles::DeliveryState); + roles.insert(MessageRoles::DeliveryState); } itr = data.find("outOfBandUrl"); bool att = false; if (itr != data.end() && itr.value().toString() != msg.getOutOfBandUrl()) { - roles.push_back(MessageRoles::Attach); + roles.insert(MessageRoles::Attach); att = true; } if (!att) { itr = data.find("attachPath"); if (itr != data.end() && itr.value().toString() != msg.getAttachPath()) { - roles.push_back(MessageRoles::Attach); + roles.insert(MessageRoles::Attach); } } if (state == Shared::Message::State::error) { itr = data.find("errorText"); if (itr != data.end()) { - roles.push_back(MessageRoles::Error); + roles.insert(MessageRoles::Error); } } @@ -158,8 +172,8 @@ QVector Models::MessageFeed::detectChanges(const Shared::Message& msg, cons correctionDate = QDateTime::currentDateTimeUtc(); //in case there is no information about time of this correction it's applied } if (!msg.getEdited() || msg.getLastModified() < correctionDate) { - roles.push_back(MessageRoles::Text); - roles.push_back(MessageRoles::Correction); + roles.insert(MessageRoles::Text); + roles.insert(MessageRoles::Correction); } } @@ -410,6 +424,11 @@ void Models::MessageFeed::uploadAttachment(const QString& messageId) qDebug() << "request to upload attachment of the message" << messageId; } +bool Models::MessageFeed::registerUpload(const QString& messageId) +{ + return uploads.insert(std::make_pair(messageId, 0)).second; +} + void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bool up) { Progress* pr = 0; diff --git a/ui/models/messagefeed.h b/ui/models/messagefeed.h index f5b27b2..c86df33 100644 --- a/ui/models/messagefeed.h +++ b/ui/models/messagefeed.h @@ -23,6 +23,8 @@ #include #include +#include + #include #include #include @@ -57,6 +59,7 @@ public: void responseArchive(const std::list list, bool last); void downloadAttachment(const QString& messageId); void uploadAttachment(const QString& messageId); + bool registerUpload(const QString& messageId); unsigned int unreadMessagesCount() const; void fileProgress(const QString& messageId, qreal value, bool up); @@ -68,13 +71,6 @@ signals: void requestStateChange(bool requesting); void fileDownloadRequest(const QString& url); -protected: - bool sentByMe(const Shared::Message& msg) const; - Attachment fillAttach(const Shared::Message& msg) const; - QModelIndex modelIndexById(const QString& id) const; - QModelIndex modelIndexByTime(const QString& id, const QDateTime& time) const; - QVector detectChanges(const Shared::Message& msg, const QMap& data) const; - public: enum MessageRoles { Text = Qt::UserRole + 1, @@ -90,6 +86,13 @@ public: Bulk }; +protected: + bool sentByMe(const Shared::Message& msg) const; + Attachment fillAttach(const Shared::Message& msg) const; + QModelIndex modelIndexById(const QString& id) const; + QModelIndex modelIndexByTime(const QString& id, const QDateTime& time) const; + std::set detectChanges(const Shared::Message& msg, const QMap& data) const; + private: enum SyncState { incomplete, diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 017b9ba..d6e3c9a 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -33,6 +33,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el, QWidget(parent), isMuc(muc), account(acc), + element(el), palJid(pJid), activePalResource(pRes), m_ui(new Ui::Conversation()), @@ -162,11 +163,6 @@ QString Conversation::getJid() const return palJid; } -void Conversation::changeMessage(const QString& id, const QMap& data) -{ -// line->changeMessage(id, data); -} - KeyEnterReceiver::KeyEnterReceiver(QObject* parent): QObject(parent), ownEvent(false) {} bool KeyEnterReceiver::eventFilter(QObject* obj, QEvent* event) @@ -220,6 +216,7 @@ void Conversation::onEnterPressed() for (Badge* badge : filesToAttach) { Shared::Message msg = createMessage(); msg.setAttachPath(badge->id); + element->feed->registerUpload(msg.getId()); emit sendMessage(msg); } clearAttachedFiles(); diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 7d10aff..b506e39 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -73,7 +73,6 @@ public: void fileError(const QString& messageId, const QString& error); void responseFileProgress(const QString& messageId, qreal progress); virtual void setAvatar(const QString& path); - void changeMessage(const QString& id, const QMap& data); void setFeedFrames(bool top, bool right, bool bottom, bool left); signals: