0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 23:44:01 +01:00

ircd:Ⓜ️:push: Add push ruleset, rule, condition, and pushers structures.

This commit is contained in:
Jason Volk 2020-03-17 21:55:58 -07:00
parent 0bb52f57a3
commit 6c807f7e96
4 changed files with 203 additions and 0 deletions

View file

@ -69,6 +69,7 @@ namespace ircd
#include "rooms.h"
#include "rooms_summary.h"
#include "membership.h"
#include "push.h"
#include "filter.h"
#include "events.h"
#include "node.h"

View file

@ -180,4 +180,26 @@ struct ircd::m::name
static constexpr const char *const filter {"filter"};
static constexpr const char *const rel_type {"rel_type"};
static constexpr const char *const kind {"kind"};
static constexpr const char *const key {"key"};
static constexpr const char *const pattern {"pattern"};
static constexpr const char *const is {"is"};
static constexpr const char *const cond {"cond"};
static constexpr const char *const actions {"actions"};
static constexpr const char *const default_ {"default"};
static constexpr const char *const enabled {"enabled"};
static constexpr const char *const rule_id {"rule_id"};
static constexpr const char *const conditions {"conditions"};
static constexpr const char *const override_ {"override"};
static constexpr const char *const underride {"underride"};
static constexpr const char *const pushkey {"pushkey"};
static constexpr const char *const app_id {"app_id"};
static constexpr const char *const app_display_name {"app_display_name"};
static constexpr const char *const profile_tag {"profile_tag"};
static constexpr const char *const lang {"lang"};
static constexpr const char *const append {"append"};
};

158
include/ircd/m/push.h Normal file
View file

@ -0,0 +1,158 @@
// The Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_M_PUSH_H
namespace ircd::m::push
{
struct cond;
struct rule;
struct rules;
struct pusher;
}
/// PushCondition
struct ircd::m::push::cond
:json::tuple
<
/// Required. The kind of condition to apply. See conditions for more
/// information on the allowed kinds and how they work.
json::property<name::kind, json::string>,
/// Required for event_match conditions. The dot- separated field of the
/// event to match. Required for sender_notification_permission conditions.
/// The field in the power level event the user needs a minimum power level
/// for. Fields must be specified under the notifications property in the
/// power level event's content.
json::property<name::key, json::string>,
/// Required for event_match conditions. The glob-style pattern to match
/// against. Patterns with no special glob characters should be treated
/// as having asterisks prepended and appended when testing the condition.
json::property<name::pattern, json::string>,
/// Required for room_member_count conditions. A decimal integer optionally
/// prefixed by one of, ==, <, >, >= or <=. A prefix of < matches rooms
/// where the member count is strictly less than the given number and so
/// forth. If no prefix is present, this parameter defaults to ==.
json::property<name::is, json::string>
>
{
using super_type::tuple;
using super_type::operator=;
};
/// PushRule
struct ircd::m::push::rule
:json::tuple
<
/// [object or string] Required. The actions to perform when this rule is
/// matched.
json::property<name::actions, string_view>,
/// Required. Whether this is a default rule, or has been set explicitly.
json::property<name::default_, bool>,
/// Required. Whether the push rule is enabled or not.
json::property<name::enabled, bool>,
/// Required. The ID of this rule.
json::property<name::rule_id, json::string>,
/// The conditions that must hold true for an event in order for a rule
/// to be applied to an event. A rule with no conditions always matches.
/// Only applicable to underride and override rules.
json::property<name::conditions, json::array>,
/// The glob-style pattern to match against. Only applicable to content
/// rules.
json::property<name::pattern, json::string>
>
{
using super_type::tuple;
using super_type::operator=;
};
/// 13.13.1.5 Push Ruleset
struct ircd::m::push::rules
:json::tuple
<
/// These configure behaviour for (unencrypted) messages that match
/// certain patterns. Content rules take one parameter: pattern, that
/// gives the glob pattern to match against. This is treated in the same
/// way as pattern for event_match.
json::property<name::content, json::array>,
/// The highest priority rules are user-configured overrides.
json::property<name::override_, json::array>,
/// These rules change the behaviour of all messages for a given room. The
/// rule_id of a room rule is always the ID of the room that it affects.
json::property<name::room, json::array>,
/// These rules configure notification behaviour for messages from a
/// specific Matrix user ID. The rule_id of Sender rules is always the
/// Matrix user ID of the user whose messages they'd apply to.
json::property<name::sender, json::array>,
/// These are identical to override rules, but have a lower priority
/// than content, room and sender rules.
json::property<name::underride, json::array>
>
{
using super_type::tuple;
using super_type::operator=;
};
/// 13.13.1 I'm your pusher, baby.
struct ircd::m::push::pusher
:json::tuple
<
/// Required. This is a unique identifier for this pusher. See /set for
/// more detail. Max length, 512 bytes.
json::property<name::pushkey, json::string>,
/// Required. The kind of pusher. "http" is a pusher that sends HTTP pokes.
json::property<name::kind, json::string>,
/// Required. This is a reverse-DNS style identifier for the application.
/// Max length, 64 chars.
json::property<name::app_id, json::string>,
/// Required. A string that will allow the user to identify what
/// application owns this pusher.
json::property<name::app_display_name, json::string>,
/// Required. A string that will allow the user to identify what device owns this pusher.
json::property<name::device_display_name, json::string>,
/// This string determines which set of device specific rules this
/// pusher executes.
json::property<name::profile_tag, json::string>,
/// Required. The preferred language for receiving notifications
/// (e.g. 'en' or 'en-US')
json::property<name::lang, json::string>,
/// Required. A dictionary of information for the pusher
/// implementation itself.
json::property<name::data, json::object>,
/// If true, the homeserver should add another pusher with the given
/// pushkey and App ID in addition to any others with different user IDs.
/// Otherwise, the homeserver must remove any other pushers with the same
/// App ID and pushkey for different users. The default is false.
json::property<name::append, bool>
>
{
using super_type::tuple;
using super_type::operator=;
};

View file

@ -159,3 +159,25 @@ constexpr const char *const ircd::m::name::groupings;
constexpr const char *const ircd::m::name::filter;
constexpr const char *const ircd::m::name::rel_type;
constexpr const char *const ircd::m::name::kind;
constexpr const char *const ircd::m::name::key;
constexpr const char *const ircd::m::name::pattern;
constexpr const char *const ircd::m::name::is;
constexpr const char *const ircd::m::name::cond;
constexpr const char *const ircd::m::name::actions;
constexpr const char *const ircd::m::name::default_;
constexpr const char *const ircd::m::name::enabled;
constexpr const char *const ircd::m::name::rule_id;
constexpr const char *const ircd::m::name::conditions;
constexpr const char *const ircd::m::name::override_;
constexpr const char *const ircd::m::name::underride;
constexpr const char *const ircd::m::name::pushkey;
constexpr const char *const ircd::m::name::app_id;
constexpr const char *const ircd::m::name::app_display_name;
constexpr const char *const ircd::m::name::profile_tag;
constexpr const char *const ircd::m::name::lang;
constexpr const char *const ircd::m::name::append;