forked from Nexus/nexus
add invite blocking support plus msc4494 support
To accomplish this I also reworked how account data is stored and added a method to fetch capabilities, and another method to set account data
This commit is contained in:
parent
115bec5f05
commit
f97c5548a3
11 changed files with 176 additions and 24 deletions
|
|
@ -1,16 +1,69 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
part "account_data.freezed.dart";
|
||||
part "account_data.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class AccountData with _$AccountData {
|
||||
const AccountData._();
|
||||
static List<dynamic>? readRecentEmojiValue(
|
||||
Map<dynamic, dynamic> json,
|
||||
String key,
|
||||
) => json[key]?["recent_emoji"];
|
||||
|
||||
static Map<String, List<dynamic>>? recentEmojiToJson(
|
||||
IList<RecentEmoji> recentEmoji,
|
||||
) => {"recent_emoji": recentEmoji.map((emoji) => emoji.toJson()).toList()};
|
||||
|
||||
const factory AccountData({
|
||||
required String userId,
|
||||
required String? roomId,
|
||||
required String type,
|
||||
required dynamic content,
|
||||
@JsonKey(name: InvitePermissionConfig.key)
|
||||
@Default(InvitePermissionConfig())
|
||||
InvitePermissionConfig invitePermissionConfig,
|
||||
|
||||
@JsonKey(name: "m.direct")
|
||||
@Default(IMap.empty())
|
||||
IMap<String, IList<String>> directMessages,
|
||||
|
||||
@JsonKey(
|
||||
name: "m.recent_emoji",
|
||||
readValue: AccountData.readRecentEmojiValue,
|
||||
toJson: AccountData.recentEmojiToJson,
|
||||
)
|
||||
@Default(IList.empty())
|
||||
IList<RecentEmoji> recentEmoji,
|
||||
}) = _AccountData;
|
||||
|
||||
factory AccountData.fromJson(Map<String, Object?> json) =>
|
||||
_$AccountDataFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class InvitePermissionConfig with _$InvitePermissionConfig {
|
||||
static const key = "m.invite_permission_config";
|
||||
|
||||
const factory InvitePermissionConfig({
|
||||
@JsonKey(unknownEnumValue: DefaultInviteAction.allow)
|
||||
@Default(DefaultInviteAction.allow)
|
||||
DefaultInviteAction defaultAction,
|
||||
}) = _InvitePermissionConfig;
|
||||
|
||||
factory InvitePermissionConfig.fromJson(Map<String, Object?> json) =>
|
||||
_$InvitePermissionConfigFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class RecentEmoji with _$RecentEmoji {
|
||||
const factory RecentEmoji({required String emoji, required int total}) =
|
||||
_RecentEmoji;
|
||||
|
||||
factory RecentEmoji.fromJson(Map<String, Object?> json) =>
|
||||
_$RecentEmojiFromJson(json);
|
||||
}
|
||||
|
||||
@JsonEnum(fieldRename: .snake)
|
||||
enum DefaultInviteAction {
|
||||
allow,
|
||||
deny,
|
||||
@JsonValue("uk.timedout.msc4494.deny_public")
|
||||
denyPublic,
|
||||
}
|
||||
|
|
|
|||
15
lib/models/requests/set_account_data.dart
Normal file
15
lib/models/requests/set_account_data.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
part "set_account_data.freezed.dart";
|
||||
part "set_account_data.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class SetAccountDataRequest with _$SetAccountDataRequest {
|
||||
const factory SetAccountDataRequest({
|
||||
required String type,
|
||||
required dynamic content,
|
||||
String? roomId,
|
||||
}) = _SetAccountDataRequest;
|
||||
|
||||
factory SetAccountDataRequest.fromJson(Map<String, Object?> json) =>
|
||||
_$SetAccountDataRequestFromJson(json);
|
||||
}
|
||||
25
lib/models/spec_versions_response.dart
Normal file
25
lib/models/spec_versions_response.dart
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
part "spec_versions_response.freezed.dart";
|
||||
part "spec_versions_response.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class SpecVersionsResponse with _$SpecVersionsResponse {
|
||||
const factory SpecVersionsResponse({
|
||||
required IList<String> versions,
|
||||
required UnstableFeatures unstableFeatures,
|
||||
}) = _SpecVersionsResponse;
|
||||
|
||||
factory SpecVersionsResponse.fromJson(Map<String, Object?> json) =>
|
||||
_$SpecVersionsResponseFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class UnstableFeatures with _$UnstableFeatures {
|
||||
const factory UnstableFeatures({
|
||||
@JsonKey(name: "uk.timedout.msc4494") @Default(false) bool msc4494,
|
||||
}) = _UnstableFeatures;
|
||||
|
||||
factory UnstableFeatures.fromJson(Map<String, Object?> json) =>
|
||||
_$UnstableFeaturesFromJson(json);
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
import "package:nexus/models/room.dart";
|
||||
import "package:nexus/models/space_edge.dart";
|
||||
part "sync_data.freezed.dart";
|
||||
|
|
@ -10,7 +9,7 @@ part "sync_data.g.dart";
|
|||
abstract class SyncData with _$SyncData {
|
||||
const factory SyncData({
|
||||
@Default(false) bool clearState,
|
||||
@Default(IMap.empty()) IMap<String, AccountData> accountData,
|
||||
@Default(IMap.empty()) IMap<String, IMap<String, dynamic>> accountData,
|
||||
@Default(IMap.empty()) IMap<String, Room> rooms,
|
||||
@Default(ISet.empty()) ISet<String> leftRooms,
|
||||
// required IList<InvitedRoom> invitedRooms,
|
||||
|
|
|
|||
Loading…
Reference in a new issue