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_button.h"
|
|
|
|
#include "info/profile/info_profile_values.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "window/window_controller.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
using Type = Storage::SharedMediaType;
|
|
|
|
|
|
|
|
inline auto MediaTextPhrase(Type type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Photo: return lng_profile_photos;
|
|
|
|
case Type::Video: return lng_profile_videos;
|
|
|
|
case Type::File: return lng_profile_files;
|
|
|
|
case Type::MusicFile: return lng_profile_songs;
|
|
|
|
case Type::Link: return lng_profile_shared_links;
|
|
|
|
case Type::VoiceFile: return lng_profile_audios;
|
2017-11-14 17:22:44 +00:00
|
|
|
// case Type::RoundFile: return lng_profile_rounds;
|
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) {
|
|
|
|
return phrase(lt_count, count);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Count, typename Text>
|
|
|
|
inline auto AddCountedButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
|
|
|
Count &&count,
|
|
|
|
Text &&textFromCount,
|
|
|
|
Ui::MultiSlideTracker &tracker) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
using Button = Profile::Button;
|
|
|
|
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,
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> 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(
|
2017-10-04 12:39:59 +00:00
|
|
|
Info::Memento(peer->id, Section(type)));
|
|
|
|
});
|
|
|
|
return std::move(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
inline auto AddCommonGroupsButton(
|
|
|
|
Ui::VerticalLayout *parent,
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> 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) {
|
|
|
|
return lng_profile_common_groups(lt_count, count);
|
|
|
|
},
|
|
|
|
tracker)->entity();
|
2017-12-04 07:33:33 +00:00
|
|
|
result->addClickHandler([=] {
|
|
|
|
navigation->showSection(
|
2017-10-31 18:25:22 +00:00
|
|
|
Info::Memento(user->id, Section::Type::CommonGroups));
|
2017-10-04 12:39:59 +00:00
|
|
|
});
|
|
|
|
return std::move(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Media
|
|
|
|
} // namespace Info
|