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"
|
|
|
|
#include "storage/storage_shared_media.h"
|
|
|
|
#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"
|
|
|
|
#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"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2019-11-02 17:06:47 +00:00
|
|
|
using Button = Ui::SettingsButton;
|
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();
|
|
|
|
});
|
2017-10-04 12:39:59 +00:00
|
|
|
auto button = parent->add(object_ptr<Ui::SlideWrap<Button>>(
|
|
|
|
parent,
|
|
|
|
object_ptr<Button>(
|
|
|
|
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,
|
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,
|
2017-10-31 18:25:22 +00:00
|
|
|
Profile::SharedMediaCountValue(peer, migrated, type),
|
2017-10-04 12:39:59 +00:00
|
|
|
MediaText(type),
|
|
|
|
tracker)->entity();
|
2017-12-04 07:33:33 +00:00
|
|
|
result->addClickHandler([=] {
|
|
|
|
navigation->showSection(
|
2020-12-14 14:48:10 +00:00
|
|
|
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(
|
2020-12-14 14:48:10 +00:00
|
|
|
std::make_shared<Info::Memento>(user, Section::Type::CommonGroups));
|
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
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Media
|
2019-11-12 15:15:34 +00:00
|
|
|
} // namespace Info
|