mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
use room rules for mentions
This commit is contained in:
parent
96e3a7735d
commit
aae8612482
2 changed files with 32 additions and 22 deletions
|
@ -334,7 +334,7 @@ if(USE_BUNDLED_MTXCLIENT)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
MatrixClient
|
MatrixClient
|
||||||
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
GIT_TAG c914f8bd042bf8c2d0ee499c0d89e010e8ba9180
|
GIT_TAG ec569028ee7a5945bc5552858b2eac930c9d2871
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(MatrixClient)
|
FetchContent_MakeAvailable(MatrixClient)
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -225,18 +225,27 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
||||||
[this](const mtx::pushrules::PushRule &rule, mtx::http::RequestErr &err) {
|
[this](const mtx::pushrules::PushRule &rule, mtx::http::RequestErr &err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err->status_code == boost::beast::http::status::not_found)
|
if (err->status_code == boost::beast::http::status::not_found)
|
||||||
|
http::client()->get_pushrules(
|
||||||
|
"global",
|
||||||
|
"room",
|
||||||
|
room_id_.toStdString(),
|
||||||
|
[this](const mtx::pushrules::PushRule &rule,
|
||||||
|
mtx::http::RequestErr &err) {
|
||||||
|
if (err) {
|
||||||
emit notifChanged(2); // all messages
|
emit notifChanged(2); // all messages
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rule.actions.size() == 1 &&
|
if (rule.enabled)
|
||||||
std::holds_alternative<mtx::pushrules::actions::dont_notify>(
|
|
||||||
rule.actions[0])) {
|
|
||||||
if (rule.conditions.empty())
|
|
||||||
emit notifChanged(1); // mentions only
|
emit notifChanged(1); // mentions only
|
||||||
else
|
});
|
||||||
emit notifChanged(0); // muted
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rule.enabled)
|
||||||
|
emit notifChanged(0); // muted
|
||||||
|
else
|
||||||
|
emit notifChanged(2); // all messages
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(notifCombo, QOverload<int>::of(&QComboBox::activated), [this](int index) {
|
connect(notifCombo, QOverload<int>::of(&QComboBox::activated), [this](int index) {
|
||||||
|
@ -264,6 +273,9 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
||||||
room_id,
|
room_id,
|
||||||
static_cast<int>(err->status_code),
|
static_cast<int>(err->status_code),
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
|
http::client()->delete_pushrules(
|
||||||
|
"global", "room", room_id, [room_id](mtx::http::RequestErr &) {
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else if (index == 1) {
|
} else if (index == 1) {
|
||||||
// mentions only
|
// mentions only
|
||||||
|
@ -271,28 +283,26 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
||||||
mtx::pushrules::PushRule rule;
|
mtx::pushrules::PushRule rule;
|
||||||
rule.actions = {mtx::pushrules::actions::dont_notify{}};
|
rule.actions = {mtx::pushrules::actions::dont_notify{}};
|
||||||
http::client()->put_pushrules(
|
http::client()->put_pushrules(
|
||||||
"global",
|
"global", "room", room_id, rule, [room_id](mtx::http::RequestErr &err) {
|
||||||
"override",
|
|
||||||
room_id,
|
|
||||||
rule,
|
|
||||||
[room_id](mtx::http::RequestErr &err) {
|
|
||||||
if (err)
|
if (err)
|
||||||
nhlog::net()->error(
|
nhlog::net()->error(
|
||||||
"failed to set pushrule for room {}: {} {}",
|
"failed to set pushrule for room {}: {} {}",
|
||||||
room_id,
|
room_id,
|
||||||
static_cast<int>(err->status_code),
|
static_cast<int>(err->status_code),
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
|
http::client()->delete_pushrules(
|
||||||
|
"global",
|
||||||
|
"override",
|
||||||
|
room_id,
|
||||||
|
[room_id](mtx::http::RequestErr &) {});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// all messages
|
// all messages
|
||||||
http::client()->delete_pushrules(
|
http::client()->delete_pushrules(
|
||||||
"global", "override", room_id, [room_id](mtx::http::RequestErr &err) {
|
"global", "override", room_id, [room_id](mtx::http::RequestErr &) {
|
||||||
if (err)
|
http::client()->delete_pushrules(
|
||||||
nhlog::net()->error(
|
"global", "room", room_id, [room_id](mtx::http::RequestErr &) {
|
||||||
"failed to delete pushrule for room {}: {} {}",
|
});
|
||||||
room_id,
|
|
||||||
static_cast<int>(err->status_code),
|
|
||||||
err->matrix_error.error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue