Removed redundant template from Info::Media::AddCountedButton.

This commit is contained in:
23rd 2025-01-30 13:12:18 +03:00
parent ef9f7ab27a
commit 1d8a7f8fd3
6 changed files with 294 additions and 229 deletions

View file

@ -7,14 +7,28 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/media/info_media_buttons.h"
#include "base/call_delayed.h"
#include "base/qt/qt_key_modifiers.h"
#include "data/data_channel.h"
#include "data/data_saved_messages.h"
#include "data/data_session.h"
#include "data/data_stories_ids.h"
#include "data/data_user.h"
#include "history/view/history_view_sublist_section.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
#include "info/profile/info_profile_values.h"
#include "info/stories/info_stories_widget.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "window/window_separate_id.h"
#include "window/window_session_controller.h"
#include "styles/style_info.h"
#include "styles/style_menu_icons.h"
namespace Info {
namespace Media {
namespace Info::Media {
namespace {
Window::SeparateSharedMediaType ToSeparateType(
@ -38,8 +52,6 @@ Window::SeparateSharedMediaType ToSeparateType(
: SeparatedType::None;
}
} // namespace
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
@ -83,5 +95,218 @@ void AddContextMenuToButton(
});
}
} // namespace Media
} // namespace Info
} // namespace
tr::phrase<lngtag_count> MediaTextPhrase(Type type) {
switch (type) {
case Type::Photo: return tr::lng_profile_photos;
case Type::GIF: return tr::lng_profile_gifs;
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;
}
Unexpected("Type in MediaTextPhrase()");
};
Fn<QString(int)> MediaText(Type type) {
return [phrase = MediaTextPhrase(type)](int count) {
return phrase(tr::now, lt_count, count);
};
}
not_null<Ui::SlideWrap<Ui::SettingsButton>*> AddCountedButton(
Ui::VerticalLayout *parent,
rpl::producer<int> &&count,
Fn<QString(int)> &&textFromCount,
Ui::MultiSlideTracker &tracker) {
using namespace ::Settings;
auto forked = std::move(count)
| start_spawning(parent->lifetime());
auto text = rpl::duplicate(
forked
) | rpl::map([textFromCount](int count) {
return (count > 0)
? textFromCount(count)
: QString();
});
auto button = parent->add(object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
parent,
object_ptr<Ui::SettingsButton>(
parent,
std::move(text),
st::infoSharedMediaButton))
)->setDuration(
st::infoSlideDuration
)->toggleOn(
rpl::duplicate(forked) | rpl::map(rpl::mappers::_1 > 0)
);
tracker.track(button);
return button;
};
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
MsgId topicRootId,
Type type);
void AddContextMenuToButton(
not_null<Ui::AbstractButton*> button,
Fn<void()> openInWindow);
not_null<Ui::SettingsButton*> AddButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
MsgId topicRootId,
PeerData *migrated,
Type type,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::SharedMediaCountValue(peer, topicRootId, migrated, type),
MediaText(type),
tracker)->entity();
const auto openInWindow = SeparateWindowFactory(
navigation->parentController(),
peer,
topicRootId,
type);
AddContextMenuToButton(result, openInWindow);
result->addClickHandler([=](Qt::MouseButton mouse) {
if (mouse == Qt::RightButton) {
return;
}
if (openInWindow
&& (base::IsCtrlPressed() || mouse == Qt::MiddleButton)) {
return openInWindow();
}
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)));
});
return result;
};
not_null<Ui::SettingsButton*> AddCommonGroupsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::CommonGroupsCountValue(user),
[](int count) {
return tr::lng_profile_common_groups(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
user,
Section::Type::CommonGroups));
});
return result;
}
not_null<Ui::SettingsButton*> AddSimilarPeersButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::SimilarPeersCountValue(peer),
[=](int count) {
return peer->isBroadcast()
? tr::lng_profile_similar_channels(tr::now, lt_count, count)
: tr::lng_profile_similar_bots(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
peer,
Section::Type::SimilarPeers));
});
return result;
}
not_null<Ui::SettingsButton*> AddStoriesButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto count = rpl::single(0) | rpl::then(Data::SavedStoriesIds(
peer,
ServerMaxStoryId - 1,
0
) | rpl::map([](const Data::StoriesIdsSlice &slice) {
return slice.fullCount().value_or(0);
}));
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);
});
auto result = AddCountedButton(
parent,
std::move(count),
phrase,
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(Info::Stories::Make(peer));
});
return result;
}
not_null<Ui::SettingsButton*> 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;
}
not_null<Ui::SettingsButton*> AddPeerGiftsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::PeerGiftsCountValue(peer),
[](int count) {
return tr::lng_profile_peer_gifts(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
peer,
Section::Type::PeerGifts));
});
return result;
}
} // namespace Info::Media

