Add user actions to info profile.
This commit is contained in:
		
							parent
							
								
									f50bf0b97f
								
							
						
					
					
						commit
						4180ed09a5
					
				
					 4 changed files with 103 additions and 16 deletions
				
			
		| 
						 | 
					@ -560,8 +560,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
"lng_profile_bio" = "Bio:";
 | 
					"lng_profile_bio" = "Bio:";
 | 
				
			||||||
"lng_profile_add_contact" = "Add Contact";
 | 
					"lng_profile_add_contact" = "Add Contact";
 | 
				
			||||||
"lng_profile_edit_contact" = "Edit";
 | 
					"lng_profile_edit_contact" = "Edit";
 | 
				
			||||||
"lng_profile_clear_history" = "Clear history";
 | 
					 | 
				
			||||||
"lng_profile_delete_conversation" = "Delete conversation";
 | 
					 | 
				
			||||||
"lng_profile_clear_and_exit" = "Delete and exit";
 | 
					"lng_profile_clear_and_exit" = "Delete and exit";
 | 
				
			||||||
"lng_profile_leave_channel" = "Leave channel";
 | 
					"lng_profile_leave_channel" = "Leave channel";
 | 
				
			||||||
"lng_profile_delete_channel" = "Delete channel";
 | 
					"lng_profile_delete_channel" = "Delete channel";
 | 
				
			||||||
| 
						 | 
					@ -569,11 +567,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
"lng_profile_delete_group" = "Delete group";
 | 
					"lng_profile_delete_group" = "Delete group";
 | 
				
			||||||
"lng_profile_report" = "Report";
 | 
					"lng_profile_report" = "Report";
 | 
				
			||||||
"lng_profile_search_messages" = "Search for messages";
 | 
					"lng_profile_search_messages" = "Search for messages";
 | 
				
			||||||
"lng_profile_block_user" = "Block user";
 | 
					 | 
				
			||||||
"lng_profile_unblock_user" = "Unblock user";
 | 
					 | 
				
			||||||
"lng_profile_block_bot" = "Stop and block bot";
 | 
					"lng_profile_block_bot" = "Stop and block bot";
 | 
				
			||||||
"lng_profile_unblock_bot" = "Unblock bot";
 | 
					"lng_profile_unblock_bot" = "Unblock bot";
 | 
				
			||||||
"lng_profile_share_contact" = "Share Contact";
 | 
					 | 
				
			||||||
"lng_profile_invite_to_group" = "Add to Group";
 | 
					"lng_profile_invite_to_group" = "Add to Group";
 | 
				
			||||||
"lng_profile_delete_contact" = "Delete";
 | 
					"lng_profile_delete_contact" = "Delete";
 | 
				
			||||||
"lng_profile_set_group_photo" = "Set Photo";
 | 
					"lng_profile_set_group_photo" = "Set Photo";
 | 
				
			||||||
| 
						 | 
					@ -635,6 +630,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
"lng_media_type_links" = "Shared links";
 | 
					"lng_media_type_links" = "Shared links";
 | 
				
			||||||
"lng_media_type_rounds" = "Video messages";
 | 
					"lng_media_type_rounds" = "Video messages";
 | 
				
			||||||
"lng_profile_common_groups_section" = "Groups in common";
 | 
					"lng_profile_common_groups_section" = "Groups in common";
 | 
				
			||||||
 | 
					"lng_profile_share_contact" = "Share Contact";
 | 
				
			||||||
 | 
					"lng_info_edit_contact" = "Edit contact";
 | 
				
			||||||
 | 
					"lng_profile_clear_history" = "Clear history";
 | 
				
			||||||
 | 
					"lng_profile_delete_conversation" = "Delete conversation";
 | 
				
			||||||
 | 
					"lng_profile_block_user" = "Block user";
 | 
				
			||||||
 | 
					"lng_profile_unblock_user" = "Unblock user";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"lng_report_title" = "Report channel";
 | 
					"lng_report_title" = "Report channel";
 | 
				
			||||||
"lng_report_group_title" = "Report group";
 | 
					"lng_report_group_title" = "Report group";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -149,7 +149,6 @@ infoProfileSeparatorPadding: margins(
 | 
				
			||||||
	infoProfileSkip);
 | 
						infoProfileSkip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
infoIconFg: menuIconFg;
 | 
					infoIconFg: menuIconFg;
 | 
				
			||||||
infoIconPosition: point(20px, 12px);
 | 
					 | 
				
			||||||
infoIconInformation: icon {{ "info_information", infoIconFg }};
 | 
					infoIconInformation: icon {{ "info_information", infoIconFg }};
 | 
				
			||||||
infoIconMembers: icon {{ "info_members", infoIconFg }};
 | 
					infoIconMembers: icon {{ "info_members", infoIconFg }};
 | 
				
			||||||
infoIconNotifications: icon {{ "info_notifications", infoIconFg }};
 | 
					infoIconNotifications: icon {{ "info_notifications", infoIconFg }};
 | 
				
			||||||
| 
						 | 
					@ -158,7 +157,7 @@ infoIconMediaPhoto: icon {{ "info_media_photo", infoIconFg }};
 | 
				
			||||||
infoInformationIconPosition: point(25px, 12px);
 | 
					infoInformationIconPosition: point(25px, 12px);
 | 
				
			||||||
infoNotificationsIconPosition: point(20px, 5px);
 | 
					infoNotificationsIconPosition: point(20px, 5px);
 | 
				
			||||||
infoSharedMediaIconPosition: point(20px, 24px);
 | 
					infoSharedMediaIconPosition: point(20px, 24px);
 | 
				
			||||||
infoMembersIconPosition: point(20px, 15px);
 | 
					infoIconPosition: point(20px, 15px);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
