mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Implement MSC3664, pushrules for related events
This commit is contained in:
parent
ea5984a575
commit
59703d3c25
4 changed files with 37 additions and 4 deletions
|
@ -595,7 +595,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 c7a13e79289ae35c4e2a9bccb3fdeb2bc03a925d
|
GIT_TAG 7155cbb8ed3289f2cc7269da7607b0dd012f471b
|
||||||
)
|
)
|
||||||
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
|
||||||
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")
|
||||||
|
|
|
@ -182,7 +182,7 @@ modules:
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
name: mtxclient
|
name: mtxclient
|
||||||
sources:
|
sources:
|
||||||
- commit: c7a13e79289ae35c4e2a9bccb3fdeb2bc03a925d
|
- commit: 7155cbb8ed3289f2cc7269da7607b0dd012f471b
|
||||||
#tag: v0.8.2
|
#tag: v0.8.2
|
||||||
type: git
|
type: git
|
||||||
url: https://github.com/Nheko-Reborn/mtxclient.git
|
url: https://github.com/Nheko-Reborn/mtxclient.git
|
||||||
|
|
|
@ -261,6 +261,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
|
||||||
cache::getEventIndex(room_id, cache::client()->getFullyReadEventId(room_id));
|
cache::getEventIndex(room_id, cache::client()->getFullyReadEventId(room_id));
|
||||||
|
|
||||||
auto ctx = roomModel->pushrulesRoomContext();
|
auto ctx = roomModel->pushrulesRoomContext();
|
||||||
|
std::vector<
|
||||||
|
std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvent>>
|
||||||
|
relatedEvents;
|
||||||
|
|
||||||
for (const auto &event : room.timeline.events) {
|
for (const auto &event : room.timeline.events) {
|
||||||
mtx::events::collections::TimelineEvent te{event};
|
mtx::events::collections::TimelineEvent te{event};
|
||||||
std::visit([room_id = room_id](auto &event_) { event_.room_id = room_id; },
|
std::visit([room_id = room_id](auto &event_) { event_.room_id = room_id; },
|
||||||
|
@ -277,7 +281,25 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
|
||||||
te.data = result.event.value();
|
te.data = result.event.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto actions = pushrules->evaluate(te, ctx);
|
relatedEvents.clear();
|
||||||
|
for (const auto &r : mtx::accessors::relations(te.data).relations) {
|
||||||
|
auto related = cache::client()->getEvent(room_id, r.event_id);
|
||||||
|
if (related) {
|
||||||
|
relatedEvents.emplace_back(r, *related);
|
||||||
|
if (auto encryptedEvent = std::get_if<
|
||||||
|
mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
||||||
|
&related->data);
|
||||||
|
encryptedEvent && userSettings_->decryptNotifications()) {
|
||||||
|
MegolmSessionIndex index(room_id, encryptedEvent->content);
|
||||||
|
|
||||||
|
auto result = olm::decryptEvent(index, *encryptedEvent);
|
||||||
|
if (result.event)
|
||||||
|
relatedEvents.back().second.data = result.event.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto actions = pushrules->evaluate(te, ctx, relatedEvents);
|
||||||
if (std::find(actions.begin(),
|
if (std::find(actions.begin(),
|
||||||
actions.end(),
|
actions.end(),
|
||||||
mtx::pushrules::actions::Action{
|
mtx::pushrules::actions::Action{
|
||||||
|
|
|
@ -742,7 +742,18 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
|
||||||
case Notificationlevel: {
|
case Notificationlevel: {
|
||||||
const auto &push = ChatPage::instance()->pushruleEvaluator();
|
const auto &push = ChatPage::instance()->pushruleEvaluator();
|
||||||
if (push) {
|
if (push) {
|
||||||
auto actions = push->evaluate({event}, pushrulesRoomContext());
|
const auto &id = event_id(event);
|
||||||
|
std::vector<std::pair<mtx::common::Relation, mtx::events::collections::TimelineEvent>>
|
||||||
|
relatedEvents;
|
||||||
|
for (const auto &r : mtx::accessors::relations(event).relations) {
|
||||||
|
auto related = events.get(r.event_id, id);
|
||||||
|
if (related) {
|
||||||
|
relatedEvents.emplace_back(r,
|
||||||
|
mtx::events::collections::TimelineEvent{*related});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto actions = push->evaluate({event}, pushrulesRoomContext(), relatedEvents);
|
||||||
if (std::find(actions.begin(),
|
if (std::find(actions.begin(),
|
||||||
actions.end(),
|
actions.end(),
|
||||||
mtx::pushrules::actions::Action{
|
mtx::pushrules::actions::Action{
|
||||||
|
|
Loading…
Reference in a new issue