mirror of https://github.com/procxx/kepka.git
Allow hiding contact status bar.
This commit is contained in:
parent
984f19b1e9
commit
f49c7ba7ee
|
@ -46,6 +46,10 @@ bool BarCurrentlyHidden(not_null<PeerData*> peer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto MapToEmpty() {
|
||||||
|
return rpl::map([] { return rpl::empty_value(); });
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
//
|
//
|
||||||
//void HistoryWidget::onReportSpamClicked() {
|
//void HistoryWidget::onReportSpamClicked() {
|
||||||
|
@ -118,14 +122,14 @@ bool BarCurrentlyHidden(not_null<PeerData*> peer) {
|
||||||
ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
|
ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _name(name)
|
, _name(name)
|
||||||
, _block(
|
|
||||||
this,
|
|
||||||
lang(lng_new_contact_block).toUpper(),
|
|
||||||
st::historyContactStatusBlock)
|
|
||||||
, _add(
|
, _add(
|
||||||
this,
|
this,
|
||||||
lang(lng_new_contact_add).toUpper(),
|
lang(lng_new_contact_add).toUpper(),
|
||||||
st::historyContactStatusButton)
|
st::historyContactStatusButton)
|
||||||
|
, _block(
|
||||||
|
this,
|
||||||
|
lang(lng_new_contact_block).toUpper(),
|
||||||
|
st::historyContactStatusBlock)
|
||||||
, _share(
|
, _share(
|
||||||
this,
|
this,
|
||||||
lang(lng_new_contact_share).toUpper(),
|
lang(lng_new_contact_share).toUpper(),
|
||||||
|
@ -148,6 +152,25 @@ void ContactStatus::Bar::showState(State state) {
|
||||||
: lang(lng_new_contact_add).toUpper());
|
: lang(lng_new_contact_add).toUpper());
|
||||||
updateButtonsGeometry();
|
updateButtonsGeometry();
|
||||||
}
|
}
|
||||||
|
rpl::producer<> ContactStatus::Bar::addClicks() const {
|
||||||
|
return _add->clicks() | MapToEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ContactStatus::Bar::blockClicks() const {
|
||||||
|
return _block->clicks() | MapToEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ContactStatus::Bar::shareClicks() const {
|
||||||
|
return _share->clicks() | MapToEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ContactStatus::Bar::reportClicks() const {
|
||||||
|
return _report->clicks() | MapToEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ContactStatus::Bar::closeClicks() const {
|
||||||
|
return _close->clicks() | MapToEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void ContactStatus::Bar::resizeEvent(QResizeEvent *e) {
|
void ContactStatus::Bar::resizeEvent(QResizeEvent *e) {
|
||||||
_close->moveToRight(0, 0);
|
_close->moveToRight(0, 0);
|
||||||
|
@ -224,6 +247,7 @@ ContactStatus::ContactStatus(
|
||||||
, _shadow(parent) {
|
, _shadow(parent) {
|
||||||
setupWidgets(parent);
|
setupWidgets(parent);
|
||||||
setupState(peer);
|
setupState(peer);
|
||||||
|
setupHandlers(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactStatus::setupWidgets(not_null<Ui::RpWidget*> parent) {
|
void ContactStatus::setupWidgets(not_null<Ui::RpWidget*> parent) {
|
||||||
|
@ -274,8 +298,11 @@ auto ContactStatus::PeerState(not_null<PeerData*> peer)
|
||||||
} else {
|
} else {
|
||||||
return State::None;
|
return State::None;
|
||||||
}
|
}
|
||||||
|
} else if (settings.value & Setting::f_block_contact) {
|
||||||
|
return State::AddOrBlock;
|
||||||
|
} else {
|
||||||
|
return State::Add;
|
||||||
}
|
}
|
||||||
return State::AddOrBlock;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,6 +318,7 @@ void ContactStatus::setupState(not_null<PeerData*> peer) {
|
||||||
if (!BarCurrentlyHidden(peer)) {
|
if (!BarCurrentlyHidden(peer)) {
|
||||||
peer->session().api().requestPeerSettings(peer);
|
peer->session().api().requestPeerSettings(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerState(
|
PeerState(
|
||||||
peer
|
peer
|
||||||
) | rpl::start_with_next([=](State state) {
|
) | rpl::start_with_next([=](State state) {
|
||||||
|
@ -304,14 +332,46 @@ void ContactStatus::setupState(not_null<PeerData*> peer) {
|
||||||
}, _bar.lifetime());
|
}, _bar.lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupHandlers(not_null<PeerData*> peer) {
|
||||||
|
setupAddHandler(peer);
|
||||||
|
setupBlockHandler(peer);
|
||||||
|
setupShareHandler(peer);
|
||||||
|
setupReportHandler(peer);
|
||||||
|
setupCloseHandler(peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupAddHandler(not_null<PeerData*> peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupBlockHandler(not_null<PeerData*> peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupShareHandler(not_null<PeerData*> peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupReportHandler(not_null<PeerData*> peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupCloseHandler(not_null<PeerData*> peer) {
|
||||||
|
const auto request = _bar.lifetime().make_state<mtpRequestId>(0);
|
||||||
|
_bar.entity()->closeClicks(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return !(*request);
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
peer->setSettings(0);
|
||||||
|
*request = peer->session().api().request(
|
||||||
|
MTPmessages_HidePeerSettingsBar(peer->input)
|
||||||
|
).send();
|
||||||
|
}, _bar.lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void ContactStatus::show() {
|
void ContactStatus::show() {
|
||||||
if (_shown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_shown = true;
|
|
||||||
const auto visible = (_state != State::None);
|
const auto visible = (_state != State::None);
|
||||||
if (visible) {
|
if (!_shown) {
|
||||||
_bar.entity()->showState(_state);
|
_shown = true;
|
||||||
|
if (visible) {
|
||||||
|
_bar.entity()->showState(_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_bar.toggle(visible, anim::type::instant);
|
_bar.toggle(visible, anim::type::instant);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,12 @@ private:
|
||||||
|
|
||||||
void showState(State state);
|
void showState(State state);
|
||||||
|
|
||||||
|
rpl::producer<> addClicks() const;
|
||||||
|
rpl::producer<> blockClicks() const;
|
||||||
|
rpl::producer<> shareClicks() const;
|
||||||
|
rpl::producer<> reportClicks() const;
|
||||||
|
rpl::producer<> closeClicks() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
|
@ -55,8 +61,8 @@ private:
|
||||||
void updateButtonsGeometry();
|
void updateButtonsGeometry();
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
object_ptr<Ui::FlatButton> _block;
|
|
||||||
object_ptr<Ui::FlatButton> _add;
|
object_ptr<Ui::FlatButton> _add;
|
||||||
|
object_ptr<Ui::FlatButton> _block;
|
||||||
object_ptr<Ui::FlatButton> _share;
|
object_ptr<Ui::FlatButton> _share;
|
||||||
object_ptr<Ui::FlatButton> _report;
|
object_ptr<Ui::FlatButton> _report;
|
||||||
object_ptr<Ui::IconButton> _close;
|
object_ptr<Ui::IconButton> _close;
|
||||||
|
@ -65,6 +71,12 @@ private:
|
||||||
|
|
||||||
void setupWidgets(not_null<Ui::RpWidget*> parent);
|
void setupWidgets(not_null<Ui::RpWidget*> parent);
|
||||||
void setupState(not_null<PeerData*> peer);
|
void setupState(not_null<PeerData*> peer);
|
||||||
|
void setupHandlers(not_null<PeerData*> peer);
|
||||||
|
void setupAddHandler(not_null<PeerData*> peer);
|
||||||
|
void setupBlockHandler(not_null<PeerData*> peer);
|
||||||
|
void setupShareHandler(not_null<PeerData*> peer);
|
||||||
|
void setupReportHandler(not_null<PeerData*> peer);
|
||||||
|
void setupCloseHandler(not_null<PeerData*> peer);
|
||||||
|
|
||||||
static rpl::producer<State> PeerState(not_null<PeerData*> peer);
|
static rpl::producer<State> PeerState(not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue