From 2f112b300d2c5582b9a614ce3588d6d6879bcd1c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 12 Oct 2024 21:03:45 +0300 Subject: Telegram: fix for occasional crash --- protocols/Telegram/src/utils.cpp | 22 ++++++++++++++-------- src/mir_core/src/db.cpp | 17 ++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 627e11eda5..9ef0809d38 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -738,15 +738,21 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg } if (m_bSmileyAdd) { - const char *pwszFileExt; - switch (pSticker->format_->get_id()) { - case TD::stickerFormatTgs::ID: pwszFileExt = "tga"; break; - case TD::stickerFormatWebm::ID: pwszFileExt = "webm"; break; - case TD::stickerFormatWebp::ID: pwszFileExt = "webp"; break; - default:pwszFileExt = "jpeg"; break; + if (pSticker->thumbnail_.get()) { + const char *pwszFileExt; + switch (pSticker->format_->get_id()) { + case TD::stickerFormatTgs::ID: pwszFileExt = "tga"; break; + case TD::stickerFormatWebm::ID: pwszFileExt = "webm"; break; + case TD::stickerFormatWebp::ID: pwszFileExt = "webp"; break; + default: + pwszFileExt = "jpeg"; break; + } + ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt); + } + else { + debugLogA("Strange sticker without preview"); + ret.Append(pSticker->emoji_.c_str()); } - - ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt); } else ret.AppendFormat("%s: %s", TranslateU("SmileyAdd plugin required to support stickers"), pSticker->emoji_.c_str()); } diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index b691461e66..9527537a4d 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -485,16 +485,19 @@ MIR_CORE_DLL(int) db_event_markRead(MCONTACT hContact, MEVENT hDbEvent, bool bFr { if (g_pCurrDb == nullptr) return 1; - - if (!g_pCurrDb->MarkEventRead(hContact, hDbEvent)) - return 1; + // we received remote mark read command if (bFromServer) CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ); - else if (auto *ppro = Proto_GetInstance(hContact)) { - ppro->OnMarkRead(hContact, hDbEvent); - return 0; - } + + if (!g_pCurrDb->MarkEventRead(hContact, hDbEvent)) + return 1; + + if (!bFromServer) + if (auto *ppro = Proto_GetInstance(hContact)) { + ppro->OnMarkRead(hContact, hDbEvent); + return 0; + } return 1; } -- cgit v1.2.3