<commit_before>/*
Copyright 2015 - 2021 Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * @module filter
 */

import { FilterComponent, IFilterComponent } from "./filter-component";
import { MatrixEvent } from "./models/event";

/**
 * @param {Object} obj
 * @param {string} keyNesting
 * @param {*} val
 */
function setProp(obj: object, keyNesting: string, val: any) {
    const nestedKeys = keyNesting.split(".");
    let currentObj = obj;
    for (let i = 0; i < (nestedKeys.length - 1); i++) {
        if (!currentObj[nestedKeys[i]]) {
            currentObj[nestedKeys[i]] = {};
        }
        currentObj = currentObj[nestedKeys[i]];
    }
    currentObj[nestedKeys[nestedKeys.length - 1]] = val;
}

/* eslint-disable camelcase */
export interface IFilterDefinition {
    event_fields?: string[];
    event_format?: "client" | "federation";
    presence?: IFilterComponent;
    account_data?: IFilterComponent;
    room?: IRoomFilter;
}

export interface IRoomEventFilter extends IFilterComponent {
    lazy_load_members?: boolean;
    include_redundant_members?: boolean;
}

interface IStateFilter extends IRoomEventFilter {}

interface IRoomFilter {
    not_rooms?: string[];
    rooms?: string[];
    ephemeral?: IRoomEventFilter;<commit_msg>Add new room event filter fields (#2051)<commit_after>/*
Copyright 2015 - 2021 Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * @module filter
 */

import {
    EventType,
    RelationType,
} from "./@types/event";
import { FilterComponent, IFilterComponent } from "./filter-component";
import { MatrixEvent } from "./models/event";
import { UnstableValue } from "./NamespacedValue";

export const UNSTABLE_FILTER_RELATION_SENDERS = new UnstableValue(
    "relation_senders",
    "io.element.relation_senders",
);

export const UNSTABLE_FILTER_RELATION_TYPES = new UnstableValue(
    "relation_types",
    "io.element.relation_types",
);

/**
 * @param {Object} obj
 * @param {string} keyNesting
 * @param {*} val
 */
function setProp(obj: object, keyNesting: string, val: any) {
    const nestedKeys = keyNesting.split(".");
    let currentObj = obj;
    for (let i = 0; i < (nestedKeys.length - 1); i++) {
        if (!currentObj[nestedKeys[i]]) {
            currentObj[nestedKeys[i]] = {};
        }
        currentObj = currentObj[nestedKeys[i]];
    }
    currentObj[nestedKeys[nestedKeys.length - 1]] = val;
}

/* eslint-disable camelcase */
export interface IFilterDefinition {
    event_fields?: string[];
    event_format?: "client" | "federation";
    presence?: IFilterComponent;
    account_data?: IFilterComponent;
    room?: IRoomFilter;
}

export interface IRoomEventFilter extends IFilterComponent {
    lazy_load_members?: boolean;
    include_redundant_members?: boolean;
    types?: EventType[] | string[];
    [UNSTABLE_FILTER_RELATION_TYPES.name]?: Array<RelationType | string>;
    [UNSTABLE_FILTER_RELATION_SENDERS.name]?: string[];
}

interface IStateFilter extends IRoomEventFilter {}

interface IRoomFilter {
    not_rooms?: string[];
    rooms?: string[];
    ephemeral?: IRoomEventFilter;
{'fraction_non_alphanumeric': 0.11216776396000976, 'fraction_numerical': 0.008290660814435503, 'mean_word_length': 3.9842041312272176, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1917007', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1183, 'n_words': 376}