forked from blue/squawk
First attemtps to upload files, debug, reused of once uploaded or downloaded files
This commit is contained in:
parent
d936c0302d
commit
8310708c92
7 changed files with 59 additions and 32 deletions
|
@ -86,7 +86,7 @@ void Models::MessageFeed::changeMessage(const QString& id, const QMap<QString, Q
|
|||
}
|
||||
|
||||
Shared::Message* msg = *itr;
|
||||
QVector<int> changeRoles = detectChanges(*msg, data);
|
||||
std::set<MessageRoles> 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<QString, Q
|
|||
}
|
||||
|
||||
if (functor.hasIdBeenModified()) {
|
||||
changeRoles.push_back(MessageRoles::Id);
|
||||
changeRoles.insert(MessageRoles::Id);
|
||||
}
|
||||
|
||||
//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 (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<int> cr;
|
||||
for (MessageRoles role : changeRoles) {
|
||||
cr.push_back(role);
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, cr);
|
||||
}
|
||||
|
||||
QVector<int> Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const
|
||||
std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const
|
||||
{
|
||||
QVector<int> roles;
|
||||
std::set<MessageRoles> roles;
|
||||
Shared::Message::State state = msg.getState();
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("state");
|
||||
if (itr != data.end() && static_cast<Shared::Message::State>(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<int> 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;
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <boost/multi_index_container.hpp>
|
||||
#include <boost/multi_index/ordered_index.hpp>
|
||||
#include <boost/multi_index/ranked_index.hpp>
|
||||
|
@ -57,6 +59,7 @@ public:
|
|||
void responseArchive(const std::list<Shared::Message> 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<int> detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& 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<MessageRoles> detectChanges(const Shared::Message& msg, const QMap<QString, QVariant>& data) const;
|
||||
|
||||
private:
|
||||
enum SyncState {
|
||||
incomplete,
|
||||
|
|
|
@ -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<QString, QVariant>& 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();
|
||||
|
|
|
@ -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<QString, QVariant>& data);
|
||||
void setFeedFrames(bool top, bool right, bool bottom, bool left);
|
||||
|
||||
signals:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue