Add user actions to info profile.

This commit is contained in:
John Preston 2017-09-26 22:42:58 +03:00
parent f50bf0b97f
commit 4180ed09a5
4 changed files with 103 additions and 16 deletions

View File

@ -560,8 +560,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_profile_bio" = "Bio:";
"lng_profile_add_contact" = "Add Contact";
"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_leave_channel" = "Leave 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_report" = "Report";
"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_unblock_bot" = "Unblock bot";
"lng_profile_share_contact" = "Share Contact";
"lng_profile_invite_to_group" = "Add to Group";
"lng_profile_delete_contact" = "Delete";
"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_rounds" = "Video messages";
"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_group_title" = "Report group";

View File

@ -149,7 +149,6 @@ infoProfileSeparatorPadding: margins(
infoProfileSkip);
infoIconFg: menuIconFg;
infoIconPosition: point(20px, 12px);
infoIconInformation: icon {{ "info_information", infoIconFg }};
infoIconMembers: icon {{ "info_members", infoIconFg }};
infoIconNotifications: icon {{ "info_notifications", infoIconFg }};
@ -158,7 +157,7 @@ infoIconMediaPhoto: icon {{ "info_media_photo", infoIconFg }};
infoInformationIconPosition: point(25px, 12px);
infoNotificationsIconPosition: point(20px, 5px);
infoSharedMediaIconPosition: point(20px, 24px);
infoMembersIconPosition: point(20px, 15px);
infoIconPosition: point(20px, 15px);
infoLabeledOneLine: FlatLabel(defaultFlatLabel) {
width: 0px; // No need to set minWidth in one-line text.
@ -223,6 +222,12 @@ infoSharedMediaCoverHeight: 62px;
infoSharedMediaButton: infoProfileButton;
infoSharedMediaBottomSkip: 12px;
infoBlockButton: InfoProfileButton(infoProfileButton) {
textFg: attentionButtonFg;
textFgOver: attentionButtonFgOver;
}
infoBlockButtonSkip: 8px;
infoMembersHeader: 56px;
infoMembersList: PeerList(defaultPeerList) {
item: PeerListItem(defaultPeerListItem) {

View File

@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/profile/info_profile_inner_widget.h"
#include <rpl/combine.h>
#include <rpl/flatten_latest.h>
#include "info/profile/info_profile_button.h"
#include "info/profile/info_profile_widget.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 "boxes/abstract_box.h"
#include "boxes/add_contact_box.h"
#include "boxes/confirm_box.h"
#include "mainwidget.h"
#include "auth_session.h"
#include "apiwrap.h"
#include "window/window_controller.h"
#include "storage/storage_shared_media.h"
#include "lang/lang_keys.h"
#include "styles/style_info.h"
#include "styles/style_boxes.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/scroll_area.h"
@ -368,18 +373,94 @@ object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
RpWidget *parent,
not_null<UserData*> user) const {
auto result = object_ptr<Ui::VerticalLayout>(parent);
auto tracker = MultiLineTracker();
auto addButton = [&](rpl::producer<QString> &&text) {
auto button = result->add(object_ptr<Ui::SlideWrap<Button>>(
result->add(createSkipWidget(result));
auto addButton = [&](
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,
object_ptr<Button>(
result,
std::move(text),
st::infoSharedMediaButton)));
tracker.track(button);
return button;
st))
)->toggleOn(
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>(
result,
st::infoIconActions,

View File

@ -146,7 +146,7 @@ void Members::setupButtons() {
object_ptr<FloatingIcon>(
this,
st::infoIconMembers,
st::infoMembersIconPosition)->lower();
st::infoIconPosition)->lower();
}
object_ptr<Members::ListWidget> Members::setupList(
@ -195,7 +195,7 @@ int Members::resizeGetHeight(int newWidth) {
cancelLeft,
st::infoMembersButtonPosition.y());
auto searchShownLeft = st::infoMembersIconPosition.x()
auto searchShownLeft = st::infoIconPosition.x()
- st::infoMembersSearch.iconPosition.x();
auto searchHiddenLeft = availableWidth - _search->width();
auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.);