1
0
forked from blue/squawk

First attemtps to upload files, debug, reused of once uploaded or downloaded files

This commit is contained in:
Blue 2021-04-23 14:53:48 +03:00
parent d936c0302d
commit 8310708c92
7 changed files with 59 additions and 32 deletions

View File

@ -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<QString, QVariant> 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<QXmppMessage::Type>(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<uint>(data.getState())},
{"errorText", data.getErrorText()}
});
Shared::Message::State mstate = data.getState();
changes.insert("state", static_cast<uint>(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)

View File

@ -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 (...) {

View File

@ -46,6 +46,7 @@ public:
delivered,
error
};
static const State StateHighest = State::error;
static const State StateLowest = State::pending;

View File

@ -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;

View File

@ -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,

View File

@ -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();

View File

@ -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: