a crash fix on one of archive corner cases

This commit is contained in:
Blue 2022-04-17 16:25:15 +03:00
parent 8f949277f6
commit 4c20a314f0
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
2 changed files with 19 additions and 10 deletions

View File

@ -4,6 +4,7 @@
### Bug fixes ### Bug fixes
- now when you remove an account it actually gets removed - now when you remove an account it actually gets removed
- segfault on unitialized Availability in some rare occesions - segfault on unitialized Availability in some rare occesions
- fixed crash when you open a dialog with someone that has only error messages in archive
### Improvements ### Improvements
- there is a way to disable an account and it wouldn't connect when you change availability - there is a way to disable an account and it wouldn't connect when you change availability

View File

@ -124,15 +124,19 @@ void Core::RosterItem::nextRequest()
if (requestedCount != -1) { if (requestedCount != -1) {
bool last = false; bool last = false;
if (archiveState == beginning || archiveState == complete) { if (archiveState == beginning || archiveState == complete) {
QString firstId = archive->oldestId(); try {
if (responseCache.size() == 0) { QString firstId = archive->oldestId();
if (requestedBefore == firstId) { if (responseCache.size() == 0) {
last = true; if (requestedBefore == firstId) {
} last = true;
} else { }
if (responseCache.front().getId() == firstId) { } else {
last = true; if (responseCache.front().getId() == firstId) {
last = true;
}
} }
} catch (const Archive::Empty& e) {
last = true;
} }
} else if (archiveState == empty && responseCache.size() == 0) { } else if (archiveState == empty && responseCache.size() == 0) {
last = true; last = true;
@ -171,8 +175,12 @@ void Core::RosterItem::performRequest(int count, const QString& before)
requestCache.emplace_back(requestedCount, before); requestCache.emplace_back(requestedCount, before);
requestedCount = -1; requestedCount = -1;
} }
Shared::Message msg = archive->newest(); try {
emit needHistory("", getId(msg), msg.getTime()); Shared::Message msg = archive->newest();
emit needHistory("", getId(msg), msg.getTime());
} catch (const Archive::Empty& e) { //this can happen when the only message in archive is not server stored (error, for example)
emit needHistory(before, "");
}
} }
break; break;
case end: case end: