Fix crash on incoming message deletions & minor other fixes

This commit is contained in:
Sebastian Wolf 2020-12-28 14:35:27 +01:00
parent 2e970f2003
commit 225eb76899
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
3 changed files with 32 additions and 15 deletions

View file

@ -64,9 +64,9 @@ Item {
audioType = ( audioData['@type'] === "voiceNote" ) ? "voice" : "audio";
audioFileId = audioData[audioType].id;
if (typeof audioData.album_cover_thumbnail !== "undefined") {
previewFileId = audioData.album_cover_thumbnail.photo.id;
if (audioData.album_cover_thumbnail.photo.local.is_downloading_completed) {
placeholderImage.source = audioData.album_cover_thumbnail.photo.local.path;
previewFileId = audioData.album_cover_thumbnail.file.id;
if (audioData.album_cover_thumbnail.file.local.is_downloading_completed) {
placeholderImage.source = audioData.album_cover_thumbnail.file.local.path;
} else {
tdLibWrapper.downloadFile(previewFileId);
}
@ -94,7 +94,7 @@ Item {
if (typeof audioData === "object") {
if (fileInformation.local.is_downloading_completed) {
if (fileId === previewFileId) {
audioData.thumbnail.photo = fileInformation;
audioData.album_cover_thumbnail.file = fileInformation;
placeholderImage.source = fileInformation.local.path;
}
if (fileId === audioFileId) {

View file

@ -52,6 +52,10 @@ Page {
Debug.log(JSON.stringify(chats));
chatsFound = chats;
}
onErrorReceived: {
searchChatsPage.isLoading = false;
Functions.handleErrorMessage(code, message);
}
}
property bool isLoading: false;

View file

@ -480,27 +480,40 @@ void ChatModel::handleMessagesDeleted(qlonglong chatId, const QList<qlonglong> &
if (chatId == this->chatId) {
const int count = messageIds.size();
LOG(count << "messages in this chat were deleted...");
int firstDeleted = -1, lastDeleted = -2;
for (int i = 0; i < count; i++) {
const int pos = messageIndexMap.value(messageIds.at(i), -1);
if (pos >= 0) {
if (pos == lastDeleted + 1) {
lastDeleted = pos; // Extend the current range
int firstPosition = count, lastPosition = count;
for (int i = (count - 1); i > -1; i--) {
const int position = messageIndexMap.value(messageIds.at(i), -1);
if (position >= 0) {
// We found at least one message in our list that needs to be deleted
if (lastPosition == count) {
lastPosition = position;
}
if (firstPosition == count) {
firstPosition = position;
}
if (position < (firstPosition - 1)) {
// Some gap in between, can remove previous range and reset positions
removeRange(firstPosition, lastPosition);
firstPosition = lastPosition = position;
} else {
removeRange(firstDeleted, lastDeleted);
firstDeleted = lastDeleted = pos; // Start new range
// No gap in between, extend the range and continue loop
firstPosition = position;
}
}
}
// Handle the last (and likely the only) range
removeRange(firstDeleted, lastDeleted);
// After all elements have been processed, there may be one last range to remove
// But only if we found at least one item to remove
if (firstPosition != count && lastPosition != count) {
removeRange(firstPosition, lastPosition);
}
}
}
void ChatModel::removeRange(int firstDeleted, int lastDeleted)
{
if (firstDeleted >= 0 && firstDeleted <= lastDeleted) {
LOG("Removing range" << firstDeleted << "..." << lastDeleted);
LOG("Removing range" << firstDeleted << "..." << lastDeleted << "| current messages size" << messages.size());
beginRemoveRows(QModelIndex(), firstDeleted, lastDeleted);
for (int i = firstDeleted; i <= lastDeleted; i++) {
MessageData *message = messages.at(i);