infoLabeledOneLine: FlatLabel(defaultFlatLabel) {
 | 
					infoLabeledOneLine: FlatLabel(defaultFlatLabel) {
 | 
				
			||||||
	width: 0px; // No need to set minWidth in one-line text.
 | 
						width: 0px; // No need to set minWidth in one-line text.
 | 
				
			||||||
| 
						 | 
					@ -223,6 +222,12 @@ infoSharedMediaCoverHeight: 62px;
 | 
				
			||||||
infoSharedMediaButton: infoProfileButton;
 | 
					infoSharedMediaButton: infoProfileButton;
 | 
				
			||||||
infoSharedMediaBottomSkip: 12px;
 | 
					infoSharedMediaBottomSkip: 12px;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					infoBlockButton: InfoProfileButton(infoProfileButton) {
 | 
				
			||||||
 | 
						textFg: attentionButtonFg;
 | 
				
			||||||
 | 
						textFgOver: attentionButtonFgOver;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					infoBlockButtonSkip: 8px;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
infoMembersHeader: 56px;
 | 
					infoMembersHeader: 56px;
 | 
				
			||||||
infoMembersList: PeerList(defaultPeerList) {
 | 
					infoMembersList: PeerList(defaultPeerList) {
 | 
				
			||||||
	item: PeerListItem(defaultPeerListItem) {
 | 
						item: PeerListItem(defaultPeerListItem) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
#include "info/profile/info_profile_inner_widget.h"
 | 
					#include "info/profile/info_profile_inner_widget.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <rpl/combine.h>
 | 
					#include <rpl/combine.h>
 | 
				
			||||||
 | 
					#include <rpl/flatten_latest.h>
 | 
				
			||||||
#include "info/profile/info_profile_button.h"
 | 
					#include "info/profile/info_profile_button.h"
 | 
				
			||||||
#include "info/profile/info_profile_widget.h"
 | 
					#include "info/profile/info_profile_widget.h"
 | 
				
			||||||
#include "info/profile/info_profile_text.h"
 | 
					#include "info/profile/info_profile_text.h"
 | 
				
			||||||
| 
						 | 
					@ -30,11 +31,15 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
 | 
				
			||||||
#include "info/profile/info_profile_members.h"
 | 
					#include "info/profile/info_profile_members.h"
 | 
				
			||||||
#include "boxes/abstract_box.h"
 | 
					#include "boxes/abstract_box.h"
 | 
				
			||||||
#include "boxes/add_contact_box.h"
 | 
					#include "boxes/add_contact_box.h"
 | 
				
			||||||
 | 
					#include "boxes/confirm_box.h"
 | 
				
			||||||
#include "mainwidget.h"
 | 
					#include "mainwidget.h"
 | 
				
			||||||
 | 
					#include "auth_session.h"
 | 
				
			||||||
 | 
					#include "apiwrap.h"
 | 
				
			||||||
#include "window/window_controller.h"
 | 
					#include "window/window_controller.h"
 | 
				
			||||||
#include "storage/storage_shared_media.h"
 | 
					#include "storage/storage_shared_media.h"
 | 
				
			||||||
#include "lang/lang_keys.h"
 | 
					#include "lang/lang_keys.h"
 | 
				
			||||||
#include "styles/style_info.h"
 | 
					#include "styles/style_info.h"
 | 
				
			||||||
 | 
					#include "styles/style_boxes.h"
 | 
				
			||||||
#include "ui/widgets/buttons.h"
 | 
					#include "ui/widgets/buttons.h"
 | 
				
			||||||
#include "ui/widgets/checkbox.h"
 | 
					#include "ui/widgets/checkbox.h"
 | 
				
			||||||
#include "ui/widgets/scroll_area.h"
 | 
					#include "ui/widgets/scroll_area.h"
 | 
				
			||||||
| 
						 | 
					@ -368,18 +373,94 @@ object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
 | 
				
			||||||
		RpWidget *parent,
 | 
							RpWidget *parent,
 | 
				
			||||||
		not_null<UserData*> user) const {
 | 
							not_null<UserData*> user) const {
 | 
				
			||||||
	auto result = object_ptr<Ui::VerticalLayout>(parent);
 | 
						auto result = object_ptr<Ui::VerticalLayout>(parent);
 | 
				
			||||||
	auto tracker = MultiLineTracker();
 | 
						result->add(createSkipWidget(result));
 | 
				
			||||||
	auto addButton = [&](rpl::producer<QString> &&text) {
 | 
						auto addButton = [&](
 | 
				
			||||||
		auto button = result->add(object_ptr<Ui::SlideWrap<Button>>(
 | 
								rpl::producer<QString> &&text,
 | 
				
			||||||
 | 
								rpl::producer<bool> &&toggleOn,
 | 
				
			||||||
 | 
								auto &&callback,
 | 
				
			||||||
 | 
								const style::InfoProfileButton &st
 | 
				
			||||||
 | 
									= st::infoSharedMediaButton) {
 | 
				
			||||||
 | 
							return result->add(object_ptr<Ui::SlideWrap<Button>>(
 | 
				
			||||||
			result,
 | 
								result,
 | 
				
			||||||
			object_ptr<Button>(
 | 
								object_ptr<Button>(
 | 
				
			||||||
				result,
 | 
									result,
 | 
				
			||||||
				std::move(text),
 | 
									std::move(text),
 | 
				
			||||||
				st::infoSharedMediaButton)));
 | 
									st))
 | 
				
			||||||
		tracker.track(button);
 | 
							)->toggleOn(
 | 
				
			||||||
		return button;
 | 
								std::move(toggleOn)
 | 
				
			||||||
 | 
							)->entity()->clicks()
 | 
				
			||||||
 | 
								| rpl::start([callback = std::move(callback)](auto&&) {
 | 
				
			||||||
 | 
									callback();
 | 
				
			||||||
 | 
								}, result->lifetime());
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	addButton(rpl::single(QString("test action")));
 | 
					
 | 
				
			||||||
 | 
						addButton(
 | 
				
			||||||
 | 
							Lang::Viewer(lng_profile_share_contact),
 | 
				
			||||||
 | 
							CanShareContactValue(user),
 | 
				
			||||||
 | 
							[user] { App::main()->shareContactLayer(user); });
 | 
				
			||||||
 | 
						addButton(
 | 
				
			||||||
 | 
							Lang::Viewer(lng_info_edit_contact),
 | 
				
			||||||
 | 
							IsContactValue(user),
 | 
				
			||||||
 | 
							[user] { Ui::show(Box<AddContactBox>(user)); });
 | 
				
			||||||
 | 
						addButton(
 | 
				
			||||||
 | 
							Lang::Viewer(lng_profile_clear_history),
 | 
				
			||||||
 | 
							rpl::single(true),
 | 
				
			||||||
 | 
							[user] {
 | 
				
			||||||
 | 
								auto confirmation = lng_sure_delete_history(lt_contact, App::peerName(user));
 | 
				
			||||||
 | 
								Ui::show(Box<ConfirmBox>(confirmation, lang(lng_box_delete), st::attentionBoxButton, [user] {
 | 
				
			||||||
 | 
									Ui::hideLayer();
 | 
				
			||||||
 | 
									App::main()->clearHistory(user);
 | 
				
			||||||
 | 
									Ui::showPeerHistory(user, ShowAtUnreadMsgId);
 | 
				
			||||||
 | 
								}));
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						addButton(
 | 
				
			||||||
 | 
							Lang::Viewer(lng_profile_delete_conversation),
 | 
				
			||||||
 | 
							rpl::single(true),
 | 
				
			||||||
 | 
							[user] {
 | 
				
			||||||
 | 
								auto confirmation = lng_sure_delete_history(lt_contact, App::peerName(user));
 | 
				
			||||||
 | 
								auto confirmButton = lang(lng_box_delete);
 | 
				
			||||||
 | 
								Ui::show(Box<ConfirmBox>(confirmation, confirmButton, st::attentionBoxButton, [user] {
 | 
				
			||||||
 | 
									Ui::hideLayer();
 | 
				
			||||||
 | 
									Ui::showChatsList();
 | 
				
			||||||
 | 
									App::main()->deleteConversation(user);
 | 
				
			||||||
 | 
								}));
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!user->isSelf()) {
 | 
				
			||||||
 | 
							result->add(CreateSkipWidget(
 | 
				
			||||||
 | 
								result,
 | 
				
			||||||
 | 
								st::infoBlockButtonSkip));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							auto text = PeerUpdateValue(user, Notify::PeerUpdate::Flag::UserIsBlocked)
 | 
				
			||||||
 | 
								| rpl::map([user](auto&&) {
 | 
				
			||||||
 | 
									switch (user->blockStatus()) {
 | 
				
			||||||
 | 
									case UserData::BlockStatus::Blocked:
 | 
				
			||||||
 | 
										return Lang::Viewer(lng_profile_unblock_user);
 | 
				
			||||||
 | 
									case UserData::BlockStatus::NotBlocked:
 | 
				
			||||||
 | 
										return Lang::Viewer(lng_profile_block_user);
 | 
				
			||||||
 | 
									default:
 | 
				
			||||||
 | 
										return rpl::single(QString());
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								| rpl::flatten_latest()
 | 
				
			||||||
 | 
								| rpl::start_spawning(result->lifetime());
 | 
				
			||||||
 | 
							addButton(
 | 
				
			||||||
 | 
								rpl::duplicate(text),
 | 
				
			||||||
 | 
								rpl::duplicate(text)
 | 
				
			||||||
 | 
									| rpl::map([](const QString &text) {
 | 
				
			||||||
 | 
										return !text.isEmpty();
 | 
				
			||||||
 | 
									}),
 | 
				
			||||||
 | 
								[user] {
 | 
				
			||||||
 | 
									if (user->isBlocked()) {
 | 
				
			||||||
 | 
										Auth().api().unblockUser(user);
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										Auth().api().blockUser(user);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								st::infoBlockButton);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						result->add(createSkipWidget(result));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	object_ptr<FloatingIcon>(
 | 
						object_ptr<FloatingIcon>(
 | 
				
			||||||
		result,
 | 
							result,
 | 
				
			||||||
		st::infoIconActions,
 | 
							st::infoIconActions,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,7 +146,7 @@ void Members::setupButtons() {
 | 
				
			||||||
	object_ptr<FloatingIcon>(
 | 
						object_ptr<FloatingIcon>(
 | 
				
			||||||
		this,
 | 
							this,
 | 
				
			||||||
		st::infoIconMembers,
 | 
							st::infoIconMembers,
 | 
				
			||||||
		st::infoMembersIconPosition)->lower();
 | 
							st::infoIconPosition)->lower();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
object_ptr<Members::ListWidget> Members::setupList(
 | 
					object_ptr<Members::ListWidget> Members::setupList(
 | 
				
			||||||
| 
						 | 
					@ -195,7 +195,7 @@ int Members::resizeGetHeight(int newWidth) {
 | 
				
			||||||
		cancelLeft,
 | 
							cancelLeft,
 | 
				
			||||||
		st::infoMembersButtonPosition.y());
 | 
							st::infoMembersButtonPosition.y());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto searchShownLeft = st::infoMembersIconPosition.x()
 | 
						auto searchShownLeft = st::infoIconPosition.x()
 | 
				
			||||||
		- st::infoMembersSearch.iconPosition.x();
 | 
							- st::infoMembersSearch.iconPosition.x();
 | 
				
			||||||
	auto searchHiddenLeft = availableWidth - _search->width();
 | 
						auto searchHiddenLeft = availableWidth - _search->width();
 | 
				
			||||||
	auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.);
 | 
						auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue