tdesktop/Telegram/SourceFiles/data/data_story.h

239 lines
5.5 KiB
C
Raw Normal View History

/*
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"
class Image;
class PhotoData;
class DocumentData;
namespace Main {
class Session;
} // namespace Main
namespace Data {
class Session;
class Thread;
class PhotoMedia;
enum class StoryPrivacy : uchar {
Public,
CloseFriends,
Contacts,
SelectedContacts,
Other,
};
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;
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;
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;
};
class Story final {
public:
Story(
StoryId id,
not_null<PeerData*> peer,
StoryMedia media,
const MTPDstoryItem &data,
TimeId now);
static constexpr int kRecentViewersMax = 3;
[[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;
[[nodiscard]] StoryPrivacy privacy() const;
2023-06-29 10:48:14 +00:00
[[nodiscard]] bool forbidsForward() const;
[[nodiscard]] bool edited() const;
2023-08-31 08:58:34 +00:00
[[nodiscard]] bool out() const;
[[nodiscard]] bool canDownloadIfPremium() const;
[[nodiscard]] bool canDownloadChecked() const;
[[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);
[[nodiscard]] auto recentViewers() const
-> const std::vector<not_null<PeerData*>> &;
2023-08-04 14:49:58 +00:00
[[nodiscard]] const StoryViews &viewsList() const;
[[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-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
void applyChanges(
2023-07-05 15:52:22 +00:00
StoryMedia media,
const MTPDstoryItem &data,
TimeId now);
[[nodiscard]] TimeId lastUpdateTime() const;
private:
2023-09-14 08:29:14 +00:00
void changeSuggestedReactionCount(Data::ReactionId id, int delta);
void applyFields(
StoryMedia media,
const MTPDstoryItem &data,
TimeId now,
bool initial);
const StoryId _id = 0;
const not_null<PeerData*> _peer;
2023-08-08 08:55:12 +00:00
Data::ReactionId _sentReactionId;
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;
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;
bool _pinned : 1 = false;
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;
bool _edited : 1 = false;
};
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