View file

@ -7,244 +7,73 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include <rpl/mappers.h>
#include <rpl/map.h>
#include "lang/lang_keys.h"
#include "base/qt/qt_key_modifiers.h"
#include "data/data_saved_messages.h"
#include "data/data_session.h"
#include "data/data_stories_ids.h"
#include "storage/storage_shared_media.h"
#include "history/view/history_view_sublist_section.h"
#include "info/info_memento.h"
#include "info/info_controller.h"
#include "info/profile/info_profile_values.h"
#include "info/stories/info_stories_widget.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/widgets/buttons.h"
#include "window/window_session_controller.h"
#include "data/data_channel.h"
#include "data/data_user.h"
#include "styles/style_info.h"
namespace Ui {
class AbstractButton;
class MultiSlideTracker;
class SettingsButton;
class VerticalLayout;
template <typename Widget>
class SlideWrap;
} // namespace Ui
namespace Window {
class SessionNavigation;
} // namespace Window
namespace Info::Media {
using Type = Storage::SharedMediaType;
inline tr::phrase<lngtag_count> MediaTextPhrase(Type type) {
switch (type) {
case Type::Photo: return tr::lng_profile_photos;
case Type::GIF: return tr::lng_profile_gifs;
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;
}
Unexpected("Type in MediaTextPhrase()");
};
[[nodiscard]] tr::phrase<lngtag_count> MediaTextPhrase(Type type);
inline auto MediaText(Type type) {
return [phrase = MediaTextPhrase(type)](int count) {
return phrase(tr::now, lt_count, count);
};
}
[[nodiscard]] Fn<QString(int)> MediaText(Type type);
template <typename Count, typename Text>
inline auto AddCountedButton(
Ui::VerticalLayout *parent,
Count &&count,
Text &&textFromCount,
Ui::MultiSlideTracker &tracker) {
using namespace rpl::mappers;
[[nodiscard]] not_null<Ui::SlideWrap<Ui::SettingsButton>*> AddCountedButton(
Ui::VerticalLayout *parent,
rpl::producer<int> &&count,
Fn<QString(int)> &&textFromCount,
Ui::MultiSlideTracker &tracker);
using namespace ::Settings;
auto forked = std::move(count)
| start_spawning(parent->lifetime());
auto text = rpl::duplicate(
forked
) | rpl::map([textFromCount](int count) {
return (count > 0)
? textFromCount(count)
: QString();
});
auto button = parent->add(object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
parent,
object_ptr<Ui::SettingsButton>(
parent,
std::move(text),
st::infoSharedMediaButton))
)->setDuration(
st::infoSlideDuration
)->toggleOn(
rpl::duplicate(forked) | rpl::map(_1 > 0)
);
tracker.track(button);
return button;
};
Fn<void()> SeparateWindowFactory(
not_null<Window::SessionController*> controller,
[[nodiscard]] not_null<Ui::SettingsButton*> AddButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
MsgId topicRootId,
Type type);
PeerData *migrated,
Type type,
Ui::MultiSlideTracker &tracker);
void AddContextMenuToButton(
not_null<Ui::AbstractButton*> button,
Fn<void()> openInWindow);
[[nodiscard]] not_null<Ui::SettingsButton*> AddCommonGroupsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user,
Ui::MultiSlideTracker &tracker);
inline auto AddButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
MsgId topicRootId,
PeerData *migrated,
Type type,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::SharedMediaCountValue(peer, topicRootId, migrated, type),
MediaText(type),
tracker)->entity();
const auto openInWindow = SeparateWindowFactory(
navigation->parentController(),
peer,
topicRootId,
type);
AddContextMenuToButton(result, openInWindow);
result->addClickHandler([=](Qt::MouseButton mouse) {
if (mouse == Qt::RightButton) {
return;
}
if (openInWindow
&& (base::IsCtrlPressed() || mouse == Qt::MiddleButton)) {
return openInWindow();
}
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)));
});
return result;
};
[[nodiscard]] not_null<Ui::SettingsButton*> AddSimilarPeersButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker);
inline auto AddCommonGroupsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::CommonGroupsCountValue(user),
[](int count) {
return tr::lng_profile_common_groups(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
user,
Section::Type::CommonGroups));
});
return result;
}
[[nodiscard]] not_null<Ui::SettingsButton*> AddStoriesButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker);
inline auto AddSimilarPeersButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::SimilarPeersCountValue(peer),
[=](int count) {
return peer->isBroadcast()
? tr::lng_profile_similar_channels(tr::now, lt_count, count)
: tr::lng_profile_similar_bots(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
peer,
Section::Type::SimilarPeers));
});
return result;
}
[[nodiscard]] not_null<Ui::SettingsButton*> AddSavedSublistButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker);
inline auto AddStoriesButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto count = rpl::single(0) | rpl::then(Data::SavedStoriesIds(
peer,
ServerMaxStoryId - 1,
0
) | rpl::map([](const Data::StoriesIdsSlice &slice) {
return slice.fullCount().value_or(0);
}));
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);
});
auto result = AddCountedButton(
parent,
std::move(count),
phrase,
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(Info::Stories::Make(peer));
});
return result;
}
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;
}
inline auto AddPeerGiftsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker) {
auto result = AddCountedButton(
parent,
Profile::PeerGiftsCountValue(peer),
[](int count) {
return tr::lng_profile_peer_gifts(tr::now, lt_count, count);
},
tracker)->entity();
result->addClickHandler([=] {
navigation->showSection(
std::make_shared<Info::Memento>(
peer,
Section::Type::PeerGifts));
});
return result;
}
[[nodiscard]] not_null<Ui::SettingsButton*> AddPeerGiftsButton(
Ui::VerticalLayout *parent,
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Ui::MultiSlideTracker &tracker);
} // namespace Info::Media

