2023-05-22 15:59:16 +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
|
|
|
|
*/
|
|
|
|
#include "dialogs/ui/dialogs_stories_content.h"
|
|
|
|
|
|
|
|
#include "data/data_changes.h"
|
2023-06-19 17:00:34 +00:00
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_document_media.h"
|
|
|
|
#include "data/data_file_origin.h"
|
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_photo_media.h"
|
2023-05-22 15:59:16 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_stories.h"
|
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "dialogs/ui/dialogs_stories_list.h"
|
2023-06-30 08:48:42 +00:00
|
|
|
#include "info/stories/info_stories_widget.h"
|
|
|
|
#include "info/info_controller.h"
|
|
|
|
#include "info/info_memento.h"
|
2023-05-22 15:59:16 +00:00
|
|
|
#include "main/main_session.h"
|
2023-06-09 15:31:51 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2023-05-22 15:59:16 +00:00
|
|
|
#include "ui/painter.h"
|
2023-06-30 08:48:42 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "styles/style_menu_icons.h"
|
2023-05-22 15:59:16 +00:00
|
|
|
|
|
|
|
namespace Dialogs::Stories {
|
|
|
|
namespace {
|
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
constexpr auto kShownLastCount = 3;
|
|
|
|
|
|
|
|
class PeerUserpic final : public Thumbnail {
|
2023-05-22 15:59:16 +00:00
|
|
|
public:
|
|
|
|
explicit PeerUserpic(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
QImage image(int size) override;
|
|
|
|
void subscribeToUpdates(Fn<void()> callback) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Subscribed {
|
|
|
|
explicit Subscribed(Fn<void()> callback)
|
|
|
|
: callback(std::move(callback)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::PeerUserpicView view;
|
|
|
|
Fn<void()> callback;
|
|
|
|
InMemoryKey key;
|
|
|
|
rpl::lifetime photoLifetime;
|
|
|
|
rpl::lifetime downloadLifetime;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] bool waitingUserpicLoad() const;
|
|
|
|
void processNewPhoto();
|
|
|
|
|
|
|
|
const not_null<PeerData*> _peer;
|
|
|
|
QImage _frame;
|
|
|
|
std::unique_ptr<Subscribed> _subscribed;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
class StoryThumbnail : public Thumbnail {
|
|
|
|
public:
|
|
|
|
explicit StoryThumbnail(FullStoryId id);
|
|
|
|
virtual ~StoryThumbnail() = default;
|
|
|
|
|
|
|
|
QImage image(int size) override;
|
|
|
|
void subscribeToUpdates(Fn<void()> callback) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct Thumb {
|
|
|
|
Image *image = nullptr;
|
|
|
|
bool blurred = false;
|
|
|
|
};
|
|
|
|
[[nodiscard]] virtual Main::Session &session() = 0;
|
|
|
|
[[nodiscard]] virtual Thumb loaded(FullStoryId id) = 0;
|
|
|
|
virtual void clear() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const FullStoryId _id;
|
|
|
|
QImage _full;
|
|
|
|
rpl::lifetime _subscription;
|
|
|
|
QImage _prepared;
|
|
|
|
bool _blurred = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PhotoThumbnail final : public StoryThumbnail {
|
|
|
|
public:
|
|
|
|
PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Main::Session &session() override;
|
|
|
|
Thumb loaded(FullStoryId id) override;
|
|
|
|
void clear() override;
|
|
|
|
|
|
|
|
const not_null<PhotoData*> _photo;
|
|
|
|
std::shared_ptr<Data::PhotoMedia> _media;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class VideoThumbnail final : public StoryThumbnail {
|
|
|
|
public:
|
|
|
|
VideoThumbnail(not_null<DocumentData*> video, FullStoryId id);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Main::Session &session() override;
|
|
|
|
Thumb loaded(FullStoryId id) override;
|
|
|
|
void clear() override;
|
|
|
|
|
|
|
|
const not_null<DocumentData*> _video;
|
|
|
|
std::shared_ptr<Data::DocumentMedia> _media;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class EmptyThumbnail final : public Thumbnail {
|
|
|
|
public:
|
|
|
|
QImage image(int size) override;
|
|
|
|
void subscribeToUpdates(Fn<void()> callback) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QImage _cached;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-05-22 15:59:16 +00:00
|
|
|
class State final {
|
|
|
|
public:
|
2023-06-02 14:26:39 +00:00
|
|
|
State(not_null<Data::Stories*> data, Data::StorySourcesList list);
|
2023-05-22 15:59:16 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Content next();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const not_null<Data::Stories*> _data;
|
2023-06-02 14:26:39 +00:00
|
|
|
const Data::StorySourcesList _list;
|
2023-06-19 17:00:34 +00:00
|
|
|
base::flat_map<
|
2023-08-31 08:58:34 +00:00
|
|
|
not_null<PeerData*>,
|
2023-06-19 17:00:34 +00:00
|
|
|
std::shared_ptr<Thumbnail>> _userpics;
|
2023-05-22 15:59:16 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
PeerUserpic::PeerUserpic(not_null<PeerData*> peer)
|
|
|
|
: _peer(peer) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage PeerUserpic::image(int size) {
|
|
|
|
Expects(_subscribed != nullptr);
|
|
|
|
|
|
|
|
const auto good = (_frame.width() == size * _frame.devicePixelRatio());
|
|
|
|
const auto key = _peer->userpicUniqueKey(_subscribed->view);
|
|
|
|
if (!good || (_subscribed->key != key && !waitingUserpicLoad())) {
|
2023-06-29 10:48:14 +00:00
|
|
|
const auto ratio = style::DevicePixelRatio();
|
2023-05-22 15:59:16 +00:00
|
|
|
_subscribed->key = key;
|
|
|
|
_frame = QImage(
|
2023-06-29 10:48:14 +00:00
|
|
|
QSize(size, size) * ratio,
|
2023-05-22 15:59:16 +00:00
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
2023-06-29 10:48:14 +00:00
|
|
|
_frame.setDevicePixelRatio(ratio);
|
2023-05-22 15:59:16 +00:00
|
|
|
_frame.fill(Qt::transparent);
|
|
|
|
|
|
|
|
auto p = Painter(&_frame);
|
|
|
|
_peer->paintUserpic(p, _subscribed->view, 0, 0, size);
|
|
|
|
}
|
|
|
|
return _frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PeerUserpic::waitingUserpicLoad() const {
|
|
|
|
return _peer->hasUserpic() && _peer->useEmptyUserpic(_subscribed->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerUserpic::subscribeToUpdates(Fn<void()> callback) {
|
|
|
|
if (!callback) {
|
|
|
|
_subscribed = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_subscribed = std::make_unique<Subscribed>(std::move(callback));
|
|
|
|
|
|
|
|
_peer->session().changes().peerUpdates(
|
|
|
|
_peer,
|
|
|
|
Data::PeerUpdate::Flag::Photo
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_subscribed->callback();
|
|
|
|
processNewPhoto();
|
|
|
|
}, _subscribed->photoLifetime);
|
|
|
|
|
|
|
|
processNewPhoto();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerUserpic::processNewPhoto() {
|
|
|
|
Expects(_subscribed != nullptr);
|
|
|
|
|
|
|
|
if (!waitingUserpicLoad()) {
|
|
|
|
_subscribed->downloadLifetime.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_peer->session().downloaderTaskFinished(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !waitingUserpicLoad();
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
_subscribed->callback();
|
|
|
|
_subscribed->downloadLifetime.destroy();
|
|
|
|
}, _subscribed->downloadLifetime);
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
StoryThumbnail::StoryThumbnail(FullStoryId id)
|
|
|
|
: _id(id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage StoryThumbnail::image(int size) {
|
|
|
|
const auto ratio = style::DevicePixelRatio();
|
|
|
|
if (_prepared.width() != size * ratio) {
|
|
|
|
if (_full.isNull()) {
|
|
|
|
_prepared = QImage(
|
|
|
|
QSize(size, size) * ratio,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_prepared.fill(Qt::black);
|
|
|
|
} else {
|
|
|
|
const auto width = _full.width();
|
|
|
|
const auto skip = std::max((_full.height() - width) / 2, 0);
|
|
|
|
_prepared = _full.copy(0, skip, width, width).scaled(
|
|
|
|
QSize(size, size) * ratio,
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
_prepared = Images::Circle(std::move(_prepared));
|
2023-06-29 10:48:14 +00:00
|
|
|
_prepared.setDevicePixelRatio(ratio);
|
2023-06-19 17:00:34 +00:00
|
|
|
}
|
|
|
|
return _prepared;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StoryThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
|
|
|
_subscription.destroy();
|
|
|
|
if (!callback) {
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
} else if (!_full.isNull() && !_blurred) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto thumbnail = loaded(_id);
|
|
|
|
if (const auto image = thumbnail.image) {
|
|
|
|
_full = image->original();
|
|
|
|
}
|
|
|
|
_blurred = thumbnail.blurred;
|
|
|
|
if (!_blurred) {
|
|
|
|
_prepared = QImage();
|
|
|
|
} else {
|
|
|
|
_subscription = session().downloaderTaskFinished(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
const auto thumbnail = loaded(_id);
|
|
|
|
if (!thumbnail.blurred) {
|
|
|
|
_full = thumbnail.image->original();
|
|
|
|
_prepared = QImage();
|
|
|
|
_blurred = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}) | rpl::take(1) | rpl::start_with_next(callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoThumbnail::PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id)
|
|
|
|
: StoryThumbnail(id)
|
|
|
|
, _photo(photo) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Main::Session &PhotoThumbnail::session() {
|
|
|
|
return _photo->session();
|
|
|
|
}
|
|
|
|
|
|
|
|
StoryThumbnail::Thumb PhotoThumbnail::loaded(FullStoryId id) {
|
|
|
|
if (!_media) {
|
|
|
|
_media = _photo->createMediaView();
|
|
|
|
_media->wanted(
|
|
|
|
Data::PhotoSize::Small,
|
|
|
|
Data::FileOriginStory(id.peer, id.story));
|
|
|
|
}
|
|
|
|
if (const auto small = _media->image(Data::PhotoSize::Small)) {
|
|
|
|
return { .image = small };
|
|
|
|
}
|
|
|
|
return { .image = _media->thumbnailInline(), .blurred = true };
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhotoThumbnail::clear() {
|
|
|
|
_media = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoThumbnail::VideoThumbnail(
|
|
|
|
not_null<DocumentData*> video,
|
|
|
|
FullStoryId id)
|
|
|
|
: StoryThumbnail(id)
|
|
|
|
, _video(video) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Main::Session &VideoThumbnail::session() {
|
|
|
|
return _video->session();
|
|
|
|
}
|
|
|
|
|
|
|
|
StoryThumbnail::Thumb VideoThumbnail::loaded(FullStoryId id) {
|
|
|
|
if (!_media) {
|
|
|
|
_media = _video->createMediaView();
|
|
|
|
_media->thumbnailWanted(Data::FileOriginStory(id.peer, id.story));
|
|
|
|
}
|
|
|
|
if (const auto small = _media->thumbnail()) {
|
|
|
|
return { .image = small };
|
|
|
|
}
|
|
|
|
return { .image = _media->thumbnailInline(), .blurred = true };
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoThumbnail::clear() {
|
|
|
|
_media = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage EmptyThumbnail::image(int size) {
|
|
|
|
const auto ratio = style::DevicePixelRatio();
|
|
|
|
if (_cached.width() != size * ratio) {
|
|
|
|
_cached = QImage(
|
|
|
|
QSize(size, size) * ratio,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_cached.fill(Qt::black);
|
2023-06-29 10:48:14 +00:00
|
|
|
_cached.setDevicePixelRatio(ratio);
|
2023-06-19 17:00:34 +00:00
|
|
|
}
|
|
|
|
return _cached;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
|
|
|
}
|
|
|
|
|
2023-06-02 14:26:39 +00:00
|
|
|
State::State(not_null<Data::Stories*> data, Data::StorySourcesList list)
|
|
|
|
: _data(data)
|
|
|
|
, _list(list) {
|
2023-05-22 15:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Content State::next() {
|
2023-06-02 14:26:39 +00:00
|
|
|
const auto &sources = _data->sources(_list);
|
2023-09-26 08:12:33 +00:00
|
|
|
auto result = Content{ .total = int(sources.size()) };
|
2023-06-19 17:00:34 +00:00
|
|
|
result.elements.reserve(sources.size());
|
2023-06-02 14:26:39 +00:00
|
|
|
for (const auto &info : sources) {
|
2023-06-05 16:31:15 +00:00
|
|
|
const auto source = _data->source(info.id);
|
|
|
|
Assert(source != nullptr);
|
2023-06-02 14:26:39 +00:00
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
auto userpic = std::shared_ptr<Thumbnail>();
|
2023-08-31 08:58:34 +00:00
|
|
|
const auto peer = source->peer;
|
|
|
|
if (const auto i = _userpics.find(peer); i != end(_userpics)) {
|
2023-05-22 15:59:16 +00:00
|
|
|
userpic = i->second;
|
|
|
|
} else {
|
2023-08-31 08:58:34 +00:00
|
|
|
userpic = MakeUserpicThumbnail(peer);
|
|
|
|
_userpics.emplace(peer, userpic);
|
2023-05-22 15:59:16 +00:00
|
|
|
}
|
2023-06-19 17:00:34 +00:00
|
|
|
result.elements.push_back({
|
2023-08-31 08:58:34 +00:00
|
|
|
.id = uint64(peer->id.value),
|
|
|
|
.name = peer->shortName(),
|
2023-06-19 17:00:34 +00:00
|
|
|
.thumbnail = std::move(userpic),
|
2023-07-03 20:05:11 +00:00
|
|
|
.count = info.count,
|
|
|
|
.unreadCount = info.unreadCount,
|
2023-08-31 08:58:34 +00:00
|
|
|
.skipSmall = peer->isSelf() ? 1U : 0U,
|
2023-05-26 07:21:19 +00:00
|
|
|
});
|
2023-05-22 15:59:16 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-06-02 14:26:39 +00:00
|
|
|
rpl::producer<Content> ContentForSession(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
Data::StorySourcesList list) {
|
2023-05-22 15:59:16 +00:00
|
|
|
return [=](auto consumer) {
|
|
|
|
auto result = rpl::lifetime();
|
|
|
|
const auto stories = &session->data().stories();
|
2023-06-02 14:26:39 +00:00
|
|
|
const auto state = result.make_state<State>(stories, list);
|
2023-05-22 15:59:16 +00:00
|
|
|
rpl::single(
|
|
|
|
rpl::empty
|
|
|
|
) | rpl::then(
|
2023-06-02 14:26:39 +00:00
|
|
|
stories->sourcesChanged(list)
|
2023-05-22 15:59:16 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
consumer.put_next(state->next());
|
|
|
|
}, result);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
rpl::producer<Content> LastForPeer(not_null<PeerData*> peer) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto stories = &peer->owner().stories();
|
|
|
|
const auto peerId = peer->id;
|
|
|
|
|
|
|
|
return rpl::single(
|
|
|
|
peerId
|
|
|
|
) | rpl::then(
|
|
|
|
stories->sourceChanged() | rpl::filter(_1 == peerId)
|
|
|
|
) | rpl::map([=] {
|
|
|
|
auto ids = std::vector<StoryId>();
|
|
|
|
auto readTill = StoryId();
|
2023-09-26 08:12:33 +00:00
|
|
|
auto total = 0;
|
2023-06-19 17:00:34 +00:00
|
|
|
if (const auto source = stories->source(peerId)) {
|
|
|
|
readTill = source->readTill;
|
2023-09-26 08:12:33 +00:00
|
|
|
total = int(source->ids.size());
|
2023-06-19 17:00:34 +00:00
|
|
|
ids = ranges::views::all(source->ids)
|
|
|
|
| ranges::views::reverse
|
|
|
|
| ranges::views::take(kShownLastCount)
|
|
|
|
| ranges::views::transform(&Data::StoryIdDates::id)
|
|
|
|
| ranges::to_vector;
|
|
|
|
}
|
|
|
|
return rpl::make_producer<Content>([=](auto consumer) {
|
|
|
|
auto lifetime = rpl::lifetime();
|
2023-07-14 07:24:13 +00:00
|
|
|
if (ids.empty()) {
|
|
|
|
consumer.put_next(Content());
|
|
|
|
consumer.put_done();
|
|
|
|
return lifetime;
|
|
|
|
}
|
2023-06-19 17:00:34 +00:00
|
|
|
|
|
|
|
struct State {
|
|
|
|
Fn<void()> check;
|
|
|
|
base::has_weak_ptr guard;
|
2023-07-14 07:24:13 +00:00
|
|
|
int readTill = StoryId();
|
2023-06-19 17:00:34 +00:00
|
|
|
bool pushed = false;
|
|
|
|
};
|
|
|
|
const auto state = lifetime.make_state<State>();
|
2023-07-14 07:24:13 +00:00
|
|
|
state->readTill = readTill;
|
2023-06-19 17:00:34 +00:00
|
|
|
state->check = [=] {
|
|
|
|
if (state->pushed) {
|
|
|
|
return;
|
|
|
|
}
|
2023-07-14 07:24:13 +00:00
|
|
|
auto done = true;
|
2023-06-19 17:00:34 +00:00
|
|
|
auto resolving = false;
|
2023-09-26 08:12:33 +00:00
|
|
|
auto result = Content{ .total = total };
|
2023-06-19 17:00:34 +00:00
|
|
|
for (const auto id : ids) {
|
|
|
|
const auto storyId = FullStoryId{ peerId, id };
|
|
|
|
const auto maybe = stories->lookup(storyId);
|
|
|
|
if (maybe) {
|
|
|
|
if (!resolving) {
|
2023-07-14 07:24:13 +00:00
|
|
|
const auto unread = (id > state->readTill);
|
2023-06-19 17:00:34 +00:00
|
|
|
result.elements.reserve(ids.size());
|
|
|
|
result.elements.push_back({
|
|
|
|
.id = uint64(id),
|
2023-06-29 10:48:14 +00:00
|
|
|
.thumbnail = MakeStoryThumbnail(*maybe),
|
2023-07-05 07:55:16 +00:00
|
|
|
.count = 1U,
|
2023-07-14 07:24:13 +00:00
|
|
|
.unreadCount = unread ? 1U : 0U,
|
2023-06-19 17:00:34 +00:00
|
|
|
});
|
2023-07-14 07:24:13 +00:00
|
|
|
if (unread) {
|
|
|
|
done = false;
|
|
|
|
}
|
2023-06-19 17:00:34 +00:00
|
|
|
}
|
|
|
|
} else if (maybe.error() == Data::NoStory::Unknown) {
|
|
|
|
resolving = true;
|
|
|
|
stories->resolve(
|
|
|
|
storyId,
|
|
|
|
crl::guard(&state->guard, state->check));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resolving) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->pushed = true;
|
|
|
|
consumer.put_next(std::move(result));
|
2023-07-14 07:24:13 +00:00
|
|
|
if (done) {
|
|
|
|
consumer.put_done();
|
|
|
|
}
|
2023-06-19 17:00:34 +00:00
|
|
|
};
|
2023-07-14 07:24:13 +00:00
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
rpl::single(peerId) | rpl::then(
|
|
|
|
stories->itemsChanged() | rpl::filter(_1 == peerId)
|
|
|
|
) | rpl::start_with_next(state->check, lifetime);
|
|
|
|
|
2023-07-14 07:24:13 +00:00
|
|
|
stories->session().changes().storyUpdates(
|
|
|
|
Data::StoryUpdate::Flag::MarkRead
|
|
|
|
) | rpl::start_with_next([=](const Data::StoryUpdate &update) {
|
|
|
|
if (update.story->peer()->id == peerId) {
|
|
|
|
if (update.story->id() > state->readTill) {
|
|
|
|
state->readTill = update.story->id();
|
|
|
|
if (ranges::contains(ids, state->readTill)
|
|
|
|
|| state->readTill > ids.front()) {
|
|
|
|
state->pushed = false;
|
|
|
|
state->check();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, lifetime);
|
|
|
|
|
2023-06-19 17:00:34 +00:00
|
|
|
return lifetime;
|
|
|
|
});
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
}
|
|
|
|
|
2023-06-29 10:48:14 +00:00
|
|
|
std::shared_ptr<Thumbnail> MakeUserpicThumbnail(not_null<PeerData*> peer) {
|
|
|
|
return std::make_shared<PeerUserpic>(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Thumbnail> MakeStoryThumbnail(
|
|
|
|
not_null<Data::Story*> story) {
|
|
|
|
using Result = std::shared_ptr<Thumbnail>;
|
|
|
|
const auto id = story->fullId();
|
|
|
|
return v::match(story->media().data, [](v::null_t) -> Result {
|
|
|
|
return std::make_shared<EmptyThumbnail>();
|
|
|
|
}, [&](not_null<PhotoData*> photo) -> Result {
|
|
|
|
return std::make_shared<PhotoThumbnail>(photo, id);
|
|
|
|
}, [&](not_null<DocumentData*> video) -> Result {
|
|
|
|
return std::make_shared<VideoThumbnail>(video, id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-30 08:48:42 +00:00
|
|
|
void FillSourceMenu(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const ShowMenuRequest &request) {
|
|
|
|
const auto owner = &controller->session().data();
|
|
|
|
const auto peer = owner->peer(PeerId(request.id));
|
|
|
|
const auto &add = request.callback;
|
|
|
|
if (peer->isSelf()) {
|
|
|
|
add(tr::lng_stories_archive_button(tr::now), [=] {
|
|
|
|
controller->showSection(Info::Stories::Make(
|
|
|
|
peer,
|
|
|
|
Info::Stories::Tab::Archive));
|
2023-07-03 07:33:28 +00:00
|
|
|
}, &st::menuIconStoriesArchiveSection);
|
2023-06-30 08:48:42 +00:00
|
|
|
add(tr::lng_stories_my_title(tr::now), [=] {
|
|
|
|
controller->showSection(Info::Stories::Make(peer));
|
2023-07-03 07:33:28 +00:00
|
|
|
}, &st::menuIconStoriesSavedSection);
|
2023-06-30 08:48:42 +00:00
|
|
|
} else {
|
2023-09-22 16:59:37 +00:00
|
|
|
const auto channel = peer->isChannel();
|
|
|
|
const auto showHistoryText = channel
|
|
|
|
? tr::lng_context_open_channel(tr::now)
|
|
|
|
: tr::lng_profile_send_message(tr::now);
|
|
|
|
add(showHistoryText, [=] {
|
2023-06-30 08:48:42 +00:00
|
|
|
controller->showPeerHistory(peer);
|
2023-09-22 16:59:37 +00:00
|
|
|
}, channel ? &st::menuIconChannel : &st::menuIconChatBubble);
|
|
|
|
const auto viewProfileText = channel
|
|
|
|
? tr::lng_context_view_channel(tr::now)
|
|
|
|
: tr::lng_context_view_profile(tr::now);
|
|
|
|
add(viewProfileText, [=] {
|
2023-06-30 08:48:42 +00:00
|
|
|
controller->showPeerInfo(peer);
|
2023-09-22 16:59:37 +00:00
|
|
|
}, channel ? &st::menuIconInfo : &st::menuIconProfile);
|
2023-06-30 08:48:42 +00:00
|
|
|
const auto in = [&](Data::StorySourcesList list) {
|
|
|
|
return ranges::contains(
|
|
|
|
owner->stories().sources(list),
|
|
|
|
peer->id,
|
|
|
|
&Data::StoriesSourceInfo::id);
|
|
|
|
};
|
|
|
|
const auto toggle = [=](bool shown) {
|
|
|
|
owner->stories().toggleHidden(
|
|
|
|
peer->id,
|
|
|
|
!shown,
|
|
|
|
controller->uiShow());
|
|
|
|
};
|
|
|
|
if (in(Data::StorySourcesList::NotHidden)) {
|
2023-07-11 15:22:18 +00:00
|
|
|
add(tr::lng_stories_archive(tr::now), [=] {
|
2023-06-30 08:48:42 +00:00
|
|
|
toggle(false);
|
2023-07-11 15:22:18 +00:00
|
|
|
}, &st::menuIconArchive);
|
2023-06-30 08:48:42 +00:00
|
|
|
}
|
|
|
|
if (in(Data::StorySourcesList::Hidden)) {
|
2023-07-11 15:22:18 +00:00
|
|
|
add(tr::lng_stories_unarchive(tr::now), [=] {
|
2023-06-30 08:48:42 +00:00
|
|
|
toggle(true);
|
2023-07-11 15:22:18 +00:00
|
|
|
}, &st::menuIconUnarchive);
|
2023-06-30 08:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 15:59:16 +00:00
|
|
|
} // namespace Dialogs::Stories
|