"Fossies" - the Fresh Open Source Software Archive

Member "tdesktop-2.6.1/Telegram/SourceFiles/api/api_hash.cpp" (24 Feb 2021, 2642 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "api_hash.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2 This file is part of Telegram Desktop,
    3 the official desktop application for the Telegram messaging service.
    4 
    5 For license and copyright information please follow this link:
    6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
    7 */
    8 #include "api/api_hash.h"
    9 
   10 #include "data/data_document.h"
   11 #include "data/data_session.h"
   12 #include "data/stickers/data_stickers.h"
   13 #include "main/main_session.h"
   14 
   15 namespace Api {
   16 namespace {
   17 
   18 [[nodiscard]] int32 CountDocumentVectorHash(
   19         const QVector<DocumentData*> vector) {
   20     auto result = HashInit();
   21     for (const auto document : vector) {
   22         HashUpdate(result, document->id);
   23     }
   24     return HashFinalize(result);
   25 }
   26 
   27 [[nodiscard]] int32 CountSpecialStickerSetHash(
   28         not_null<Main::Session*> session,
   29         uint64 setId) {
   30     const auto &sets = session->data().stickers().sets();
   31     const auto it = sets.find(setId);
   32     if (it != sets.cend()) {
   33         return CountDocumentVectorHash(it->second->stickers);
   34     }
   35     return 0;
   36 }
   37 
   38 } // namespace
   39 
   40 int32 CountStickersHash(
   41         not_null<Main::Session*> session,
   42         bool checkOutdatedInfo) {
   43     auto result = HashInit();
   44     bool foundOutdated = false;
   45     const auto &sets = session->data().stickers().sets();
   46     const auto &order = session->data().stickers().setsOrder();
   47     for (auto i = order.cbegin(), e = order.cend(); i != e; ++i) {
   48         auto it = sets.find(*i);
   49         if (it != sets.cend()) {
   50             const auto set = it->second.get();
   51             if (set->id == Data::Stickers::DefaultSetId) {
   52                 foundOutdated = true;
   53             } else if (!(set->flags & MTPDstickerSet_ClientFlag::f_special)
   54                 && !(set->flags & MTPDstickerSet::Flag::f_archived)) {
   55                 HashUpdate(result, set->hash);
   56             }
   57         }
   58     }
   59     return (!checkOutdatedInfo || !foundOutdated)
   60         ? HashFinalize(result)
   61         : 0;
   62 }
   63 
   64 int32 CountRecentStickersHash(not_null<Main::Session*> session) {
   65     return CountSpecialStickerSetHash(
   66         session,
   67         Data::Stickers::CloudRecentSetId);
   68 }
   69 
   70 int32 CountFavedStickersHash(not_null<Main::Session*> session) {
   71     return CountSpecialStickerSetHash(session, Data::Stickers::FavedSetId);
   72 }
   73 
   74 int32 CountFeaturedStickersHash(not_null<Main::Session*> session) {
   75     auto result = HashInit();
   76     const auto &sets = session->data().stickers().sets();
   77     const auto &featured = session->data().stickers().featuredSetsOrder();
   78     for (const auto setId : featured) {
   79         HashUpdate(result, setId);
   80 
   81         const auto it = sets.find(setId);
   82         if (it != sets.cend()
   83             && (it->second->flags & MTPDstickerSet_ClientFlag::f_unread)) {
   84             HashUpdate(result, 1);
   85         }
   86     }
   87     return HashFinalize(result);
   88 }
   89 
   90 int32 CountSavedGifsHash(not_null<Main::Session*> session) {
   91     return CountDocumentVectorHash(session->data().stickers().savedGifs());
   92 }
   93 
   94 } // namespace Api