// This is the source code of AyuGram for Desktop. // // We do not and cannot prevent the use of our code, // but be respectful and credit the original author. // // Copyright @Radolyn, 2026 #pragma once #include "api/api_common.h" #include "ayu/data/entities.h" #include "ayu/utils/rc_manager.h" #include "core/application.h" #include "data/data_media_types.h" #include "dialogs/dialogs_main_list.h" #include "info/profile/info_profile_badge.h" namespace Api { struct SendOptions; } using UsernameResolverCallback = Fn; class TimedCountDownLatch { public: explicit TimedCountDownLatch(int count) : count_(count) { } TimedCountDownLatch(const TimedCountDownLatch &) = delete; TimedCountDownLatch &operator=(const TimedCountDownLatch &) = delete; void countDown() { std::unique_lock lock(mutex_); if (count_ > 0) { count_--; } if (count_ == 0) { cv_.notify_all(); } } bool await(std::chrono::milliseconds timeout) { std::unique_lock lock(mutex_); if (count_ == 0) { return true; } return cv_.wait_for(lock, timeout, [this] { return count_ == 0; }); } private: std::mutex mutex_; std::condition_variable cv_; int count_; }; Main::Session *getSession(ID userId); void dispatchToMainThread(const std::function &callback, int delay = 0); ID getDialogIdFromPeer(not_null peer); ID getBareID(not_null peer); bool isExteraPeer(ID peerId); bool isSupporterPeer(ID peerId); bool isCustomBadgePeer(ID peerId); CustomBadge getCustomBadge(ID peerId); rpl::producer ExteraBadgeTypeFromPeer(not_null peer); Fn badgeClickHandler(not_null peer); bool isMessageHidden(not_null item); void MarkAsReadChatList(not_null list); void MarkAsReadThread(not_null thread); void markReadAfterAction(not_null history); void readHistory(not_null message); QString formatTTL(int time, bool isDoc); QString formatDateTime(const QDateTime &date); QString formatMessageTime(const QTime &time); QString getDCName(int dc); QString getMediaSize(not_null message); QString getMediaMime(not_null message); QString getMediaName(not_null message); QString getMediaResolution(not_null message); QString getMediaDC(not_null message); QString getPeerDC(not_null peer); int getScheduleTime(int64 sumSize); bool isMessageSavable(not_null item); void processMessageDelete(not_null item); void searchUserById(ID userId, Main::Session *session, const UsernameResolverCallback &callback); void searchChatById(ID chatId, Main::Session *session, const UsernameResolverCallback &callback); ID getUserIdFromPackId(uint64 id); TextWithTags extractText(not_null item); bool mediaDownloadable(const Data::Media* media); TextWithEntities reverseLocalPremiumEmoji(const TextWithEntities &text, not_null history, bool isForQuote = false); void applyLocalPremiumEmoji(TextWithEntities &text); not_null currentSession(); PeerData* getPeerFromDialogId(ID id); PeerData* getPeerFromDialogId(unsigned long long id); QString filterZalgo(const QString &text); bool prependPseudoReply(Api::MessageToSend &message); bool prependPseudoReply( not_null session, not_null history, TextWithTags &caption, FullReplyTo &replyTo); void getRegistrationDate(not_null peer, Fn callback); QString getBetterLinkPreview(const QString &url); void applyGhostScheduling( not_null session, Api::SendOptions &options, int delaySeconds = 12);