mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Added initial ability to open media calendar from info media sections.
This commit is contained in:
@@ -7528,6 +7528,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_summarize_header_title" = "AI summary";
|
||||
"lng_summarize_header_about" = "Click to see original text";
|
||||
|
||||
"lng_calendar" = "Calendar";
|
||||
|
||||
// Wnd specific
|
||||
|
||||
"lng_wnd_choose_program_menu" = "Choose Default Program...";
|
||||
|
||||
@@ -462,6 +462,8 @@ void WrapWidget::setupTopBarMenuToggle() {
|
||||
button->addClickHandler([=] {
|
||||
_controller->showSettings(::Settings::InformationId());
|
||||
});
|
||||
} else if (section.type() == Section::Type::Media) {
|
||||
addTopBarMenuButton();
|
||||
} else if (section.type() == Section::Type::Downloads) {
|
||||
auto &manager = Core::App().downloadManager();
|
||||
rpl::merge(
|
||||
|
||||
@@ -10,7 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history.h"
|
||||
#include "info/media/info_media_inner_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "data/data_session.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/search_field_controller.h"
|
||||
#include "ui/ui_utility.h"
|
||||
@@ -20,7 +22,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
||||
namespace Info::Media {
|
||||
|
||||
@@ -152,6 +156,27 @@ void Widget::selectionAction(SelectionAction action) {
|
||||
_inner->selectionAction(action);
|
||||
}
|
||||
|
||||
void Widget::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
|
||||
const auto type = controller()->section().mediaType();
|
||||
if (type != Type::Photo && type != Type::Video) {
|
||||
return;
|
||||
}
|
||||
addAction(tr::lng_calendar(tr::now), [=] {
|
||||
controller()->parentController()->showCalendar({
|
||||
.chat = Dialogs::Key(
|
||||
controller()->session().data().history(
|
||||
controller()->key().peer())),
|
||||
.date = QDate::currentDate(),
|
||||
.mediaPhoto = (type == Type::Photo),
|
||||
.mediaVideo = (type == Type::Video),
|
||||
.customJump = [=](const QDate &date, Fn<void()> close) {
|
||||
_inner->jumpToDate(date, [](auto){});
|
||||
close();
|
||||
},
|
||||
});
|
||||
}, &st::menuIconSchedule);
|
||||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
if (controller()->key().peer()->sharedMediaInfo() && isStackBottom()) {
|
||||
return tr::lng_profile_shared_media();
|
||||
|
||||
@@ -125,6 +125,8 @@ public:
|
||||
rpl::producer<SelectedItems> selectedListValue() const override;
|
||||
void selectionAction(SelectionAction action) override;
|
||||
|
||||
void fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) override;
|
||||
|
||||
rpl::producer<QString> title() override;
|
||||
|
||||
void jumpToDate(const QDate &date, Fn<void(FullMsgId)> callback);
|
||||
|
||||
@@ -61,6 +61,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_web_page.h"
|
||||
#include "data/data_search_calendar.h"
|
||||
#include "dialogs/ui/chat_search_in.h"
|
||||
#include "passport/passport_form_controller.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
@@ -350,9 +351,9 @@ void DateClickHandler::onClick(ClickContext context) const {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto window = my.sessionWindow.get()) {
|
||||
if (!_chat.topic()) {
|
||||
window->showCalendar({ _chat, _date });
|
||||
window->showCalendar({ _chat, _date, true, true });
|
||||
} else if (const auto strong = _weak.get()) {
|
||||
window->showCalendar({ strong, _date });
|
||||
window->showCalendar({ strong, _date, true, true });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2810,6 +2811,31 @@ void SessionController::showCalendar(ShowCalendarDescriptor &&descriptor) {
|
||||
button->setPointerCursor(false);
|
||||
}
|
||||
};
|
||||
const auto dynamicImageForDate = [&, peerId = history->peer->id] {
|
||||
using ReturnType = Fn<void(QDate, Ui::CalendarImageSetter)>;
|
||||
if (!descriptor.mediaPhoto && !descriptor.mediaVideo) {
|
||||
return ReturnType(nullptr);
|
||||
}
|
||||
const auto search = std::make_shared<Api::SearchCalendarController>(
|
||||
&session(),
|
||||
(descriptor.mediaPhoto && descriptor.mediaVideo)
|
||||
? Storage::SharedMediaType::PhotoVideo
|
||||
: descriptor.mediaPhoto
|
||||
? Storage::SharedMediaType::Photo
|
||||
: Storage::SharedMediaType::Video);
|
||||
return (ReturnType)[=](QDate date, Ui::CalendarImageSetter set) {
|
||||
search->monthThumbnails(
|
||||
peerId,
|
||||
base::unixtime::serialize(QDateTime(date, QTime())),
|
||||
[=](const std::vector<Api::DayThumbnail> &thumbnails) {
|
||||
for (const auto &thumb : thumbnails) {
|
||||
set(
|
||||
base::unixtime::parse(thumb.date).date(),
|
||||
thumb.image);
|
||||
}
|
||||
});
|
||||
};
|
||||
}();
|
||||
const auto weak = base::make_weak(this);
|
||||
const auto weakTopic = base::make_weak(topic);
|
||||
const auto jump = [=](const QDate &date, Fn<void()> close) {
|
||||
@@ -2836,11 +2862,12 @@ void SessionController::showCalendar(ShowCalendarDescriptor &&descriptor) {
|
||||
show(Box<Ui::CalendarBox>(Ui::CalendarBoxArgs{
|
||||
.month = highlighted,
|
||||
.highlighted = highlighted,
|
||||
.callback = jump,
|
||||
.callback = descriptor.customJump ? descriptor.customJump : jump,
|
||||
.minDate = minPeerDate,
|
||||
.maxDate = maxPeerDate,
|
||||
.allowsSelection = history->peer->isUser(),
|
||||
.selectionChanged = selectionChanged,
|
||||
.dynamicImageForDate = dynamicImageForDate,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -545,6 +545,9 @@ public:
|
||||
struct ShowCalendarDescriptor {
|
||||
Dialogs::Key chat;
|
||||
QDate date;
|
||||
bool mediaPhoto = false;
|
||||
bool mediaVideo = false;
|
||||
Fn<void(const QDate &, Fn<void()>)> customJump;
|
||||
};
|
||||
void showCalendar(ShowCalendarDescriptor &&descriptor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user