2017-10-04 12:39:59 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-10-04 12:39:59 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-10-04 12:39:59 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <rpl/mappers.h>
|
|
|
|
#include <rpl/map.h>
|
|
|
|
#include "lang/lang_keys.h"
|
2023-12-28 14:52:13 +00:00
|
|
|
#include "data/data_saved_messages.h"
|
|
|
|
#include "data/data_session.h"
|
2023-06-05 16:31:15 +00:00
|
|
|
#include "data/data_stories_ids.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
2023-12-28 14:52:13 +00:00
|
|
|
#include "history/view/history_view_sublist_section.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "info/info_memento.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2023-06-05 16:31:15 +00:00
|
|
|
#include "info/stories/info_stories_widget.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2019-11-02 17:06:47 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2023-11-28 08:54:17 +00:00
|
|
|
#include "data/data_channel.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
namespace Info::Media {
|
2017-10-04 12:39:59 +00:00
|
|
|
|
|
|
|
using Type = Storage::SharedMediaType;
|
|
|
|
|
2019-06-19 16:39:25 +00:00
|
|
|
inline tr::phrase<lngtag_count> MediaTextPhrase(Type type) {
|
2017-10-04 12:39:59 +00:00
|
|
|
switch (type) {
|
2019-06-19 16:39:25 +00:00
|
|
|
case Type::Photo: return tr::lng_profile_photos;
|
2020-08-23 19:42:28 +00:00
|
|
|
case Type::GIF: return tr::lng_profile_gifs;
|
2019-06-19 16:39:25 +00:00
|
|
|
case Type::Video: return tr::lng_profile_videos;
|
|
|
|
case Type::File: return tr::lng_profile_files;
|
|
|
|
case Type::MusicFile: return tr::lng_profile_songs;
|
|
|
|
case Type::Link: return tr::lng_profile_shared_links;
|
|
|
|
case Type::RoundVoiceFile: return tr::lng_profile_audios;
|
2017-10-04 12:39:59 +00:00
|
|
|
}
|
2017-10-20 16:19:42 +00:00
|
|
|
Unexpected("Type in MediaTextPhrase()");
|
2017-10-04 12:39:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline auto MediaText(Type type) {
|
|
|
|
return [phrase = MediaTextPhrase(type)](int count) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return phrase(tr::now, lt_count, count);
|
2017-10-04 12:39:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Count, typename Text>
|
|
|
|
inline auto AddCountedButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
|
|
|
Count &&count,
|
|
|
|
Text &&textFromCount,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2022-02-13 13:30:43 +00:00
|
|
|
using namespace ::Settings;
|
2017-10-04 12:39:59 +00:00
|
|
|
auto forked = std::move(count)
|
|
|
|
| start_spawning(parent->lifetime());
|
2017-12-22 07:05:20 +00:00
|
|
|
auto text = rpl::duplicate(
|
|
|
|
forked
|
|
|
|
) | rpl::map([textFromCount](int count) {
|
|
|
|
return (count > 0)
|
|
|
|
? textFromCount(count)
|
|
|
|
: QString();
|
|
|
|
});
|
2023-11-14 22:26:47 +00:00
|
|
|
auto button = parent->add(object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
|
2017-10-04 12:39:59 +00:00
|
|
|
parent,
|
2023-11-14 22:26:47 +00:00
|
|
|
object_ptr<Ui::SettingsButton>(
|
2017-10-04 12:39:59 +00:00
|
|
|
parent,
|
|
|
|
std::move(text),
|
|
|
|
st::infoSharedMediaButton))
|
2017-11-19 11:37:15 +00:00
|
|
|
)->setDuration(
|
|
|
|
st::infoSlideDuration
|
2017-10-04 12:39:59 +00:00
|
|
|
)->toggleOn(
|
2017-11-20 12:32:55 +00:00
|
|
|
rpl::duplicate(forked) | rpl::map(_1 > 0)
|
2017-11-19 11:37:15 +00:00
|
|
|
);
|
2017-10-04 12:39:59 +00:00
|
|
|
tracker.track(button);
|
|
|
|
return button;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline auto AddButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2017-10-04 12:39:59 +00:00
|
|
|
not_null<PeerData*> peer,
|
2022-10-11 15:08:19 +00:00
|
|
|
MsgId topicRootId,
|
2017-10-31 18:25:22 +00:00
|
|
|
PeerData *migrated,
|
2017-10-04 12:39:59 +00:00
|
|
|
Type type,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
auto result = AddCountedButton(
|
|
|
|
parent,
|
2022-10-11 15:08:19 +00:00
|
|
|
Profile::SharedMediaCountValue(peer, topicRootId, migrated, type),
|
2017-10-04 12:39:59 +00:00
|
|
|
MediaText(type),
|
|
|
|
tracker)->entity();
|
2017-12-04 07:33:33 +00:00
|
|
|
result->addClickHandler([=] {
|
2022-10-12 12:57:17 +00:00
|
|
|
const auto topic = topicRootId
|
|
|
|
? peer->forumTopicFor(topicRootId)
|
|
|
|
: nullptr;
|
|
|
|
if (topicRootId && !topic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
navigation->showSection(topicRootId
|
|
|
|
? std::make_shared<Info::Memento>(topic, Section(type))
|
|
|
|
: std::make_shared<Info::Memento>(peer, Section(type)));
|
2017-10-04 12:39:59 +00:00
|
|
|
});
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-10-04 12:39:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline auto AddCommonGroupsButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2017-10-04 12:39:59 +00:00
|
|
|
not_null<UserData*> user,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
auto result = AddCountedButton(
|
|
|
|
parent,
|
|
|
|
Profile::CommonGroupsCountValue(user),
|
|
|
|
[](int count) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_profile_common_groups(tr::now, lt_count, count);
|
2017-10-04 12:39:59 +00:00
|
|
|
},
|
|
|
|
tracker)->entity();
|
2017-12-04 07:33:33 +00:00
|
|
|
result->addClickHandler([=] {
|
|
|
|
navigation->showSection(
|
2023-11-28 08:54:17 +00:00
|
|
|
std::make_shared<Info::Memento>(
|
|
|
|
user,
|
|
|
|
Section::Type::CommonGroups));
|
|
|
|
});
|
|
|
|
return result;
|
2023-12-28 14:52:13 +00:00
|
|
|
}
|
2023-11-28 08:54:17 +00:00
|
|
|
|
|
|
|
inline auto AddSimilarChannelsButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
auto result = AddCountedButton(
|
|
|
|
parent,
|
|
|
|
Profile::SimilarChannelsCountValue(channel),
|
|
|
|
[](int count) {
|
|
|
|
return tr::lng_profile_similar_channels(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
count);
|
|
|
|
},
|
|
|
|
tracker)->entity();
|
|
|
|
result->addClickHandler([=] {
|
|
|
|
navigation->showSection(
|
|
|
|
std::make_shared<Info::Memento>(
|
|
|
|
channel,
|
|
|
|
Section::Type::SimilarChannels));
|
2017-10-04 12:39:59 +00:00
|
|
|
});
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2023-12-28 14:52:13 +00:00
|
|
|
}
|
2017-10-04 12:39:59 +00:00
|
|
|
|
2023-06-05 16:31:15 +00:00
|
|
|
inline auto AddStoriesButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2023-09-01 11:20:55 +00:00
|
|
|
not_null<PeerData*> peer,
|
2023-06-05 16:31:15 +00:00
|
|
|
Ui::MultiSlideTracker &tracker) {
|
2023-06-07 15:56:38 +00:00
|
|
|
auto count = rpl::single(0) | rpl::then(Data::SavedStoriesIds(
|
2023-09-01 11:20:55 +00:00
|
|
|
peer,
|
2023-06-05 16:31:15 +00:00
|
|
|
ServerMaxStoryId - 1,
|
|
|
|
0
|
|
|
|
) | rpl::map([](const Data::StoriesIdsSlice &slice) {
|
2023-06-07 15:56:38 +00:00
|
|
|
return slice.fullCount().value_or(0);
|
|
|
|
}));
|
2023-09-05 07:07:32 +00:00
|
|
|
const auto phrase = peer->isChannel() ? (+[](int count) {
|
|
|
|
return tr::lng_profile_posts(tr::now, lt_count, count);
|
|
|
|
}) : (+[](int count) {
|
|
|
|
return tr::lng_profile_saved_stories(tr::now, lt_count, count);
|
|
|
|
});
|
2023-06-05 16:31:15 +00:00
|
|
|
auto result = AddCountedButton(
|
|
|
|
parent,
|
|
|
|
std::move(count),
|
2023-09-05 07:07:32 +00:00
|
|
|
phrase,
|
2023-06-05 16:31:15 +00:00
|
|
|
tracker)->entity();
|
|
|
|
result->addClickHandler([=] {
|
2023-09-01 11:20:55 +00:00
|
|
|
navigation->showSection(Info::Stories::Make(peer));
|
2023-06-05 16:31:15 +00:00
|
|
|
});
|
|
|
|
return result;
|
2023-12-28 14:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline auto AddSavedSublistButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
auto result = AddCountedButton(
|
|
|
|
parent,
|
|
|
|
Profile::SavedSublistCountValue(peer),
|
|
|
|
[](int count) {
|
|
|
|
return tr::lng_profile_saved_messages(tr::now, lt_count, count);
|
|
|
|
},
|
|
|
|
tracker)->entity();
|
|
|
|
result->addClickHandler([=] {
|
|
|
|
navigation->showSection(
|
|
|
|
std::make_shared<HistoryView::SublistMemento>(
|
|
|
|
peer->owner().savedMessages().sublist(peer)));
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
2023-06-05 16:31:15 +00:00
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
} // namespace Info::Media
|