fix bug when everything was treated as animation, bug with not working group amount of messages, handled the situation when preview is painted but the file was lost

This commit is contained in:
Blue 2021-05-17 00:52:59 +03:00
parent 0d584c5aba
commit 721f6daa36
Signed by: blue
GPG Key ID: 9B203B252A63EE38
10 changed files with 62 additions and 8 deletions

View File

@ -31,7 +31,8 @@ Models::Account::Account(const QMap<QString, QVariant>& 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<QString, QVariant>::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;
}
}
}

View File

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

View File

@ -240,3 +240,9 @@ QString Models::Contact::getDisplayedName() const
return getContactName();
}
void Models::Contact::handleRecconnect()
{
if (getMessagesCount() > 0) {
feed->requestLatestMessages();
}
}

View File

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

View File

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

View File

@ -48,6 +48,7 @@ Models::Roster::~Roster()
void Models::Roster::addAccount(const QMap<QString, QVariant>& 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<Account*>(sender());
QString accName = acc->getName();
for (const std::pair<const ElId, Contact*>& pair : contacts) {
if (pair.first.account == accName) {
pair.second->handleRecconnect();
}
}
}

View File

@ -100,6 +100,7 @@ private:
private slots:
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
void onAccountReconnected();
void onChildChanged(Models::Item* item, int row, int col);
void onChildIsAboutToBeInserted(Item* parent, int first, int last);
void onChildInserted();

View File

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

View File

@ -304,7 +304,7 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
std::set<QString>::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<Shared::Message> 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("");
}
}

View File

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