2023-06-27 08:38:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/weak_ptr.h"
|
2023-08-04 16:33:31 +00:00
|
|
|
#include "data/data_location.h"
|
2023-08-04 14:49:58 +00:00
|
|
|
#include "data/data_message_reaction_id.h"
|
2023-06-27 08:38:02 +00:00
|
|
|
|
|
|
|
class Image;
|
|
|
|
class PhotoData;
|
|
|
|
class DocumentData;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class Session;
|
|
|
|
class Thread;
|
|
|
|
class PhotoMedia;
|
|
|
|
|
2023-07-19 08:30:34 +00:00
|
|
|
enum class StoryPrivacy : uchar {
|
|
|
|
Public,
|
|
|
|
CloseFriends,
|
|
|
|
Contacts,
|
|
|
|
SelectedContacts,
|
|
|
|
Other,
|
|
|
|
};
|
|
|
|
|
2023-06-27 08:38:02 +00:00
|
|
|
struct StoryIdDates {
|
|
|
|
StoryId id = 0;
|
|
|
|
TimeId date = 0;
|
|
|
|
TimeId expires = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] bool valid() const {
|
|
|
|
return id != 0;
|
|
|
|
}
|
|
|
|
explicit operator bool() const {
|
|
|
|
return valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline auto operator<=>(StoryIdDates, StoryIdDates) = default;
|
|
|
|
friend inline bool operator==(StoryIdDates, StoryIdDates) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StoryMedia {
|
|
|
|
std::variant<
|
|
|
|
v::null_t,
|
|
|
|
not_null<PhotoData*>,
|
|
|
|
not_null<DocumentData*>> data;
|
|
|
|
|
|
|
|
friend inline bool operator==(StoryMedia, StoryMedia) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StoryView {
|
|
|
|
not_null<PeerData*> peer;
|
2023-08-04 14:49:58 +00:00
|
|
|
Data::ReactionId reaction;
|
2023-06-27 08:38:02 +00:00
|
|
|
TimeId date = 0;
|
|
|
|
|
|
|
|
friend inline bool operator==(StoryView, StoryView) = default;
|
|
|
|
};
|
|
|
|
|
2023-08-04 14:49:58 +00:00
|
|
|
struct StoryViews {
|
|
|
|
std::vector<StoryView> list;
|
|
|
|
QString nextOffset;
|
2023-08-04 15:30:49 +00:00
|
|
|
int reactions = 0;
|
2023-08-04 14:49:58 +00:00
|
|
|
int total = 0;
|
2023-09-13 06:30:16 +00:00
|
|
|
bool known = false;
|
2023-08-04 14:49:58 +00:00
|
|
|
};
|
|
|
|
|
2023-08-04 16:33:31 +00:00
|
|
|
struct StoryArea {
|
|
|
|
QRectF geometry;
|
|
|
|
float64 rotation = 0;
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const StoryArea &,
|
|
|
|
const StoryArea &) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StoryLocation {
|
|
|
|
StoryArea area;
|
|
|
|
Data::LocationPoint point;
|
|
|
|
QString title;
|
|
|
|
QString address;
|
|
|
|
QString provider;
|
|
|
|
QString venueId;
|
|
|
|
QString venueType;
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const StoryLocation &,
|
|
|
|
const StoryLocation &) = default;
|
|
|
|
};
|
|
|
|
|
2023-08-31 08:58:34 +00:00
|
|
|
struct SuggestedReaction {
|
|
|
|
StoryArea area;
|
|
|
|
Data::ReactionId reaction;
|
2023-09-14 08:29:14 +00:00
|
|
|
int count = 0;
|
2023-08-31 08:58:34 +00:00
|
|
|
bool flipped = false;
|
|
|
|
bool dark = false;
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const SuggestedReaction &,
|
|
|
|
const SuggestedReaction &) = default;
|
|
|
|
};
|
|
|
|
|
2023-06-27 08:38:02 +00:00
|
|
|
class Story final {
|
|
|
|
public:
|
|
|
|
Story(
|
|
|
|
StoryId id,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
StoryMedia media,
|
2023-07-05 17:02:57 +00:00
|
|
|
const MTPDstoryItem &data,
|
|
|
|
TimeId now);
|
|
|
|
|
|
|
|
static constexpr int kRecentViewersMax = 3;
|
2023-06-27 08:38:02 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Session &owner() const;
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
[[nodiscard]] not_null<PeerData*> peer() const;
|
|
|
|
|
|
|
|
[[nodiscard]] StoryId id() const;
|
|
|
|
[[nodiscard]] bool mine() const;
|
|
|
|
[[nodiscard]] StoryIdDates idDates() const;
|
|
|
|
[[nodiscard]] FullStoryId fullId() const;
|
|
|
|
[[nodiscard]] TimeId date() const;
|
|
|
|
[[nodiscard]] TimeId expires() const;
|
|
|
|
[[nodiscard]] bool unsupported() const;
|
|
|
|
[[nodiscard]] bool expired(TimeId now = 0) const;
|
|
|
|
[[nodiscard]] const StoryMedia &media() const;
|
|
|
|
[[nodiscard]] PhotoData *photo() const;
|
|
|
|
[[nodiscard]] DocumentData *document() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasReplyPreview() const;
|
|
|
|
[[nodiscard]] Image *replyPreview() const;
|
|
|
|
[[nodiscard]] TextWithEntities inReplyText() const;
|
|
|
|
|
|
|
|
void setPinned(bool pinned);
|
|
|
|
[[nodiscard]] bool pinned() const;
|
2023-07-19 08:30:34 +00:00
|
|
|
[[nodiscard]] StoryPrivacy privacy() const;
|
2023-06-29 10:48:14 +00:00
|
|
|
[[nodiscard]] bool forbidsForward() const;
|
2023-07-05 12:18:55 +00:00
|
|
|
[[nodiscard]] bool edited() const;
|
2023-08-31 08:58:34 +00:00
|
|
|
[[nodiscard]] bool out() const;
|
2023-06-27 08:38:02 +00:00
|
|
|
|
2023-08-02 19:41:58 +00:00
|
|
|
[[nodiscard]] bool canDownloadIfPremium() const;
|
|
|
|
[[nodiscard]] bool canDownloadChecked() const;
|
2023-06-27 08:38:02 +00:00
|
|
|
[[nodiscard]] bool canShare() const;
|
|
|
|
[[nodiscard]] bool canDelete() const;
|
|
|
|
[[nodiscard]] bool canReport() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasDirectLink() const;
|
|
|
|
[[nodiscard]] std::optional<QString> errorTextForForward(
|
|
|
|
not_null<Thread*> to) const;
|
|
|
|
|
|
|
|
void setCaption(TextWithEntities &&caption);
|
|
|
|
[[nodiscard]] const TextWithEntities &caption() const;
|
|
|
|
|
2023-08-08 08:55:12 +00:00
|
|
|
[[nodiscard]] Data::ReactionId sentReactionId() const;
|
|
|
|
void setReactionId(Data::ReactionId id);
|
|
|
|
|
2023-06-27 08:38:02 +00:00
|
|
|
[[nodiscard]] auto recentViewers() const
|
|
|
|
-> const std::vector<not_null<PeerData*>> &;
|
2023-08-04 14:49:58 +00:00
|
|
|
[[nodiscard]] const StoryViews &viewsList() const;
|
2023-06-27 08:38:02 +00:00
|
|
|
[[nodiscard]] int views() const;
|
2023-08-04 15:30:49 +00:00
|
|
|
[[nodiscard]] int reactions() const;
|
2023-08-04 14:49:58 +00:00
|
|
|
void applyViewsSlice(const QString &offset, const StoryViews &slice);
|
2023-06-27 08:38:02 +00:00
|
|
|
|
2023-08-04 16:33:31 +00:00
|
|
|
[[nodiscard]] const std::vector<StoryLocation> &locations() const;
|
2023-08-31 08:58:34 +00:00
|
|
|
[[nodiscard]] auto suggestedReactions() const
|
|
|
|
-> const std::vector<SuggestedReaction> &;
|
2023-08-04 16:33:31 +00:00
|
|
|
|
2023-07-05 17:02:57 +00:00
|
|
|
void applyChanges(
|
2023-07-05 15:52:22 +00:00
|
|
|
StoryMedia media,
|
|
|
|
const MTPDstoryItem &data,
|
|
|
|
TimeId now);
|
|
|
|
[[nodiscard]] TimeId lastUpdateTime() const;
|
2023-06-27 08:38:02 +00:00
|
|
|
|
|
|
|
private:
|
2023-09-14 08:29:14 +00:00
|
|
|
void changeSuggestedReactionCount(Data::ReactionId id, int delta);
|
2023-07-05 17:02:57 +00:00
|
|
|
void applyFields(
|
|
|
|
StoryMedia media,
|
|
|
|
const MTPDstoryItem &data,
|
|
|
|
TimeId now,
|
|
|
|
bool initial);
|
|
|
|
|
2023-06-27 08:38:02 +00:00
|
|
|
const StoryId _id = 0;
|
|
|
|
const not_null<PeerData*> _peer;
|
2023-08-08 08:55:12 +00:00
|
|
|
Data::ReactionId _sentReactionId;
|
2023-06-27 08:38:02 +00:00
|
|
|
StoryMedia _media;
|
|
|
|
TextWithEntities _caption;
|
|
|
|
std::vector<not_null<PeerData*>> _recentViewers;
|
2023-08-04 16:33:31 +00:00
|
|
|
std::vector<StoryLocation> _locations;
|
2023-08-31 08:58:34 +00:00
|
|
|
std::vector<SuggestedReaction> _suggestedReactions;
|
2023-08-04 14:49:58 +00:00
|
|
|
StoryViews _views;
|
2023-06-27 08:38:02 +00:00
|
|
|
const TimeId _date = 0;
|
|
|
|
const TimeId _expires = 0;
|
2023-07-05 15:52:22 +00:00
|
|
|
TimeId _lastUpdateTime = 0;
|
2023-08-31 08:58:34 +00:00
|
|
|
bool _out : 1 = false;
|
2023-06-27 08:38:02 +00:00
|
|
|
bool _pinned : 1 = false;
|
2023-07-19 08:30:34 +00:00
|
|
|
bool _privacyPublic : 1 = false;
|
|
|
|
bool _privacyCloseFriends : 1 = false;
|
|
|
|
bool _privacyContacts : 1 = false;
|
|
|
|
bool _privacySelectedContacts : 1 = false;
|
2023-06-29 10:48:14 +00:00
|
|
|
bool _noForwards : 1 = false;
|
2023-07-05 12:18:55 +00:00
|
|
|
bool _edited : 1 = false;
|
2023-06-27 08:38:02 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class StoryPreload final : public base::has_weak_ptr {
|
|
|
|
public:
|
|
|
|
StoryPreload(not_null<Story*> story, Fn<void()> done);
|
|
|
|
~StoryPreload();
|
|
|
|
|
|
|
|
[[nodiscard]] FullStoryId id() const;
|
|
|
|
[[nodiscard]] not_null<Story*> story() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class LoadTask;
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void load();
|
|
|
|
void callDone();
|
|
|
|
|
|
|
|
const not_null<Story*> _story;
|
|
|
|
Fn<void()> _done;
|
|
|
|
|
|
|
|
std::shared_ptr<Data::PhotoMedia> _photo;
|
|
|
|
std::unique_ptr<LoadTask> _task;
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|