View file

@ -15,10 +15,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/profile/info_profile_icon.h"
#include "info/info_controller.h"
#include "data/data_forum_topic.h"
#include "data/data_peer.h"
#include "ui/widgets/discrete_sliders.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/box_content_divider.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/search_field_controller.h"
#include "styles/style_info.h"

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/profile/info_profile_inner_widget.h"
#include "info/info_controller.h"
#include "info/profile/info_profile_widget.h"
#include "info/profile/info_profile_cover.h"
#include "info/profile/info_profile_icon.h"
@ -14,9 +15,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/profile/info_profile_actions.h"
#include "info/media/info_media_buttons.h"
#include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_forum_topic.h"
#include "data/data_peer.h"
#include "data/data_photo.h"
#include "data/data_file_origin.h"
#include "data/data_user.h"
#include "main/main_session.h"
#include "apiwrap.h"
#include "api/api_peer_photo.h"
@ -25,7 +29,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/checkbox.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/shadow.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/ui_utility.h"
#include "styles/style_info.h"
namespace Info {
namespace Profile {

View file

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "lang/lang_keys.h"
#include "ui/widgets/box_content_divider.h"
#include "ui/widgets/buttons.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/ui_utility.h"

View file

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/media/info_media_list_widget.h"
#include "info/profile/info_profile_actions.h"
#include "info/profile/info_profile_icon.h"
#include "info/profile/info_profile_values.h"
#include "info/profile/info_profile_widget.h"
#include "info/stories/info_stories_widget.h"
#include "info/info_controller.h"