/* * Famedly Matrix SDK * Copyright (C) 2019, 2020 Famedly GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ enum EventFormat { client, federation } class Filter { RoomFilter room; EventFilter presence; EventFilter accountData; EventFormat eventFormat; List eventFields; Filter({ this.room, this.presence, this.accountData, this.eventFormat, this.eventFields, }); Filter.fromJson(Map json) { room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null; presence = json['presence'] != null ? EventFilter.fromJson(json['presence']) : null; accountData = json['account_data'] != null ? EventFilter.fromJson(json['account_data']) : null; eventFormat = json['event_format'] != null ? EventFormat.values.firstWhere( (e) => e.toString().split('.').last == json['event_format']) : null; eventFields = json['event_fields'] != null ? json['event_fields'].cast() : null; } Map toJson() { final data = {}; if (room != null) { data['room'] = room.toJson(); } if (presence != null) { data['presence'] = presence.toJson(); } if (eventFormat != null) { data['event_format'] = eventFormat.toString().split('.').last; } if (eventFields != null) { data['event_fields'] = eventFields; } if (accountData != null) { data['account_data'] = accountData.toJson(); } return data; } } class RoomFilter { List notRooms; List rooms; StateFilter ephemeral; bool includeLeave; StateFilter state; StateFilter timeline; StateFilter accountData; RoomFilter({ this.notRooms, this.rooms, this.ephemeral, this.includeLeave, this.state, this.timeline, this.accountData, }); RoomFilter.fromJson(Map json) { notRooms = json['not_rooms']?.cast(); rooms = json['rooms']?.cast(); state = json['state'] != null ? StateFilter.fromJson(json['state']) : null; includeLeave = json['include_leave']; timeline = json['timeline'] != null ? StateFilter.fromJson(json['timeline']) : null; ephemeral = json['ephemeral'] != null ? StateFilter.fromJson(json['ephemeral']) : null; accountData = json['account_data'] != null ? StateFilter.fromJson(json['account_data']) : null; } Map toJson() { final data = {}; if (notRooms != null) { data['not_rooms'] = notRooms; } if (rooms != null) { data['rooms'] = rooms; } if (ephemeral != null) { data['ephemeral'] = ephemeral.toJson(); } if (includeLeave != null) { data['include_leave'] = includeLeave; } if (state != null) { data['state'] = state.toJson(); } if (timeline != null) { data['timeline'] = timeline.toJson(); } if (accountData != null) { data['account_data'] = accountData.toJson(); } return data; } } class EventFilter { int limit; List senders; List types; List notRooms; List notSenders; EventFilter( {this.limit, this.senders, this.types, this.notRooms, this.notSenders}); EventFilter.fromJson(Map json) { limit = json['limit']; types = json['senders']?.cast(); types = json['types']?.cast(); notRooms = json['not_rooms']?.cast(); notSenders = json['not_senders']?.cast(); } Map toJson() { final data = {}; if (limit != null) data['limit'] = limit; if (types != null) data['types'] = types; if (notRooms != null) data['not_rooms'] = notRooms; if (notSenders != null) data['not_senders'] = notSenders; return data; } } class StateFilter extends EventFilter { List notTypes; bool lazyLoadMembers; bool includeRedundantMembers; bool containsUrl; StateFilter({ this.notTypes, this.lazyLoadMembers, this.includeRedundantMembers, this.containsUrl, int limit, List senders, List types, List notRooms, List notSenders, }) : super( limit: limit, senders: senders, types: types, notRooms: notRooms, notSenders: notSenders, ); StateFilter.fromJson(Map json) { final eventFilter = EventFilter.fromJson(json); limit = eventFilter.limit; senders = eventFilter.senders; types = eventFilter.types; notRooms = eventFilter.notRooms; notSenders = eventFilter.notSenders; notTypes = json['not_types']?.cast(); lazyLoadMembers = json['lazy_load_members']; includeRedundantMembers = json['include_redundant_members']; containsUrl = json['contains_url']; } @override Map toJson() { final data = super.toJson(); if (limit != null) { data['limit'] = limit; } if (notTypes != null) { data['not_types'] = notTypes; } if (lazyLoadMembers != null) { data['lazy_load_members'] = notTypes; } if (includeRedundantMembers != null) { data['include_redundant_members'] = notTypes; } if (containsUrl != null) { data['contains_url'] = notTypes; } return data; } }