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

View file

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

View file

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