From cc80e69644be8bfa9cfaf1de4a6b06d8157ff401 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 27 May 2023 09:07:53 -0400 Subject: [PATCH] Add better checks when the pack is omitted from im.ponies.room_emotes This field is omittable, and I hit it this morning. Let's check if it's filled before using it. --- src/models/imagepacksmodel.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/models/imagepacksmodel.cpp b/src/models/imagepacksmodel.cpp index be4a3077f..16f1c2d55 100644 --- a/src/models/imagepacksmodel.cpp +++ b/src/models/imagepacksmodel.cpp @@ -102,12 +102,13 @@ void ImagePacksModel::reloadImages() const auto &stickerRoom = m_room->connection()->room(roomId); for (const auto &packKey : packs.keys()) { #ifdef QUOTIENT_07 - const auto &pack = stickerRoom->currentState().get(packKey); - if (pack) { + if (const auto &pack = stickerRoom->currentState().get(packKey)) { const auto packContent = pack->content(); - if (!packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons()) - || (packContent.pack->usage->contains("sticker") && showStickers())) { - m_events += packContent; + if (packContent.pack.has_value()) { + if (!packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons()) + || (packContent.pack->usage->contains("sticker") && showStickers())) { + m_events += packContent; + } } } #endif @@ -118,9 +119,11 @@ void ImagePacksModel::reloadImages() auto events = m_room->currentState().eventsOfType("im.ponies.room_emotes"); for (const auto &event : events) { auto packContent = eventCast(event)->content(); - if (!packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons()) - || (packContent.pack->usage->contains("sticker") && showStickers())) { - m_events += packContent; + if (packContent.pack.has_value()) { + if (!packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons()) + || (packContent.pack->usage->contains("sticker") && showStickers())) { + m_events += packContent; + } } } #endif