mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add Unarchive button to ContactStatus bar.
This commit is contained in:
parent
3aea9cb3ca
commit
e363b254f6
3 changed files with 71 additions and 23 deletions
|
@ -442,6 +442,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_settings_auto_night_warning" = "You have enabled auto-night mode. If you want to change the dark mode settings, you'll need to disable it first.";
|
"lng_settings_auto_night_warning" = "You have enabled auto-night mode. If you want to change the dark mode settings, you'll need to disable it first.";
|
||||||
"lng_settings_auto_night_disable" = "Disable";
|
"lng_settings_auto_night_disable" = "Disable";
|
||||||
|
|
||||||
|
"lng_suggest_hide_new_title" = "Hide new chats?";
|
||||||
|
"lng_suggest_hide_new_about" = "You are receiving lots of new chats from users who are not in your ContactList. Do you want to have such chats **automatically muted** and **archived**?";
|
||||||
|
"lng_suggest_hide_new_to_settings" = "Go to Settings";
|
||||||
|
|
||||||
"lng_settings_spellchecker" = "Spell checker";
|
"lng_settings_spellchecker" = "Spell checker";
|
||||||
"lng_settings_system_spellchecker" = "Use system spell checker";
|
"lng_settings_system_spellchecker" = "Use system spell checker";
|
||||||
"lng_settings_custom_spellchecker" = "Use spell checker";
|
"lng_settings_custom_spellchecker" = "Use spell checker";
|
||||||
|
@ -1290,6 +1294,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_new_contact_share_done" = "{user} can now see your phone number.";
|
"lng_new_contact_share_done" = "{user} can now see your phone number.";
|
||||||
"lng_new_contact_add_name" = "Add {user} to contacts";
|
"lng_new_contact_add_name" = "Add {user} to contacts";
|
||||||
"lng_new_contact_add_done" = "{user} is now in your contact list.";
|
"lng_new_contact_add_done" = "{user} is now in your contact list.";
|
||||||
|
"lng_new_contact_unarchive" = "Unarchive";
|
||||||
"lng_cant_send_to_not_contact" = "Sorry, you can only send messages to\nmutual contacts at the moment.\n{more_info}";
|
"lng_cant_send_to_not_contact" = "Sorry, you can only send messages to\nmutual contacts at the moment.\n{more_info}";
|
||||||
"lng_cant_invite_not_contact" = "Sorry, you can only add mutual contacts\nto groups at the moment.\n{more_info}";
|
"lng_cant_invite_not_contact" = "Sorry, you can only add mutual contacts\nto groups at the moment.\n{more_info}";
|
||||||
"lng_cant_more_info" = "More info »";
|
"lng_cant_more_info" = "More info »";
|
||||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
@ -62,6 +63,10 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
|
||||||
this,
|
this,
|
||||||
QString(),
|
QString(),
|
||||||
st::historyContactStatusButton)
|
st::historyContactStatusButton)
|
||||||
|
, _unarchive(
|
||||||
|
this,
|
||||||
|
tr::lng_new_contact_unarchive(tr::now).toUpper(),
|
||||||
|
st::historyContactStatusButton)
|
||||||
, _block(
|
, _block(
|
||||||
this,
|
this,
|
||||||
tr::lng_new_contact_block(tr::now).toUpper(),
|
tr::lng_new_contact_block(tr::now).toUpper(),
|
||||||
|
@ -72,7 +77,7 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
|
||||||
st::historyContactStatusButton)
|
st::historyContactStatusButton)
|
||||||
, _report(
|
, _report(
|
||||||
this,
|
this,
|
||||||
tr::lng_report_spam_and_leave(tr::now).toUpper(),
|
QString(),
|
||||||
st::historyContactStatusBlock)
|
st::historyContactStatusBlock)
|
||||||
, _close(this, st::historyReplyCancel) {
|
, _close(this, st::historyReplyCancel) {
|
||||||
resize(_close->size());
|
resize(_close->size());
|
||||||
|
@ -80,15 +85,26 @@ ContactStatus::Bar::Bar(QWidget *parent, const QString &name)
|
||||||
|
|
||||||
void ContactStatus::Bar::showState(State state) {
|
void ContactStatus::Bar::showState(State state) {
|
||||||
_add->setVisible(state == State::AddOrBlock || state == State::Add);
|
_add->setVisible(state == State::AddOrBlock || state == State::Add);
|
||||||
_block->setVisible(state == State::AddOrBlock);
|
_unarchive->setVisible(state == State::UnarchiveOrBlock
|
||||||
|
|| state == State::UnarchiveOrReport);
|
||||||
|
_block->setVisible(state == State::AddOrBlock
|
||||||
|
|| state == State::UnarchiveOrBlock);
|
||||||
_share->setVisible(state == State::SharePhoneNumber);
|
_share->setVisible(state == State::SharePhoneNumber);
|
||||||
_report->setVisible(state == State::ReportSpam);
|
_report->setVisible(state == State::ReportSpam
|
||||||
|
|| state == State::UnarchiveOrReport);
|
||||||
_add->setText((state == State::Add)
|
_add->setText((state == State::Add)
|
||||||
? tr::lng_new_contact_add_name(tr::now, lt_user, _name).toUpper()
|
? tr::lng_new_contact_add_name(tr::now, lt_user, _name).toUpper()
|
||||||
: tr::lng_new_contact_add(tr::now).toUpper());
|
: tr::lng_new_contact_add(tr::now).toUpper());
|
||||||
|
_report->setText((state == State::ReportSpam)
|
||||||
|
? tr::lng_report_spam_and_leave(tr::now).toUpper()
|
||||||
|
: tr::lng_report_spam(tr::now).toUpper());
|
||||||
updateButtonsGeometry();
|
updateButtonsGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ContactStatus::Bar::unarchiveClicks() const {
|
||||||
|
return _unarchive->clicks() | rpl::to_empty;
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<> ContactStatus::Bar::addClicks() const {
|
rpl::producer<> ContactStatus::Bar::addClicks() const {
|
||||||
return _add->clicks() | rpl::to_empty;
|
return _add->clicks() | rpl::to_empty;
|
||||||
}
|
}
|
||||||
|
@ -143,32 +159,34 @@ void ContactStatus::Bar::updateButtonsGeometry() {
|
||||||
closeWidth);
|
closeWidth);
|
||||||
placeButton(button, full, margin);
|
placeButton(button, full, margin);
|
||||||
};
|
};
|
||||||
if (!_add->isHidden() && !_block->isHidden()) {
|
const auto &leftButton = _unarchive->isHidden() ? _add : _unarchive;
|
||||||
const auto addWidth = buttonWidth(_add);
|
const auto &rightButton = _block->isHidden() ? _report : _block;
|
||||||
const auto blockWidth = buttonWidth(_block);
|
if (!leftButton->isHidden() && !rightButton->isHidden()) {
|
||||||
|
const auto leftWidth = buttonWidth(leftButton);
|
||||||
|
const auto rightWidth = buttonWidth(rightButton);
|
||||||
const auto half = full / 2;
|
const auto half = full / 2;
|
||||||
if (addWidth <= half
|
if (leftWidth <= half
|
||||||
&& blockWidth + 2 * closeWidth <= full - half) {
|
&& rightWidth + 2 * closeWidth <= full - half) {
|
||||||
placeButton(_add, half);
|
placeButton(leftButton, half);
|
||||||
placeButton(_block, full - half);
|
placeButton(rightButton, full - half);
|
||||||
} else if (addWidth + blockWidth <= available) {
|
} else if (leftWidth + rightWidth <= available) {
|
||||||
const auto margin = std::clamp(
|
const auto margin = std::clamp(
|
||||||
addWidth + blockWidth + closeWidth - available,
|
leftWidth + rightWidth + closeWidth - available,
|
||||||
0,
|
0,
|
||||||
closeWidth);
|
closeWidth);
|
||||||
const auto realBlockWidth = blockWidth + 2 * closeWidth - margin;
|
const auto realBlockWidth = rightWidth + 2 * closeWidth - margin;
|
||||||
if (addWidth > realBlockWidth) {
|
if (leftWidth > realBlockWidth) {
|
||||||
placeButton(_add, addWidth);
|
placeButton(leftButton, leftWidth);
|
||||||
placeButton(_block, full - addWidth, margin);
|
placeButton(rightButton, full - leftWidth, margin);
|
||||||
} else {
|
} else {
|
||||||
placeButton(_add, full - realBlockWidth);
|
placeButton(leftButton, full - realBlockWidth);
|
||||||
placeButton(_block, realBlockWidth, margin);
|
placeButton(rightButton, realBlockWidth, margin);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto forAdd = (available * addWidth)
|
const auto forLeft = (available * leftWidth)
|
||||||
/ (addWidth + blockWidth);
|
/ (leftWidth + rightWidth);
|
||||||
placeButton(_add, forAdd);
|
placeButton(leftButton, forLeft);
|
||||||
placeButton(_block, full - forAdd, closeWidth);
|
placeButton(rightButton, full - forLeft, closeWidth);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
placeOne(_add);
|
placeOne(_add);
|
||||||
|
@ -245,6 +263,8 @@ auto ContactStatus::PeerState(not_null<PeerData*> peer)
|
||||||
} else {
|
} else {
|
||||||
return State::None;
|
return State::None;
|
||||||
}
|
}
|
||||||
|
} else if (settings.value & Setting::f_autoarchived) {
|
||||||
|
return State::UnarchiveOrBlock;
|
||||||
} else if (settings.value & Setting::f_block_contact) {
|
} else if (settings.value & Setting::f_block_contact) {
|
||||||
return State::AddOrBlock;
|
return State::AddOrBlock;
|
||||||
} else if (settings.value & Setting::f_add_contact) {
|
} else if (settings.value & Setting::f_add_contact) {
|
||||||
|
@ -257,7 +277,9 @@ auto ContactStatus::PeerState(not_null<PeerData*> peer)
|
||||||
|
|
||||||
return peer->settingsValue(
|
return peer->settingsValue(
|
||||||
) | rpl::map([=](SettingsChange settings) {
|
) | rpl::map([=](SettingsChange settings) {
|
||||||
return (settings.value & Setting::f_report_spam)
|
return (settings.value & Setting::f_autoarchived)
|
||||||
|
? State::UnarchiveOrReport
|
||||||
|
: (settings.value & Setting::f_report_spam)
|
||||||
? State::ReportSpam
|
? State::ReportSpam
|
||||||
: State::None;
|
: State::None;
|
||||||
});
|
});
|
||||||
|
@ -287,6 +309,7 @@ void ContactStatus::setupHandlers(not_null<PeerData*> peer) {
|
||||||
setupBlockHandler(user);
|
setupBlockHandler(user);
|
||||||
setupShareHandler(user);
|
setupShareHandler(user);
|
||||||
}
|
}
|
||||||
|
setupUnarchiveHandler(peer);
|
||||||
setupReportHandler(peer);
|
setupReportHandler(peer);
|
||||||
setupCloseHandler(peer);
|
setupCloseHandler(peer);
|
||||||
}
|
}
|
||||||
|
@ -340,6 +363,21 @@ void ContactStatus::setupShareHandler(not_null<UserData*> user) {
|
||||||
}, _bar.lifetime());
|
}, _bar.lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContactStatus::setupUnarchiveHandler(not_null<PeerData*> peer) {
|
||||||
|
_bar.entity()->unarchiveClicks(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
Window::ToggleHistoryArchived(peer->owner().history(peer), false);
|
||||||
|
peer->owner().updateNotifySettings(peer, 0);
|
||||||
|
if (const auto settings = peer->settings()) {
|
||||||
|
using Flag = MTPDpeerSettings::Flag;
|
||||||
|
const auto flags = Flag::f_autoarchived
|
||||||
|
| Flag::f_block_contact
|
||||||
|
| Flag::f_report_spam;
|
||||||
|
peer->setSettings(*settings & ~flags);
|
||||||
|
}
|
||||||
|
}, _bar.lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void ContactStatus::setupReportHandler(not_null<PeerData*> peer) {
|
void ContactStatus::setupReportHandler(not_null<PeerData*> peer) {
|
||||||
_bar.entity()->reportClicks(
|
_bar.entity()->reportClicks(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
|
|
@ -46,6 +46,8 @@ private:
|
||||||
ReportSpam,
|
ReportSpam,
|
||||||
Add,
|
Add,
|
||||||
AddOrBlock,
|
AddOrBlock,
|
||||||
|
UnarchiveOrBlock,
|
||||||
|
UnarchiveOrReport,
|
||||||
SharePhoneNumber,
|
SharePhoneNumber,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ private:
|
||||||
|
|
||||||
void showState(State state);
|
void showState(State state);
|
||||||
|
|
||||||
|
rpl::producer<> unarchiveClicks() const;
|
||||||
rpl::producer<> addClicks() const;
|
rpl::producer<> addClicks() const;
|
||||||
rpl::producer<> blockClicks() const;
|
rpl::producer<> blockClicks() const;
|
||||||
rpl::producer<> shareClicks() const;
|
rpl::producer<> shareClicks() const;
|
||||||
|
@ -69,6 +72,7 @@ private:
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
object_ptr<Ui::FlatButton> _add;
|
object_ptr<Ui::FlatButton> _add;
|
||||||
|
object_ptr<Ui::FlatButton> _unarchive;
|
||||||
object_ptr<Ui::FlatButton> _block;
|
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;
|
||||||
|
@ -82,6 +86,7 @@ private:
|
||||||
void setupAddHandler(not_null<UserData*> user);
|
void setupAddHandler(not_null<UserData*> user);
|
||||||
void setupBlockHandler(not_null<UserData*> user);
|
void setupBlockHandler(not_null<UserData*> user);
|
||||||
void setupShareHandler(not_null<UserData*> user);
|
void setupShareHandler(not_null<UserData*> user);
|
||||||
|
void setupUnarchiveHandler(not_null<PeerData*> peer);
|
||||||
void setupReportHandler(not_null<PeerData*> peer);
|
void setupReportHandler(not_null<PeerData*> peer);
|
||||||
void setupCloseHandler(not_null<PeerData*> peer);
|
void setupCloseHandler(not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue