mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to report profile photo from peer info section.
This commit is contained in:
parent
71357a9546
commit
60e7aa90d2
2 changed files with 57 additions and 3 deletions
|
@ -24,13 +24,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/profile/info_profile_emoji_status_panel.h"
|
#include "info/profile/info_profile_emoji_status_panel.h"
|
||||||
#include "info/info_controller.h"
|
#include "info/info_controller.h"
|
||||||
#include "boxes/peers/edit_forum_topic_box.h"
|
#include "boxes/peers/edit_forum_topic_box.h"
|
||||||
|
#include "boxes/report_messages_box.h"
|
||||||
#include "history/view/media/history_view_sticker_player.h"
|
#include "history/view/media/history_view_sticker_player.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/boxes/show_or_premium_box.h"
|
#include "ui/boxes/show_or_premium_box.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -41,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
namespace Info::Profile {
|
namespace Info::Profile {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -504,7 +508,7 @@ void Cover::refreshUploadPhotoOverlay() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_userpic->switchChangePhotoOverlay([&] {
|
const auto canChange = [&] {
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
return chat->canEditInformation();
|
return chat->canEditInformation();
|
||||||
} else if (const auto channel = _peer->asChannel()) {
|
} else if (const auto channel = _peer->asChannel()) {
|
||||||
|
@ -516,7 +520,10 @@ void Cover::refreshUploadPhotoOverlay() {
|
||||||
&& !user->isServiceUser());
|
&& !user->isServiceUser());
|
||||||
}
|
}
|
||||||
Unexpected("Peer type in Info::Profile::Cover.");
|
Unexpected("Peer type in Info::Profile::Cover.");
|
||||||
}(), [=](Ui::UserpicButton::ChosenImage chosen) {
|
}();
|
||||||
|
|
||||||
|
_userpic->switchChangePhotoOverlay(canChange, [=](
|
||||||
|
Ui::UserpicButton::ChosenImage chosen) {
|
||||||
using ChosenType = Ui::UserpicButton::ChosenType;
|
using ChosenType = Ui::UserpicButton::ChosenType;
|
||||||
auto result = Api::PeerPhoto::UserPhoto{
|
auto result = Api::PeerPhoto::UserPhoto{
|
||||||
base::take<QImage>(chosen.image), // Strange MSVC bug with take.
|
base::take<QImage>(chosen.image), // Strange MSVC bug with take.
|
||||||
|
@ -538,6 +545,53 @@ void Cover::refreshUploadPhotoOverlay() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const auto canReport = [=, peer = _peer] {
|
||||||
|
if (!peer->hasUserpic()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto user = peer->asUser();
|
||||||
|
if (!user) {
|
||||||
|
if (canChange) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (user->hasPersonalPhoto()
|
||||||
|
|| user->isSelf()
|
||||||
|
|| user->isInaccessible()
|
||||||
|
|| user->isRepliesChat()
|
||||||
|
|| (user->botInfo && user->botInfo->canEditInformation)
|
||||||
|
|| user->isServiceUser()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto contextMenu = _userpic->lifetime()
|
||||||
|
.make_state<base::unique_qptr<Ui::PopupMenu>>();
|
||||||
|
const auto showMenu = [=, peer = _peer, controller = _controller](
|
||||||
|
not_null<Ui::RpWidget*> parent) {
|
||||||
|
if (!canReport()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*contextMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
parent,
|
||||||
|
st::popupMenuWithIcons);
|
||||||
|
contextMenu->get()->addAction(tr::lng_profile_report(tr::now), [=] {
|
||||||
|
controller->show(
|
||||||
|
ReportProfilePhotoBox(
|
||||||
|
peer,
|
||||||
|
peer->owner().photo(peer->userpicPhotoId())),
|
||||||
|
Ui::LayerOption::CloseOther);
|
||||||
|
}, &st::menuIconReport);
|
||||||
|
contextMenu->get()->popup(QCursor::pos());
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
base::install_event_filter(_userpic, [showMenu, raw = _userpic.data()](
|
||||||
|
not_null<QEvent*> e) {
|
||||||
|
return (e->type() == QEvent::ContextMenu && showMenu(raw))
|
||||||
|
? base::EventFilterResult::Cancel
|
||||||
|
: base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
|
||||||
if (const auto user = _peer->asUser()) {
|
if (const auto user = _peer->asUser()) {
|
||||||
_userpic->resetPersonalRequests(
|
_userpic->resetPersonalRequests(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
|
|
@ -149,7 +149,7 @@ private:
|
||||||
const std::unique_ptr<Badge> _badge;
|
const std::unique_ptr<Badge> _badge;
|
||||||
rpl::variable<int> _onlineCount;
|
rpl::variable<int> _onlineCount;
|
||||||
|
|
||||||
object_ptr<Ui::UserpicButton> _userpic;
|
const object_ptr<Ui::UserpicButton> _userpic;
|
||||||
Ui::UserpicButton *_changePersonal = nullptr;
|
Ui::UserpicButton *_changePersonal = nullptr;
|
||||||
std::optional<QImage> _personalChosen;
|
std::optional<QImage> _personalChosen;
|
||||||
object_ptr<TopicIconButton> _iconButton;
|
object_ptr<TopicIconButton> _iconButton;
|
||||||
|
|
Loading…
Add table
Reference in a new issue