diff --git a/ui/models/account.cpp b/ui/models/account.cpp index f8d0c37..43cb3ed 100644 --- a/ui/models/account.cpp +++ b/ui/models/account.cpp @@ -31,7 +31,8 @@ Models::Account::Account(const QMap& data, Models::Item* pare avatarPath(data.value("avatarPath").toString()), state(Shared::ConnectionState::disconnected), availability(Shared::Availability::offline), - passwordType(Shared::AccountPassword::plain) + passwordType(Shared::AccountPassword::plain), + wasEverConnected(false) { QMap::const_iterator sItr = data.find("state"); if (sItr != data.end()) { @@ -56,8 +57,19 @@ void Models::Account::setState(Shared::ConnectionState p_state) if (state != p_state) { state = p_state; changed(2); - if (state == Shared::ConnectionState::disconnected) { - toOfflineState(); + switch (state) { + case Shared::ConnectionState::disconnected: + toOfflineState(); + break; + case Shared::ConnectionState::connected: + if (wasEverConnected) { + emit reconnected(); + } else { + wasEverConnected = true; + } + break; + default: + break; } } } diff --git a/ui/models/account.h b/ui/models/account.h index 686d4da..3d2310f 100644 --- a/ui/models/account.h +++ b/ui/models/account.h @@ -77,6 +77,9 @@ namespace Models { QString getBareJid() const; QString getFullJid() const; + signals: + void reconnected(); + private: QString login; QString password; @@ -87,6 +90,7 @@ namespace Models { Shared::ConnectionState state; Shared::Availability availability; Shared::AccountPassword passwordType; + bool wasEverConnected; protected slots: void toOfflineState() override; diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index d54fccf..a0c70ac 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -240,3 +240,9 @@ QString Models::Contact::getDisplayedName() const return getContactName(); } +void Models::Contact::handleRecconnect() +{ + if (getMessagesCount() > 0) { + feed->requestLatestMessages(); + } +} diff --git a/ui/models/contact.h b/ui/models/contact.h index 7e76f5b..a8b80a3 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -56,6 +56,8 @@ public: QString getStatus() const; QString getDisplayedName() const override; + void handleRecconnect(); //this is a special method Models::Roster calls when reconnect happens + protected: void _removeChild(int index) override; void _appendChild(Models::Item * child) override; diff --git a/ui/models/reference.cpp b/ui/models/reference.cpp index cb8efad..1aaea15 100644 --- a/ui/models/reference.cpp +++ b/ui/models/reference.cpp @@ -104,6 +104,8 @@ void Models::Reference::onChildChanged(Models::Item* item, int row, int col) { if (item == original) { emit childChanged(this, row, col); + } else { + emit childChanged(item, row, col); } } diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index d70d9d1..2d5f99f 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -48,6 +48,7 @@ Models::Roster::~Roster() void Models::Roster::addAccount(const QMap& data) { Account* acc = new Account(data); + connect(acc, &Account::reconnected, this, &Roster::onAccountReconnected); root->appendChild(acc); accounts.insert(std::make_pair(acc->getName(), acc)); accountsModel->addAccount(acc); @@ -744,6 +745,7 @@ void Models::Roster::removeAccount(const QString& account) } } + disconnect(acc, &Account::reconnected, this, &Roster::onAccountReconnected); acc->deleteLater(); } @@ -1003,3 +1005,15 @@ Models::Element * Models::Roster::getElement(const Models::Roster::ElId& id) return NULL; } +void Models::Roster::onAccountReconnected() +{ + Account* acc = static_cast(sender()); + + QString accName = acc->getName(); + for (const std::pair& pair : contacts) { + if (pair.first.account == accName) { + pair.second->handleRecconnect(); + } + } +} + diff --git a/ui/models/roster.h b/ui/models/roster.h index 09261cd..08d5afc 100644 --- a/ui/models/roster.h +++ b/ui/models/roster.h @@ -100,6 +100,7 @@ private: private slots: void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector& roles); + void onAccountReconnected(); void onChildChanged(Models::Item* item, int row, int col); void onChildIsAboutToBeInserted(Item* parent, int first, int last); void onChildInserted(); diff --git a/ui/widgets/messageline/messagedelegate.cpp b/ui/widgets/messageline/messagedelegate.cpp index 8405964..81018ac 100644 --- a/ui/widgets/messageline/messagedelegate.cpp +++ b/ui/widgets/messageline/messagedelegate.cpp @@ -353,6 +353,10 @@ void MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* paint previews->insert(std::make_pair(data.id, preview)); } + if (!preview->isFileReachable()) { //this is the situation when the file preview couldn't be painted because the file was moved + emit invalidPath(data.id); //or deleted. This signal notifies the model, and the model notifies the core, preview can + } //handle being invalid for as long as I need and can be even become valid again with a new path + option.rect.adjust(0, preview->size().height() + textMargin, 0, 0); } diff --git a/ui/widgets/messageline/messagefeed.cpp b/ui/widgets/messageline/messagefeed.cpp index 4f22113..9537ea5 100644 --- a/ui/widgets/messageline/messagefeed.cpp +++ b/ui/widgets/messageline/messagefeed.cpp @@ -304,7 +304,7 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const std::set::const_iterator umi = unreadMessages->find(item.id); if (umi != unreadMessages->end()) { unreadMessages->erase(umi); - emit unreadMessagesCount(); + emit unreadMessagesCountChanged(); } item.sentByMe = sentByMe(*msg); @@ -370,7 +370,6 @@ void Models::MessageFeed::fetchMore(const QModelIndex& parent) if (syncState == incomplete) { syncState = syncing; emit syncStateChange(syncState); - emit requestStateChange(true); if (storage.size() == 0) { emit requestArchive(""); @@ -398,7 +397,6 @@ void Models::MessageFeed::responseArchive(const std::list list, syncState = incomplete; } emit syncStateChange(syncState); - emit requestStateChange(false); } } @@ -656,3 +654,13 @@ Models::MessageFeed::SyncState Models::MessageFeed::getSyncState() const { return syncState; } + +void Models::MessageFeed::requestLatestMessages() +{ + if (syncState != syncing) { + syncState = syncing; + emit syncStateChange(syncState); + + emit requestArchive(""); + } +} diff --git a/ui/widgets/messageline/messagefeed.h b/ui/widgets/messageline/messagefeed.h index efb005a..b368a3d 100644 --- a/ui/widgets/messageline/messagefeed.h +++ b/ui/widgets/messageline/messagefeed.h @@ -77,11 +77,12 @@ public: void decrementObservers(); SyncState getSyncState() const; + void requestLatestMessages(); //this method is used by Models::Contact to request latest messages after reconnection + signals: void requestArchive(const QString& before); - void requestStateChange(bool requesting); void fileDownloadRequest(const QString& url); - void unreadMessagesCountChanged(); + void unreadMessagesCountChanged() const; void newMessage(const Shared::Message& msg); void unnoticedMessage(const Shared::Message& msg); void localPathInvalid(const QString& path);