some debug, message changing in messageFeed

This commit is contained in:
Blue 2021-04-20 00:49:24 +03:00
parent 3a7735b192
commit 48e498be25
10 changed files with 107 additions and 35 deletions

View file

@ -143,7 +143,7 @@ void Models::Element::addMessage(const Shared::Message& data)
void Models::Element::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
{
feed->changeMessage(id, data);
}
void Models::Element::responseArchive(const std::list<Shared::Message> list, bool last)

View file

@ -76,8 +76,44 @@ void Models::MessageFeed::addMessage(const Shared::Message& msg)
endInsertRows();
}
void Models::MessageFeed::changeMessage(const QString& id, const Shared::Message& msg)
void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, QVariant>& data)
{
StorageById::iterator itr = indexById.find(id);
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;
QModelIndex index = modelIndexByTime(id, msg->getTime());
Shared::Message::Change functor(data);
bool success = indexById.modify(itr, functor);
if (!success) {
qDebug() << "received a command to change a message, but something went wrong modifying message in the feed, throwing error";
throw 872;
}
if (functor.hasIdBeenModified()) {
}
//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);
if (dItr != downloads.end()) {
if (dItr->second == 1) {
downloads.erase(dItr);
}
} else {
dItr = uploads.find(id);
if (dItr != uploads.end()) {
if (dItr->second == 1) {
uploads.erase(dItr);
}
}
}
emit dataChanged(index, index);
}
void Models::MessageFeed::removeMessage(const QString& id)
@ -338,7 +374,7 @@ void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bo
void Models::MessageFeed::fileComplete(const QString& messageId, bool up)
{
//TODO
fileProgress(messageId, 1, up);
}
void Models::MessageFeed::fileError(const QString& messageId, const QString& error, bool up)
@ -352,11 +388,29 @@ QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
StorageById::const_iterator itr = indexById.find(id);
if (itr != indexById.end()) {
Shared::Message* msg = *itr;
StorageByTime::const_iterator tItr = indexByTime.upper_bound(msg->getTime());
int position = indexByTime.rank(tItr);
return createIndex(position, 0, msg);
} else {
return QModelIndex();
return modelIndexByTime(id, msg->getTime());
}
return QModelIndex();
}
QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDateTime& time) const
{
StorageByTime::const_iterator tItr = indexByTime.upper_bound(time);
StorageByTime::const_iterator tBeg = indexByTime.begin();
bool found = false;
while (tItr != tBeg) {
if (id == (*tItr)->getId()) {
found = true;
break;
}
--tItr;
}
if (found) {
int position = indexByTime.rank(tItr);
return createIndex(position, 0, *tItr);
}
return QModelIndex();
}

View file

@ -44,7 +44,7 @@ public:
~MessageFeed();
void addMessage(const Shared::Message& msg);
void changeMessage(const QString& id, const Shared::Message& msg);
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
void removeMessage(const QString& id);
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
@ -72,6 +72,7 @@ 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;
public:
enum MessageRoles {