forked from blue/squawk
handled a case when user removes downloaded file, minor optimizations on message changing
This commit is contained in:
parent
b44873d587
commit
50190f3eac
23 changed files with 136 additions and 40 deletions
|
@ -33,6 +33,7 @@ Models::Element::Element(Type p_type, const Models::Account* acc, const QString&
|
|||
connect(feed, &MessageFeed::fileDownloadRequest, this, &Element::fileDownloadRequest);
|
||||
connect(feed, &MessageFeed::unreadMessagesCountChanged, this, &Element::onFeedUnreadMessagesCountChanged);
|
||||
connect(feed, &MessageFeed::unnoticedMessage, this, &Element::onFeedUnnoticedMessage);
|
||||
connect(feed, &MessageFeed::localPathInvalid, this, &Element::localPathInvalid);
|
||||
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
|
|
|
@ -51,6 +51,7 @@ signals:
|
|||
void requestArchive(const QString& before);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
||||
void localPathInvalid(const QString& path);
|
||||
|
||||
protected:
|
||||
void setJid(const QString& p_jid);
|
||||
|
|
|
@ -116,37 +116,39 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, Q
|
|||
}
|
||||
}
|
||||
|
||||
//change message is a final event in download/upload event train
|
||||
//only after changeMessage we can consider the download is done
|
||||
Progress::const_iterator dItr = downloads.find(id);
|
||||
bool attachOrError = changeRoles.count(MessageRoles::Attach) > 0 || changeRoles.count(MessageRoles::Error);
|
||||
if (dItr != downloads.end()) {
|
||||
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 (changeRoles.size() > 0) {
|
||||
//change message is a final event in download/upload event train
|
||||
//only after changeMessage we can consider the download is done
|
||||
Progress::const_iterator dItr = downloads.find(id);
|
||||
bool attachOrError = changeRoles.count(MessageRoles::Attach) > 0 || changeRoles.count(MessageRoles::Error);
|
||||
if (dItr != downloads.end()) {
|
||||
if (attachOrError) {
|
||||
uploads.erase(dItr);
|
||||
downloads.erase(dItr);
|
||||
} else if (changeRoles.count(MessageRoles::Id) > 0) {
|
||||
qreal progress = dItr->second;
|
||||
uploads.erase(dItr);
|
||||
uploads.insert(std::make_pair(msg->getId(), progress));
|
||||
downloads.erase(dItr);
|
||||
downloads.insert(std::make_pair(msg->getId(), progress));
|
||||
}
|
||||
} else {
|
||||
dItr = uploads.find(id);
|
||||
if (dItr != uploads.end()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<int> cr;
|
||||
for (MessageRoles role : changeRoles) {
|
||||
cr.push_back(role);
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, cr);
|
||||
}
|
||||
|
||||
QVector<int> cr;
|
||||
for (MessageRoles role : changeRoles) {
|
||||
cr.push_back(role);
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, cr);
|
||||
}
|
||||
|
||||
std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const
|
||||
|
@ -174,13 +176,13 @@ std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(c
|
|||
|
||||
if (state == Shared::Message::State::error) {
|
||||
itr = data.find("errorText");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end() && itr.value().toString() != msg.getErrorText()) {
|
||||
roles.insert(MessageRoles::Error);
|
||||
}
|
||||
}
|
||||
|
||||
itr = data.find("body");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end() && itr.value().toString() != msg.getBody()) {
|
||||
QMap<QString, QVariant>::const_iterator dItr = data.find("stamp");
|
||||
QDateTime correctionDate;
|
||||
if (dItr != data.end()) {
|
||||
|
@ -522,3 +524,22 @@ QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDate
|
|||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId)
|
||||
{
|
||||
StorageById::iterator itr = indexById.find(messageId);
|
||||
if (itr == indexById.end()) {
|
||||
qDebug() << "received a command to change a message, but the message couldn't be found, skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
Shared::Message* msg = *itr;
|
||||
|
||||
emit localPathInvalid(msg->getAttachPath());
|
||||
|
||||
//gonna change the message in current model right away, to prevent spam on each attemt to draw element
|
||||
QModelIndex index = modelIndexByTime(messageId, msg->getTime());
|
||||
msg->setAttachPath("");
|
||||
|
||||
emit dataChanged(index, index, {MessageRoles::Attach});
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void downloadAttachment(const QString& messageId);
|
||||
void uploadAttachment(const QString& messageId);
|
||||
bool registerUpload(const QString& messageId);
|
||||
void reportLocalPathInvalid(const QString& messageId);
|
||||
|
||||
unsigned int unreadMessagesCount() const;
|
||||
void fileProgress(const QString& messageId, qreal value, bool up);
|
||||
|
@ -76,6 +77,7 @@ signals:
|
|||
void unreadMessagesCountChanged();
|
||||
void newMessage(const Shared::Message& msg);
|
||||
void unnoticedMessage(const Shared::Message& msg);
|
||||
void localPathInvalid(const QString& path);
|
||||
|
||||
public:
|
||||
enum MessageRoles {
|
||||
|
|
|
@ -449,6 +449,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
connect(contact, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(contact, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
connect(contact, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage);
|
||||
connect(contact, &Contact::localPathInvalid, this, &Roster::localPathInvalid);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
} else {
|
||||
contact = itr->second;
|
||||
|
@ -787,6 +788,7 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
|
|||
connect(room, &Contact::requestArchive, this, &Roster::onElementRequestArchive);
|
||||
connect(room, &Contact::fileDownloadRequest, this, &Roster::fileDownloadRequest);
|
||||
connect(room, &Contact::unnoticedMessage, this, &Roster::unnoticedMessage);
|
||||
connect(room, &Contact::localPathInvalid, this, &Roster::localPathInvalid);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ signals:
|
|||
void requestArchive(const QString& account, const QString& jid, const QString& before);
|
||||
void fileDownloadRequest(const QString& url);
|
||||
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
||||
void localPathInvalid(const QString& path);
|
||||
|
||||
private:
|
||||
Element* getElement(const ElId& id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue