1
0
Fork 0
forked from Nexus/nexus

Remove flutter chat (#26)

Had to squash merge manually as Forgejo was erroring
This commit is contained in:
Henry Hiles 2026-05-21 16:58:22 -04:00
commit 16cf126df4
111 changed files with 3162 additions and 2366 deletions

View file

@ -0,0 +1,15 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/membership_status.dart";
part "members_by_status_config.freezed.dart";
part "members_by_status_config.g.dart";
@freezed
abstract class MembersByStatusConfig with _$MembersByStatusConfig {
const factory MembersByStatusConfig({
required String roomId,
required MembershipStatus status,
}) = _MembersByStatusConfig;
factory MembersByStatusConfig.fromJson(Map<String, Object?> json) =>
_$MembersByStatusConfigFromJson(json);
}

View file

@ -1,28 +0,0 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/event.dart";
import "package:nexus/models/room.dart";
part "message_config.freezed.dart";
part "message_config.g.dart";
@freezed
abstract class MessageConfig with _$MessageConfig {
const MessageConfig._();
const factory MessageConfig({
@Default(false) bool alwaysReturn,
@Default(false) bool includeEdits,
required Room room,
required Event event,
}) = _MessageConfig;
@override
bool operator ==(Object other) =>
other.runtimeType == runtimeType &&
other is MessageConfig &&
other.event == event;
@override
int get hashCode => Object.hash(runtimeType, event);
factory MessageConfig.fromJson(Map<String, Object?> json) =>
_$MessageConfigFromJson(json);
}

View file

@ -1,17 +0,0 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/event.dart";
import "package:nexus/models/room.dart";
part "messages_config.freezed.dart";
part "messages_config.g.dart";
@freezed
abstract class MessagesConfig with _$MessagesConfig {
const factory MessagesConfig({
required Room room,
required IList<Event> events,
}) = _MessagesConfig;
factory MessagesConfig.fromJson(Map<String, Object?> json) =>
_$MessagesConfigFromJson(json);
}

View file

@ -1,17 +1,28 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/requests/membership_action.dart";
part "power_level_config.freezed.dart";
part "power_level_config.g.dart";
@freezed
abstract class PowerLevelConfig with _$PowerLevelConfig {
sealed class PowerLevelConfig with _$PowerLevelConfig {
const factory PowerLevelConfig({
@Default(false) bool isStateEvent,
required String eventType,
MembershipAction? action,
String? targetUser,
}) = _PowerLevelConfig;
required EventType eventType,
required String roomId,
}) = EventPowerLevelConfig;
factory PowerLevelConfig.fromJson(Map<String, Object?> json) =>
_$PowerLevelConfigFromJson(json);
const factory PowerLevelConfig.membershipAction({
required MembershipAction action,
required String targetUser,
required String roomId,
}) = MembershipActionPowerLevelConfig;
const factory PowerLevelConfig.state({
required EventType eventType,
required String roomId,
}) = StatePowerLevelConfig;
const factory PowerLevelConfig.redaction({
required String targetUser,
required String roomId,
}) = RedactionPowerLevelConfig;
}

View file

@ -0,0 +1,14 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "reactions_config.freezed.dart";
part "reactions_config.g.dart";
@freezed
abstract class ReactionsConfig with _$ReactionsConfig {
const factory ReactionsConfig({
required String roomId,
required int eventRowId,
}) = _ReactionsConfig;
factory ReactionsConfig.fromJson(Map<String, Object?> json) =>
_$ReactionsConfigFromJson(json);
}

View file

@ -0,0 +1,12 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "user_config.freezed.dart";
part "user_config.g.dart";
@freezed
abstract class UserConfig with _$UserConfig {
const factory UserConfig({required String? roomId, required String userId}) =
_UserConfig;
factory UserConfig.fromJson(Map<String, Object?> json) =>
_$UserConfigFromJson(json);
}

View file

@ -0,0 +1,14 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/info/image.dart";
part "avatar.freezed.dart";
part "avatar.g.dart";
@freezed
abstract class AvatarContent extends Content with _$AvatarContent {
AvatarContent._();
factory AvatarContent({ImageInfo? info, Uri? url}) = _AvatarContent;
factory AvatarContent.fromJson(Map<String, Object?> json) =>
_$AvatarContentFromJson(json);
}

View file

@ -0,0 +1,15 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "canonical_alias.freezed.dart";
part "canonical_alias.g.dart";
@freezed
abstract class CanonicalAliasContent extends Content
with _$CanonicalAliasContent {
CanonicalAliasContent._();
factory CanonicalAliasContent({String? alias, @Default([]) altAliases}) =
_CanonicalAliasContent;
factory CanonicalAliasContent.fromJson(Map<String, Object?> json) =>
_$CanonicalAliasContentFromJson(json);
}

View file

@ -0,0 +1,61 @@
import "package:collection/collection.dart";
import "package:nexus/models/content/avatar.dart";
import "package:nexus/models/content/canonical_alias.dart";
import "package:nexus/models/content/create.dart";
import "package:nexus/models/content/encryption.dart";
import "package:nexus/models/content/join_rules.dart";
import "package:nexus/models/content/membership.dart";
import "package:nexus/models/content/message.dart";
import "package:nexus/models/content/name.dart";
import "package:nexus/models/content/pinned_events.dart";
import "package:nexus/models/content/power_levels.dart";
import "package:nexus/models/content/reaction.dart";
import "package:nexus/models/content/encrypted.dart";
import "package:nexus/models/content/redaction.dart";
import "package:nexus/models/content/server_acl.dart";
import "package:nexus/models/content/topic.dart";
class Content {
final Error? parseError;
Content({this.parseError});
factory Content.fromJson(Map<String, dynamic> json) => Content();
Map<String, dynamic> toJson() => {};
static Map<String, dynamic> readValue(Map<dynamic, dynamic> json, _) =>
json["decrypted"] ?? json["content"];
static Content fromEventJson(Map<String, dynamic> json, String type) {
try {
return (EventType.values
.firstWhereOrNull((eventType) => eventType.type == type)
?.contentFromJson ??
Content.fromJson)(json);
} catch (error) {
if (error is Error) return Content(parseError: error);
rethrow;
}
}
}
enum EventType {
encrypted("m.room.encrypted", EncryptedContent.fromJson),
redaction("m.room.redaction", RedactionContent.fromJson),
encryption("m.room.encryption", EncryptionContent.fromJson),
membership("m.room.member", MembershipContent.fromJson),
create("m.room.create", CreateContent.fromJson),
canonicalAlias("m.room.canonical_alias", CanonicalAliasContent.fromJson),
joinRules("m.room.join_rules", JoinRulesContent.fromJson),
powerLevels("m.room.power_levels", PowerLevelsContent.fromJson),
serverACL("m.room.server_acl", ServerACLContent.fromJson),
avatar("m.room.avatar", AvatarContent.fromJson),
topic("m.room.topic", TopicContent.fromJson),
name("m.room.name", NameContent.fromJson),
reaction("m.reaction", ReactionContent.fromJson),
pinnedEvents("m.room.pinned_events", PinnedEventsContent.fromJson),
message("m.room.message", MessageContent.fromJson);
final String type;
final Content Function(Map<String, dynamic> json) contentFromJson;
const EventType(this.type, this.contentFromJson);
}

View file

@ -0,0 +1,41 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "create.freezed.dart";
part "create.g.dart";
@freezed
abstract class CreateContent extends Content with _$CreateContent {
CreateContent._();
factory CreateContent({
@JsonKey(name: "creator") String? creatorId,
@JsonKey(name: "additional_creators")
@Default(IList.empty())
IList<String> additionalCreatorIds,
PreviousRoom? predecessor,
@JsonKey(name: "m.federate") @Default(true) bool federated,
@Default("1") String roomVersion,
@JsonKey(unknownEnumValue: RoomType.room) RoomType? type,
}) = _CreateContent;
factory CreateContent.fromJson(Map<String, Object?> json) =>
_$CreateContentFromJson(json);
}
enum RoomType {
room,
@JsonValue("m.space")
space,
}
@freezed
abstract class PreviousRoom with _$PreviousRoom {
const factory PreviousRoom({required String roomId}) = _PreviousRoom;
factory PreviousRoom.fromJson(Map<String, Object?> json) =>
_$PreviousRoomFromJson(json);
}

View file

@ -0,0 +1,13 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "encrypted.freezed.dart";
part "encrypted.g.dart";
@freezed
abstract class EncryptedContent extends Content with _$EncryptedContent {
EncryptedContent._();
factory EncryptedContent() = _EncryptedContent;
factory EncryptedContent.fromJson(Map<String, Object?> json) =>
_$EncryptedContentFromJson(json);
}

View file

@ -0,0 +1,23 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "encryption.freezed.dart";
part "encryption.g.dart";
@freezed
abstract class EncryptionContent extends Content with _$EncryptionContent {
EncryptionContent._();
factory EncryptionContent({
required String algorithm,
@JsonKey(name: "rotation_period_ms")
@Default(604800000)
int rotationPeriodMS,
@JsonKey(name: "rotation_period_msgs")
@Default(100)
int rotationPeriodMessages,
}) = _EncryptionContent;
factory EncryptionContent.fromJson(Map<String, Object?> json) =>
_$EncryptionContentFromJson(json);
}

View file

@ -0,0 +1,34 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/join_rule.dart";
part "join_rules.freezed.dart";
part "join_rules.g.dart";
@freezed
abstract class JoinRulesContent extends Content with _$JoinRulesContent {
JoinRulesContent._();
factory JoinRulesContent({
required JoinRule joinRule,
@Default(IList.empty()) IList<AllowCondition> allow,
}) = _JoinRulesContent;
factory JoinRulesContent.fromJson(Map<String, Object?> json) =>
_$JoinRulesContentFromJson(json);
}
@freezed
abstract class AllowCondition with _$AllowCondition {
const factory AllowCondition({
String? roomId,
required AllowConditionType type,
}) = _AllowCondition;
factory AllowCondition.fromJson(Map<String, Object?> json) =>
_$AllowConditionFromJson(json);
}
enum AllowConditionType {
@JsonValue("m.room_membership")
membership,
}

View file

@ -0,0 +1,19 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/membership_status.dart";
part "membership.freezed.dart";
part "membership.g.dart";
@freezed
abstract class MembershipContent extends Content with _$MembershipContent {
MembershipContent._();
factory MembershipContent({
@JsonKey(name: "displayname") required String? displayName,
@JsonKey(name: "membership") required MembershipStatus status,
Uri? avatarUrl,
String? reason,
}) = _MembershipContent;
factory MembershipContent.fromJson(Map<String, Object?> json) =>
_$MembershipContentFromJson(json);
}

View file

@ -0,0 +1,92 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/info/audio.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/info/file.dart";
import "package:nexus/models/info/image.dart";
import "package:nexus/models/info/video.dart";
part "message.freezed.dart";
part "message.g.dart";
@Freezed(unionKey: "msgtype", fallbackUnion: "default")
abstract class MessageContent extends Content with _$MessageContent {
MessageContent._();
factory MessageContent({required String body}) = UnknownMessageContent;
@FreezedUnionValue("m.text")
factory MessageContent.text({
required String body,
MessageFormat? format,
String? formattedBody,
}) = TextMessageContent;
@FreezedUnionValue("m.notice")
factory MessageContent.notice({
required String body,
MessageFormat? format,
String? formattedBody,
}) = NoticeMessageContent;
@FreezedUnionValue("m.emote")
factory MessageContent.emote({
required String body,
MessageFormat? format,
String? formattedBody,
}) = EmoteMessageContent;
@FreezedUnionValue("m.image")
factory MessageContent.image({
required String body,
MessageFormat? format,
String? formattedBody,
// EncryptedFile? file
String? filename,
ImageInfo? info,
Uri? url,
}) = ImageMessageContent;
@FreezedUnionValue("m.file")
factory MessageContent.file({
required String body,
MessageFormat? format,
String? formattedBody,
// EncryptedFile? file
String? filename,
FileInfo? info,
Uri? url,
}) = FileMessageContent;
@FreezedUnionValue("m.audio")
factory MessageContent.audio({
required String body,
MessageFormat? format,
String? formattedBody,
// EncryptedFile? file
String? filename,
AudioInfo? info,
Uri? url,
}) = AudioMessageContent;
@FreezedUnionValue("m.video")
factory MessageContent.video({
required String body,
MessageFormat? format,
String? formattedBody,
// EncryptedFile? file
String? filename,
VideoInfo? info,
Uri? url,
}) = VideoMessageContent;
@FreezedUnionValue("m.location")
factory MessageContent.location({required String body, required Uri geoUri}) =
LocationMessageContent;
factory MessageContent.fromJson(Map<String, Object?> json) =>
_$MessageContentFromJson(json);
}
@JsonEnum()
enum MessageFormat {
@JsonValue("org.matrix.custom.html")
html,
}

View file

@ -0,0 +1,13 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "name.freezed.dart";
part "name.g.dart";
@freezed
abstract class NameContent extends Content with _$NameContent {
NameContent._();
factory NameContent({required String name}) = _NameContent;
factory NameContent.fromJson(Map<String, Object?> json) =>
_$NameContentFromJson(json);
}

View file

@ -0,0 +1,15 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "pinned_events.freezed.dart";
part "pinned_events.g.dart";
@freezed
abstract class PinnedEventsContent extends Content with _$PinnedEventsContent {
PinnedEventsContent._();
factory PinnedEventsContent({@Default(IList.empty()) IList<String> pinned}) =
_PinnedEventsContent;
factory PinnedEventsContent.fromJson(Map<String, Object?> json) =>
_$PinnedEventsContentFromJson(json);
}

View file

@ -0,0 +1,36 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "power_levels.freezed.dart";
part "power_levels.g.dart";
@freezed
abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
PowerLevelsContent._();
factory PowerLevelsContent({
@Default(IMap.empty()) IMap<String, int> events,
@Default(IMap.empty()) IMap<String, int> users,
Notifications? notifications,
@Default(50) int ban,
@Default(0) int eventsDefault,
@Default(0) int invite,
@Default(50) int kick,
@Default(50) int redact,
@Default(50) int stateDefault,
@Default(0) int usersDefault,
}) = _PowerLevelsContent;
factory PowerLevelsContent.fromJson(Map<String, Object?> json) =>
_$PowerLevelsContentFromJson(json);
}
@freezed
abstract class Notifications with _$Notifications {
const factory Notifications({
@Default(50) int room,
@Default(IMapConst({})) IMap<String, int> other,
}) = _Notifications;
factory Notifications.fromJson(Map<String, Object?> json) =>
_$NotificationsFromJson(json);
}

View file

@ -0,0 +1,18 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "reaction.freezed.dart";
part "reaction.g.dart";
@freezed
abstract class ReactionContent extends Content with _$ReactionContent {
ReactionContent._();
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
json["m.relates_to"]?["key"];
factory ReactionContent({
@JsonKey(readValue: ReactionContent.keyJsonFromJson) String? key,
}) = _ReactionContent;
factory ReactionContent.fromJson(Map<String, Object?> json) =>
_$ReactionContentFromJson(json);
}

View file

@ -0,0 +1,14 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "redaction.freezed.dart";
part "redaction.g.dart";
@freezed
abstract class RedactionContent extends Content with _$RedactionContent {
RedactionContent._();
factory RedactionContent({String? reason, String? redacts}) =
_RedactionContent;
factory RedactionContent.fromJson(Map<String, Object?> json) =>
_$RedactionContentFromJson(json);
}

View file

@ -0,0 +1,18 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "server_acl.freezed.dart";
part "server_acl.g.dart";
@freezed
abstract class ServerACLContent extends Content with _$ServerACLContent {
ServerACLContent._();
factory ServerACLContent({
@Default(IList.empty()) IList<String> allow,
@Default(IList.empty()) IList<String> deny,
@Default(true) allowIpLiterals,
}) = _ServerACLContent;
factory ServerACLContent.fromJson(Map<String, Object?> json) =>
_$ServerACLContentFromJson(json);
}

View file

@ -0,0 +1,40 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "topic.freezed.dart";
part "topic.g.dart";
@freezed
abstract class TopicContent extends Content with _$TopicContent {
TopicContent._();
factory TopicContent({
required String topic,
@JsonKey(name: "m.topic") TopicContentBlock? content,
}) = _TopicContent;
factory TopicContent.fromJson(Map<String, Object?> json) =>
_$TopicContentFromJson(json);
}
@freezed
abstract class TopicContentBlock with _$TopicContentBlock {
factory TopicContentBlock({
@Default(IList.empty())
@JsonKey(name: "m.text")
IList<TextualRepresentation> representations,
}) = _TopicContentBlock;
factory TopicContentBlock.fromJson(Map<String, Object?> json) =>
_$TopicContentBlockFromJson(json);
}
@freezed
abstract class TextualRepresentation with _$TextualRepresentation {
factory TextualRepresentation({
required String body,
@Default("text/plain") String mimetype,
}) = _TextualRepresentation;
factory TextualRepresentation.fromJson(Map<String, Object?> json) =>
_$TextualRepresentationFromJson(json);
}

View file

@ -1,37 +1,69 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/epoch_date_time_converter.dart";
import "package:nexus/models/profile.dart";
part "event.freezed.dart";
part "event.g.dart";
@freezed
abstract class Event with _$Event {
static String typeJsonFromJson(Map<dynamic, dynamic> json, _) =>
json["decrypted_type"] ?? json["type"];
static Map<String, dynamic> getContentFromJson(Map<dynamic, dynamic> json) {
final content = json["decrypted"] ?? json["content"];
return content["m.new_content"] ?? content;
}
const factory Event({
@JsonKey(name: "rowid") required int rowId,
@JsonKey(name: "timeline_rowid") required int timelineRowId,
required String roomId,
required String eventId,
@JsonKey(name: "sender") required String authorId,
required String type,
required String sender,
@JsonKey(readValue: Event.typeJsonFromJson) required String type,
String? stateKey,
@EpochDateTimeConverter() required DateTime timestamp,
required IMap<String, dynamic> content,
IMap<String, dynamic>? decrypted,
String? decryptedType,
@Default(IMap.empty()) IMap<String, dynamic> unsigned,
LocalContent? localContent,
String? transactionId,
String? redactedBy,
String? relatesTo,
String? relationType,
String? replyTo,
String? decryptionError,
String? sendError,
@Default(IMap.empty()) IMap<String, int> reactions,
@JsonKey(name: "last_edit_rowid") int? lastEditRowId,
@JsonKey(name: "last_edit_rowid") @Default(0) int lastEditRowId,
@UnreadTypeConverter() UnreadType? unreadType,
Profile? pmp,
required Content content,
required Content? previousContent,
}) = _Event;
factory Event.fromJson(Map<String, Object?> json) => _$EventFromJson(json);
factory Event.fromJson(Map<String, dynamic> json) =>
_$EventFromJson(json).copyWith(
replyTo: getContentFromJson(
json,
)["m.relates_to"]?["m.in_reply_to"]?["event_id"],
pmp: json["content"]?["com.beeper.per_message_profile"] == null
? null
: Profile.fromJsonWithCatch(
json["content"]?["com.beeper.per_message_profile"],
),
content: Content.fromEventJson(
getContentFromJson(json),
json["decrypted_type"] ?? json["type"],
),
previousContent: json["unsigned"]?["prev_content"] == null
? null
: Content.fromEventJson(
json["unsigned"]?["prev_content"],
json["decrypted_type"] ?? json["type"],
),
);
}
@freezed

View file

@ -0,0 +1,17 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/ms_duration.dart";
part "audio.freezed.dart";
part "audio.g.dart";
@freezed
abstract class AudioInfo with _$AudioInfo {
/// Information for images, [size] is in bytes.
const factory AudioInfo({
@MSDuration() Duration? duration,
@JsonKey(name: "mimetype") String? mimeType,
int? size,
}) = _AudioInfo;
factory AudioInfo.fromJson(Map<String, Object?> json) =>
_$AudioInfoFromJson(json);
}

15
lib/models/info/file.dart Normal file
View file

@ -0,0 +1,15 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "file.freezed.dart";
part "file.g.dart";
@freezed
abstract class FileInfo with _$FileInfo {
/// Information for images, [size] is in bytes.
const factory FileInfo({
@JsonKey(name: "mimetype") String? mimeType,
int? size,
}) = _FileInfo;
factory FileInfo.fromJson(Map<String, Object?> json) =>
_$FileInfoFromJson(json);
}

View file

@ -0,0 +1,18 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "image.freezed.dart";
part "image.g.dart";
@freezed
abstract class ImageInfo with _$ImageInfo {
/// Information for images, [size] is in bytes.
const factory ImageInfo({
@JsonKey(name: "h") double? height,
@JsonKey(name: "w") double? width,
@JsonKey(name: "mimetype") String? mimeType,
@JsonKey(name: "xyz.amorgan.blurhash") String? blurHash,
int? size,
}) = _ImageInfo;
factory ImageInfo.fromJson(Map<String, Object?> json) =>
_$ImageInfoFromJson(json);
}

View file

@ -0,0 +1,19 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/ms_duration.dart";
part "video.freezed.dart";
part "video.g.dart";
@freezed
abstract class VideoInfo with _$VideoInfo {
/// Information for images, [size] is in bytes.
const factory VideoInfo({
@JsonKey(name: "h") int? height,
@JsonKey(name: "w") int? width,
@JsonKey(name: "mimetype") String? mimeType,
@MSDuration() Duration? duration,
int? size,
}) = _VideoInfo;
factory VideoInfo.fromJson(Map<String, Object?> json) =>
_$VideoInfoFromJson(json);
}

View file

@ -0,0 +1,4 @@
import "package:freezed_annotation/freezed_annotation.dart";
@JsonEnum(fieldRename: FieldRename.snake)
enum JoinRule { public, knock, invite, private, restricted, knockRestricted }

View file

@ -1,32 +0,0 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/helpers/extensions/mxc_to_https.dart";
import "package:nexus/models/membership_status.dart";
part "membership.freezed.dart";
@freezed
abstract class Membership with _$Membership {
const Membership._();
const factory Membership({
required MembershipStatus status,
required Uri? avatarUrl,
required String displayName,
required String userId,
}) = _Membership;
factory Membership.fromContent(
IMap<String, dynamic> content,
String userId,
String homeserver,
) => Membership(
status: MembershipStatus.values.firstWhere(
(status) => status.name == content["membership"],
orElse: () => MembershipStatus.leave,
),
avatarUrl: Uri.tryParse(
content["avatar_url"] ?? "",
)?.mxcToHttps(homeserver),
userId: userId,
displayName: content["displayname"] ?? userId.substring(1).split(":").first,
);
}

View file

@ -1,4 +1,4 @@
import "package:freezed_annotation/freezed_annotation.dart";
@JsonEnum()
enum MembershipStatus { leave, invite, ban, join }
enum MembershipStatus { leave, invite, ban, join, knock }

View file

@ -0,0 +1,11 @@
import "package:freezed_annotation/freezed_annotation.dart";
class MSDuration implements JsonConverter<Duration, int> {
const MSDuration();
@override
Duration fromJson(int ms) => Duration(milliseconds: ms);
@override
int toJson(Duration duration) => duration.inMilliseconds;
}

View file

@ -0,0 +1,17 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "open_graph_data.freezed.dart";
part "open_graph_data.g.dart";
@freezed
abstract class OpenGraphData with _$OpenGraphData {
const factory OpenGraphData({
@JsonKey(name: "og:title") required String? title,
@JsonKey(name: "og:description") required String? description,
@JsonKey(name: "og:image") required Uri? imageUrl,
@JsonKey(name: "og:image:width") required double? width,
@JsonKey(name: "og:image:height") required double? height,
}) = _OpenGraphData;
factory OpenGraphData.fromJson(Map<String, dynamic> json) =>
_$OpenGraphDataFromJson(json);
}

View file

@ -12,18 +12,28 @@ Object? readTimezone(Map<dynamic, dynamic> map, _) =>
@freezed
abstract class Profile with _$Profile {
const factory Profile({
String? avatarUrl,
required String id,
String? parseError,
Uri? avatarUrl,
@JsonKey(name: "displayname") String? displayName,
@JsonKey(readValue: readTimezone) String? timezone,
@JsonKey(readValue: readTimezone, name: "m.tz") String? timezone,
@Default(IList.empty())
@JsonKey(readValue: readPronouns)
@JsonKey(readValue: readPronouns, name: "io.fsky.nyx.pronouns")
IList<Pronoun> pronouns,
}) = _Profile;
factory Profile.fromJson(Map<String, Object?> json) =>
factory Profile.fromJson(Map<String, dynamic> json) =>
_$ProfileFromJson(json);
factory Profile.fromJsonWithCatch(Map<String, dynamic> json) {
try {
return Profile.fromJson(json);
} catch (error) {
return Profile(id: json["id"], parseError: error.toString());
}
}
}
@freezed

View file

@ -1,32 +1,16 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/room.dart";
part "get_event_request.freezed.dart";
part "get_event_request.g.dart";
@Freezed(toJson: false)
@Freezed()
abstract class GetEventRequest with _$GetEventRequest {
const GetEventRequest._();
const factory GetEventRequest({
required Room room,
required String roomId,
required String eventId,
@Default(false) bool unredact,
}) = _GetEventRequest;
Map<String, dynamic> toJson() => {
"room_id": room.metadata?.id,
"event_id": eventId,
"unredact": unredact,
};
@override
bool operator ==(Object other) =>
other.runtimeType == runtimeType &&
other is GetEventRequest &&
other.eventId == eventId;
@override
int get hashCode => Object.hash(runtimeType, eventId);
factory GetEventRequest.fromJson(Map<String, Object?> json) =>
_$GetEventRequestFromJson(json);
}

View file

@ -8,29 +8,48 @@ part "room.g.dart";
@freezed
abstract class Room with _$Room {
static IMap<int, int?> timelineTupleJsonToIMap(List<dynamic> json) =>
IMap.fromEntries(
json.map(
(timelineTuple) => MapEntry(
timelineTuple["timeline_rowid"],
timelineTuple["event_rowid"],
),
),
);
static IMap<int, Event> eventsJsonToIMap(List<dynamic> json) =>
IMap.fromEntries(
json.map((eventJson) {
final event = Event.fromJson(eventJson);
return MapEntry(event.rowId, event);
}),
);
/// [timeline] is an IMap of timelineRowId to eventRowId
/// [events] is an IMap of eventRowId to event
const factory Room({
@JsonKey(name: "meta") RoomMetadata? metadata,
@Default(IList.empty()) IList<TimelineRowTuple> timeline,
@Default(IMap.empty())
@JsonKey(fromJson: Room.timelineTupleJsonToIMap)
IMap<int, int?> timeline,
@Default(IMap.empty())
@JsonKey(fromJson: Room.eventsJsonToIMap)
IMap<int, Event> events,
@Default(false) bool reset,
@Default(false) bool hasFetchedState,
@Default(false) bool hasFetchedMembers,
@Default(IMap.empty()) IMap<String, IMap<String, int>> state,
// required IMap<String, AccountData> accountData,
@Default(IList.empty()) IList<Event> events,
@Default(IMap.empty()) IMap<String, IList<ReadReceipt>> receipts,
@Default(false) bool dismissNotifications,
@Default(true) bool hasMore,
// required IMap<String, AccountData> accountData,
// required IList<Notification> notifications,
}) = _Room;
factory Room.fromJson(Map<String, Object?> json) => _$RoomFromJson(json);
}
@freezed
abstract class TimelineRowTuple with _$TimelineRowTuple {
const factory TimelineRowTuple({
@JsonKey(name: "timeline_rowid") required int timelineRowId,
@JsonKey(name: "event_rowid") int? eventRowId,
}) = _TimelineRowTuple;
factory TimelineRowTuple.fromJson(Map<String, Object?> json) =>
_$TimelineRowTupleFromJson(json);
}