[SMS App] Prevent crash if a conversation doesn't have any messages

## Summary

Fix crash in kdeconnect-sms if a conversation contains a message which has no addresses.

I am not sure why this would happen and there's probably something which should be fixed on the Android side to ensure that every message has addresses, but this is an easy fix to prevent user-reported crashes.

BUG: 449719

## Test Plan

### Before:
kdeconnect-sms crashes upon selecting a conversation with a message with no addresses

### After:
kdeconnect-sms does not crash
This commit is contained in:
Simon Redman 2022-03-06 22:56:18 +00:00
parent 035a0d6ca8
commit 3ee78eadd7

View file

@ -142,7 +142,15 @@ void ConversationModel::createRowFromMessage(const ConversationMessage& message,
return;
}
ConversationAddress sender = message.addresses().first();
ConversationAddress sender;
if (!message.addresses().isEmpty()) {
sender = message.addresses().first();
}
else {
qCDebug(KDECONNECT_SMS_CONVERSATION_MODEL)
<< "Conversation with ID " << message.threadID() << " did not have any addresses";
}
QString senderName = message.isIncoming() ? SmsHelper::getTitleForAddresses({sender}) : QString();
QString displayBody = message.body();