From 99e10cb612ad2df2532b3c0af15e4310eb904517 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 18 Aug 2025 02:01:13 +0800 Subject: [PATCH] :sparkles: Chat, realm member list with status --- lib/models/chat.dart | 1 + lib/models/chat.freezed.dart | 71 ++++++++++++++++++++--------- lib/models/chat.g.dart | 7 +++ lib/models/realm.dart | 1 + lib/models/realm.freezed.dart | 71 ++++++++++++++++++++--------- lib/models/realm.g.dart | 7 +++ lib/screens/chat/room.g.dart | 2 +- lib/screens/chat/room_detail.dart | 5 +- lib/screens/realm/realm_detail.dart | 19 +++++--- lib/widgets/account/status.dart | 39 ++++++++++++++++ 10 files changed, 171 insertions(+), 52 deletions(-) diff --git a/lib/models/chat.dart b/lib/models/chat.dart index 09f391fd..42f39685 100644 --- a/lib/models/chat.dart +++ b/lib/models/chat.dart @@ -91,6 +91,7 @@ sealed class SnChatMember with _$SnChatMember { required DateTime? breakUntil, required DateTime? timeoutUntil, required bool isBot, + required SnAccountStatus? status, // Frontend data DateTime? lastTyped, }) = _SnChatMember; diff --git a/lib/models/chat.freezed.dart b/lib/models/chat.freezed.dart index df590064..6dd772b7 100644 --- a/lib/models/chat.freezed.dart +++ b/lib/models/chat.freezed.dart @@ -1037,7 +1037,7 @@ $SnChatMemberCopyWith<$Res> get sender { /// @nodoc mixin _$SnChatMember { - DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; String get id; String get chatRoomId; SnChatRoom? get chatRoom; String get accountId; SnAccount get account; String? get nick; int get role; int get notify; DateTime? get joinedAt; DateTime? get breakUntil; DateTime? get timeoutUntil; bool get isBot;// Frontend data + DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; String get id; String get chatRoomId; SnChatRoom? get chatRoom; String get accountId; SnAccount get account; String? get nick; int get role; int get notify; DateTime? get joinedAt; DateTime? get breakUntil; DateTime? get timeoutUntil; bool get isBot; SnAccountStatus? get status;// Frontend data DateTime? get lastTyped; /// Create a copy of SnChatMember /// with the given fields replaced by the non-null parameter values. @@ -1051,16 +1051,16 @@ $SnChatMemberCopyWith get copyWith => _$SnChatMemberCopyWithImpl Object.hash(runtimeType,createdAt,updatedAt,deletedAt,id,chatRoomId,chatRoom,accountId,account,nick,role,notify,joinedAt,breakUntil,timeoutUntil,isBot,lastTyped); +int get hashCode => Object.hash(runtimeType,createdAt,updatedAt,deletedAt,id,chatRoomId,chatRoom,accountId,account,nick,role,notify,joinedAt,breakUntil,timeoutUntil,isBot,status,lastTyped); @override String toString() { - return 'SnChatMember(createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, id: $id, chatRoomId: $chatRoomId, chatRoom: $chatRoom, accountId: $accountId, account: $account, nick: $nick, role: $role, notify: $notify, joinedAt: $joinedAt, breakUntil: $breakUntil, timeoutUntil: $timeoutUntil, isBot: $isBot, lastTyped: $lastTyped)'; + return 'SnChatMember(createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, id: $id, chatRoomId: $chatRoomId, chatRoom: $chatRoom, accountId: $accountId, account: $account, nick: $nick, role: $role, notify: $notify, joinedAt: $joinedAt, breakUntil: $breakUntil, timeoutUntil: $timeoutUntil, isBot: $isBot, status: $status, lastTyped: $lastTyped)'; } @@ -1071,11 +1071,11 @@ abstract mixin class $SnChatMemberCopyWith<$Res> { factory $SnChatMemberCopyWith(SnChatMember value, $Res Function(SnChatMember) _then) = _$SnChatMemberCopyWithImpl; @useResult $Res call({ - DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, DateTime? lastTyped + DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, SnAccountStatus? status, DateTime? lastTyped }); -$SnChatRoomCopyWith<$Res>? get chatRoom;$SnAccountCopyWith<$Res> get account; +$SnChatRoomCopyWith<$Res>? get chatRoom;$SnAccountCopyWith<$Res> get account;$SnAccountStatusCopyWith<$Res>? get status; } /// @nodoc @@ -1088,7 +1088,7 @@ class _$SnChatMemberCopyWithImpl<$Res> /// Create a copy of SnChatMember /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? id = null,Object? chatRoomId = null,Object? chatRoom = freezed,Object? accountId = null,Object? account = null,Object? nick = freezed,Object? role = null,Object? notify = null,Object? joinedAt = freezed,Object? breakUntil = freezed,Object? timeoutUntil = freezed,Object? isBot = null,Object? lastTyped = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? id = null,Object? chatRoomId = null,Object? chatRoom = freezed,Object? accountId = null,Object? account = null,Object? nick = freezed,Object? role = null,Object? notify = null,Object? joinedAt = freezed,Object? breakUntil = freezed,Object? timeoutUntil = freezed,Object? isBot = null,Object? status = freezed,Object? lastTyped = freezed,}) { return _then(_self.copyWith( createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable @@ -1105,7 +1105,8 @@ as int,joinedAt: freezed == joinedAt ? _self.joinedAt : joinedAt // ignore: cast as DateTime?,breakUntil: freezed == breakUntil ? _self.breakUntil : breakUntil // ignore: cast_nullable_to_non_nullable as DateTime?,timeoutUntil: freezed == timeoutUntil ? _self.timeoutUntil : timeoutUntil // ignore: cast_nullable_to_non_nullable as DateTime?,isBot: null == isBot ? _self.isBot : isBot // ignore: cast_nullable_to_non_nullable -as bool,lastTyped: freezed == lastTyped ? _self.lastTyped : lastTyped // ignore: cast_nullable_to_non_nullable +as bool,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable +as SnAccountStatus?,lastTyped: freezed == lastTyped ? _self.lastTyped : lastTyped // ignore: cast_nullable_to_non_nullable as DateTime?, )); } @@ -1130,6 +1131,18 @@ $SnAccountCopyWith<$Res> get account { return $SnAccountCopyWith<$Res>(_self.account, (value) { return _then(_self.copyWith(account: value)); }); +}/// Create a copy of SnChatMember +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$SnAccountStatusCopyWith<$Res>? get status { + if (_self.status == null) { + return null; + } + + return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) { + return _then(_self.copyWith(status: value)); + }); } } @@ -1209,10 +1222,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, DateTime? lastTyped)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, SnAccountStatus? status, DateTime? lastTyped)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _SnChatMember() when $default != null: -return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.lastTyped);case _: +return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.status,_that.lastTyped);case _: return orElse(); } @@ -1230,10 +1243,10 @@ return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.c /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, DateTime? lastTyped) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, SnAccountStatus? status, DateTime? lastTyped) $default,) {final _that = this; switch (_that) { case _SnChatMember(): -return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.lastTyped);} +return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.status,_that.lastTyped);} } /// A variant of `when` that fallback to returning `null` /// @@ -1247,10 +1260,10 @@ return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.c /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, DateTime? lastTyped)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, SnAccountStatus? status, DateTime? lastTyped)? $default,) {final _that = this; switch (_that) { case _SnChatMember() when $default != null: -return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.lastTyped);case _: +return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.chatRoomId,_that.chatRoom,_that.accountId,_that.account,_that.nick,_that.role,_that.notify,_that.joinedAt,_that.breakUntil,_that.timeoutUntil,_that.isBot,_that.status,_that.lastTyped);case _: return null; } @@ -1262,7 +1275,7 @@ return $default(_that.createdAt,_that.updatedAt,_that.deletedAt,_that.id,_that.c @JsonSerializable() class _SnChatMember implements SnChatMember { - const _SnChatMember({required this.createdAt, required this.updatedAt, required this.deletedAt, required this.id, required this.chatRoomId, required this.chatRoom, required this.accountId, required this.account, required this.nick, required this.role, required this.notify, required this.joinedAt, required this.breakUntil, required this.timeoutUntil, required this.isBot, this.lastTyped}); + const _SnChatMember({required this.createdAt, required this.updatedAt, required this.deletedAt, required this.id, required this.chatRoomId, required this.chatRoom, required this.accountId, required this.account, required this.nick, required this.role, required this.notify, required this.joinedAt, required this.breakUntil, required this.timeoutUntil, required this.isBot, required this.status, this.lastTyped}); factory _SnChatMember.fromJson(Map json) => _$SnChatMemberFromJson(json); @override final DateTime createdAt; @@ -1280,6 +1293,7 @@ class _SnChatMember implements SnChatMember { @override final DateTime? breakUntil; @override final DateTime? timeoutUntil; @override final bool isBot; +@override final SnAccountStatus? status; // Frontend data @override final DateTime? lastTyped; @@ -1296,16 +1310,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnChatMember&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)&&(identical(other.id, id) || other.id == id)&&(identical(other.chatRoomId, chatRoomId) || other.chatRoomId == chatRoomId)&&(identical(other.chatRoom, chatRoom) || other.chatRoom == chatRoom)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.nick, nick) || other.nick == nick)&&(identical(other.role, role) || other.role == role)&&(identical(other.notify, notify) || other.notify == notify)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.breakUntil, breakUntil) || other.breakUntil == breakUntil)&&(identical(other.timeoutUntil, timeoutUntil) || other.timeoutUntil == timeoutUntil)&&(identical(other.isBot, isBot) || other.isBot == isBot)&&(identical(other.lastTyped, lastTyped) || other.lastTyped == lastTyped)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnChatMember&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)&&(identical(other.id, id) || other.id == id)&&(identical(other.chatRoomId, chatRoomId) || other.chatRoomId == chatRoomId)&&(identical(other.chatRoom, chatRoom) || other.chatRoom == chatRoom)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.nick, nick) || other.nick == nick)&&(identical(other.role, role) || other.role == role)&&(identical(other.notify, notify) || other.notify == notify)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.breakUntil, breakUntil) || other.breakUntil == breakUntil)&&(identical(other.timeoutUntil, timeoutUntil) || other.timeoutUntil == timeoutUntil)&&(identical(other.isBot, isBot) || other.isBot == isBot)&&(identical(other.status, status) || other.status == status)&&(identical(other.lastTyped, lastTyped) || other.lastTyped == lastTyped)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,createdAt,updatedAt,deletedAt,id,chatRoomId,chatRoom,accountId,account,nick,role,notify,joinedAt,breakUntil,timeoutUntil,isBot,lastTyped); +int get hashCode => Object.hash(runtimeType,createdAt,updatedAt,deletedAt,id,chatRoomId,chatRoom,accountId,account,nick,role,notify,joinedAt,breakUntil,timeoutUntil,isBot,status,lastTyped); @override String toString() { - return 'SnChatMember(createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, id: $id, chatRoomId: $chatRoomId, chatRoom: $chatRoom, accountId: $accountId, account: $account, nick: $nick, role: $role, notify: $notify, joinedAt: $joinedAt, breakUntil: $breakUntil, timeoutUntil: $timeoutUntil, isBot: $isBot, lastTyped: $lastTyped)'; + return 'SnChatMember(createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, id: $id, chatRoomId: $chatRoomId, chatRoom: $chatRoom, accountId: $accountId, account: $account, nick: $nick, role: $role, notify: $notify, joinedAt: $joinedAt, breakUntil: $breakUntil, timeoutUntil: $timeoutUntil, isBot: $isBot, status: $status, lastTyped: $lastTyped)'; } @@ -1316,11 +1330,11 @@ abstract mixin class _$SnChatMemberCopyWith<$Res> implements $SnChatMemberCopyWi factory _$SnChatMemberCopyWith(_SnChatMember value, $Res Function(_SnChatMember) _then) = __$SnChatMemberCopyWithImpl; @override @useResult $Res call({ - DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, DateTime? lastTyped + DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, String id, String chatRoomId, SnChatRoom? chatRoom, String accountId, SnAccount account, String? nick, int role, int notify, DateTime? joinedAt, DateTime? breakUntil, DateTime? timeoutUntil, bool isBot, SnAccountStatus? status, DateTime? lastTyped }); -@override $SnChatRoomCopyWith<$Res>? get chatRoom;@override $SnAccountCopyWith<$Res> get account; +@override $SnChatRoomCopyWith<$Res>? get chatRoom;@override $SnAccountCopyWith<$Res> get account;@override $SnAccountStatusCopyWith<$Res>? get status; } /// @nodoc @@ -1333,7 +1347,7 @@ class __$SnChatMemberCopyWithImpl<$Res> /// Create a copy of SnChatMember /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? id = null,Object? chatRoomId = null,Object? chatRoom = freezed,Object? accountId = null,Object? account = null,Object? nick = freezed,Object? role = null,Object? notify = null,Object? joinedAt = freezed,Object? breakUntil = freezed,Object? timeoutUntil = freezed,Object? isBot = null,Object? lastTyped = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? id = null,Object? chatRoomId = null,Object? chatRoom = freezed,Object? accountId = null,Object? account = null,Object? nick = freezed,Object? role = null,Object? notify = null,Object? joinedAt = freezed,Object? breakUntil = freezed,Object? timeoutUntil = freezed,Object? isBot = null,Object? status = freezed,Object? lastTyped = freezed,}) { return _then(_SnChatMember( createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable @@ -1350,7 +1364,8 @@ as int,joinedAt: freezed == joinedAt ? _self.joinedAt : joinedAt // ignore: cast as DateTime?,breakUntil: freezed == breakUntil ? _self.breakUntil : breakUntil // ignore: cast_nullable_to_non_nullable as DateTime?,timeoutUntil: freezed == timeoutUntil ? _self.timeoutUntil : timeoutUntil // ignore: cast_nullable_to_non_nullable as DateTime?,isBot: null == isBot ? _self.isBot : isBot // ignore: cast_nullable_to_non_nullable -as bool,lastTyped: freezed == lastTyped ? _self.lastTyped : lastTyped // ignore: cast_nullable_to_non_nullable +as bool,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable +as SnAccountStatus?,lastTyped: freezed == lastTyped ? _self.lastTyped : lastTyped // ignore: cast_nullable_to_non_nullable as DateTime?, )); } @@ -1376,6 +1391,18 @@ $SnAccountCopyWith<$Res> get account { return $SnAccountCopyWith<$Res>(_self.account, (value) { return _then(_self.copyWith(account: value)); }); +}/// Create a copy of SnChatMember +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$SnAccountStatusCopyWith<$Res>? get status { + if (_self.status == null) { + return null; + } + + return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) { + return _then(_self.copyWith(status: value)); + }); } } diff --git a/lib/models/chat.g.dart b/lib/models/chat.g.dart index 76281e28..e16bf6c7 100644 --- a/lib/models/chat.g.dart +++ b/lib/models/chat.g.dart @@ -177,6 +177,12 @@ _SnChatMember _$SnChatMemberFromJson(Map json) => ? null : DateTime.parse(json['timeout_until'] as String), isBot: json['is_bot'] as bool, + status: + json['status'] == null + ? null + : SnAccountStatus.fromJson( + json['status'] as Map, + ), lastTyped: json['last_typed'] == null ? null @@ -200,6 +206,7 @@ Map _$SnChatMemberToJson(_SnChatMember instance) => 'break_until': instance.breakUntil?.toIso8601String(), 'timeout_until': instance.timeoutUntil?.toIso8601String(), 'is_bot': instance.isBot, + 'status': instance.status?.toJson(), 'last_typed': instance.lastTyped?.toIso8601String(), }; diff --git a/lib/models/realm.dart b/lib/models/realm.dart index df24fe43..6141dbc5 100644 --- a/lib/models/realm.dart +++ b/lib/models/realm.dart @@ -40,6 +40,7 @@ sealed class SnRealmMember with _$SnRealmMember { required DateTime createdAt, required DateTime updatedAt, required DateTime? deletedAt, + required SnAccountStatus? status, }) = _SnRealmMember; factory SnRealmMember.fromJson(Map json) => diff --git a/lib/models/realm.freezed.dart b/lib/models/realm.freezed.dart index dbe41e66..cb35c235 100644 --- a/lib/models/realm.freezed.dart +++ b/lib/models/realm.freezed.dart @@ -359,7 +359,7 @@ $SnCloudFileCopyWith<$Res>? get background { /// @nodoc mixin _$SnRealmMember { - String get realmId; SnRealm? get realm; String get accountId; SnAccount? get account; int get role; DateTime? get joinedAt; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; + String get realmId; SnRealm? get realm; String get accountId; SnAccount? get account; int get role; DateTime? get joinedAt; DateTime get createdAt; DateTime get updatedAt; DateTime? get deletedAt; SnAccountStatus? get status; /// Create a copy of SnRealmMember /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -372,16 +372,16 @@ $SnRealmMemberCopyWith get copyWith => _$SnRealmMemberCopyWithImp @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is SnRealmMember&&(identical(other.realmId, realmId) || other.realmId == realmId)&&(identical(other.realm, realm) || other.realm == realm)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.role, role) || other.role == role)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is SnRealmMember&&(identical(other.realmId, realmId) || other.realmId == realmId)&&(identical(other.realm, realm) || other.realm == realm)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.role, role) || other.role == role)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)&&(identical(other.status, status) || other.status == status)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,realmId,realm,accountId,account,role,joinedAt,createdAt,updatedAt,deletedAt); +int get hashCode => Object.hash(runtimeType,realmId,realm,accountId,account,role,joinedAt,createdAt,updatedAt,deletedAt,status); @override String toString() { - return 'SnRealmMember(realmId: $realmId, realm: $realm, accountId: $accountId, account: $account, role: $role, joinedAt: $joinedAt, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; + return 'SnRealmMember(realmId: $realmId, realm: $realm, accountId: $accountId, account: $account, role: $role, joinedAt: $joinedAt, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, status: $status)'; } @@ -392,11 +392,11 @@ abstract mixin class $SnRealmMemberCopyWith<$Res> { factory $SnRealmMemberCopyWith(SnRealmMember value, $Res Function(SnRealmMember) _then) = _$SnRealmMemberCopyWithImpl; @useResult $Res call({ - String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt + String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, SnAccountStatus? status }); -$SnRealmCopyWith<$Res>? get realm;$SnAccountCopyWith<$Res>? get account; +$SnRealmCopyWith<$Res>? get realm;$SnAccountCopyWith<$Res>? get account;$SnAccountStatusCopyWith<$Res>? get status; } /// @nodoc @@ -409,7 +409,7 @@ class _$SnRealmMemberCopyWithImpl<$Res> /// Create a copy of SnRealmMember /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? realmId = null,Object? realm = freezed,Object? accountId = null,Object? account = freezed,Object? role = null,Object? joinedAt = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? realmId = null,Object? realm = freezed,Object? accountId = null,Object? account = freezed,Object? role = null,Object? joinedAt = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? status = freezed,}) { return _then(_self.copyWith( realmId: null == realmId ? _self.realmId : realmId // ignore: cast_nullable_to_non_nullable as String,realm: freezed == realm ? _self.realm : realm // ignore: cast_nullable_to_non_nullable @@ -420,7 +420,8 @@ as int,joinedAt: freezed == joinedAt ? _self.joinedAt : joinedAt // ignore: cast as DateTime?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable -as DateTime?, +as DateTime?,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable +as SnAccountStatus?, )); } /// Create a copy of SnRealmMember @@ -447,6 +448,18 @@ $SnAccountCopyWith<$Res>? get account { return $SnAccountCopyWith<$Res>(_self.account!, (value) { return _then(_self.copyWith(account: value)); }); +}/// Create a copy of SnRealmMember +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$SnAccountStatusCopyWith<$Res>? get status { + if (_self.status == null) { + return null; + } + + return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) { + return _then(_self.copyWith(status: value)); + }); } } @@ -526,10 +539,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, SnAccountStatus? status)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _SnRealmMember() when $default != null: -return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt);case _: +return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt,_that.status);case _: return orElse(); } @@ -547,10 +560,10 @@ return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.ro /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, SnAccountStatus? status) $default,) {final _that = this; switch (_that) { case _SnRealmMember(): -return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt);} +return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt,_that.status);} } /// A variant of `when` that fallback to returning `null` /// @@ -564,10 +577,10 @@ return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.ro /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, SnAccountStatus? status)? $default,) {final _that = this; switch (_that) { case _SnRealmMember() when $default != null: -return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt);case _: +return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.role,_that.joinedAt,_that.createdAt,_that.updatedAt,_that.deletedAt,_that.status);case _: return null; } @@ -579,7 +592,7 @@ return $default(_that.realmId,_that.realm,_that.accountId,_that.account,_that.ro @JsonSerializable() class _SnRealmMember implements SnRealmMember { - const _SnRealmMember({required this.realmId, required this.realm, required this.accountId, required this.account, required this.role, required this.joinedAt, required this.createdAt, required this.updatedAt, required this.deletedAt}); + const _SnRealmMember({required this.realmId, required this.realm, required this.accountId, required this.account, required this.role, required this.joinedAt, required this.createdAt, required this.updatedAt, required this.deletedAt, required this.status}); factory _SnRealmMember.fromJson(Map json) => _$SnRealmMemberFromJson(json); @override final String realmId; @@ -591,6 +604,7 @@ class _SnRealmMember implements SnRealmMember { @override final DateTime createdAt; @override final DateTime updatedAt; @override final DateTime? deletedAt; +@override final SnAccountStatus? status; /// Create a copy of SnRealmMember /// with the given fields replaced by the non-null parameter values. @@ -605,16 +619,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnRealmMember&&(identical(other.realmId, realmId) || other.realmId == realmId)&&(identical(other.realm, realm) || other.realm == realm)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.role, role) || other.role == role)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnRealmMember&&(identical(other.realmId, realmId) || other.realmId == realmId)&&(identical(other.realm, realm) || other.realm == realm)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.account, account) || other.account == account)&&(identical(other.role, role) || other.role == role)&&(identical(other.joinedAt, joinedAt) || other.joinedAt == joinedAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)&&(identical(other.status, status) || other.status == status)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,realmId,realm,accountId,account,role,joinedAt,createdAt,updatedAt,deletedAt); +int get hashCode => Object.hash(runtimeType,realmId,realm,accountId,account,role,joinedAt,createdAt,updatedAt,deletedAt,status); @override String toString() { - return 'SnRealmMember(realmId: $realmId, realm: $realm, accountId: $accountId, account: $account, role: $role, joinedAt: $joinedAt, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; + return 'SnRealmMember(realmId: $realmId, realm: $realm, accountId: $accountId, account: $account, role: $role, joinedAt: $joinedAt, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, status: $status)'; } @@ -625,11 +639,11 @@ abstract mixin class _$SnRealmMemberCopyWith<$Res> implements $SnRealmMemberCopy factory _$SnRealmMemberCopyWith(_SnRealmMember value, $Res Function(_SnRealmMember) _then) = __$SnRealmMemberCopyWithImpl; @override @useResult $Res call({ - String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt + String realmId, SnRealm? realm, String accountId, SnAccount? account, int role, DateTime? joinedAt, DateTime createdAt, DateTime updatedAt, DateTime? deletedAt, SnAccountStatus? status }); -@override $SnRealmCopyWith<$Res>? get realm;@override $SnAccountCopyWith<$Res>? get account; +@override $SnRealmCopyWith<$Res>? get realm;@override $SnAccountCopyWith<$Res>? get account;@override $SnAccountStatusCopyWith<$Res>? get status; } /// @nodoc @@ -642,7 +656,7 @@ class __$SnRealmMemberCopyWithImpl<$Res> /// Create a copy of SnRealmMember /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? realmId = null,Object? realm = freezed,Object? accountId = null,Object? account = freezed,Object? role = null,Object? joinedAt = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? realmId = null,Object? realm = freezed,Object? accountId = null,Object? account = freezed,Object? role = null,Object? joinedAt = freezed,Object? createdAt = null,Object? updatedAt = null,Object? deletedAt = freezed,Object? status = freezed,}) { return _then(_SnRealmMember( realmId: null == realmId ? _self.realmId : realmId // ignore: cast_nullable_to_non_nullable as String,realm: freezed == realm ? _self.realm : realm // ignore: cast_nullable_to_non_nullable @@ -653,7 +667,8 @@ as int,joinedAt: freezed == joinedAt ? _self.joinedAt : joinedAt // ignore: cast as DateTime?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable -as DateTime?, +as DateTime?,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable +as SnAccountStatus?, )); } @@ -681,6 +696,18 @@ $SnAccountCopyWith<$Res>? get account { return $SnAccountCopyWith<$Res>(_self.account!, (value) { return _then(_self.copyWith(account: value)); }); +}/// Create a copy of SnRealmMember +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$SnAccountStatusCopyWith<$Res>? get status { + if (_self.status == null) { + return null; + } + + return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) { + return _then(_self.copyWith(status: value)); + }); } } diff --git a/lib/models/realm.g.dart b/lib/models/realm.g.dart index 3283d375..eabc9a3d 100644 --- a/lib/models/realm.g.dart +++ b/lib/models/realm.g.dart @@ -75,6 +75,12 @@ _SnRealmMember _$SnRealmMemberFromJson(Map json) => json['deleted_at'] == null ? null : DateTime.parse(json['deleted_at'] as String), + status: + json['status'] == null + ? null + : SnAccountStatus.fromJson( + json['status'] as Map, + ), ); Map _$SnRealmMemberToJson(_SnRealmMember instance) => @@ -88,4 +94,5 @@ Map _$SnRealmMemberToJson(_SnRealmMember instance) => 'created_at': instance.createdAt.toIso8601String(), 'updated_at': instance.updatedAt.toIso8601String(), 'deleted_at': instance.deletedAt?.toIso8601String(), + 'status': instance.status?.toJson(), }; diff --git a/lib/screens/chat/room.g.dart b/lib/screens/chat/room.g.dart index 5653132d..d739d679 100644 --- a/lib/screens/chat/room.g.dart +++ b/lib/screens/chat/room.g.dart @@ -6,7 +6,7 @@ part of 'room.dart'; // RiverpodGenerator // ************************************************************************** -String _$messagesNotifierHash() => r'3740c02ab1e4dba9c8e619b63c40e2236a89b342'; +String _$messagesNotifierHash() => r'32afe6ea24086d869cc47bd3389c8fd734409ca0'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/screens/chat/room_detail.dart b/lib/screens/chat/room_detail.dart index 2694be63..3bcdd679 100644 --- a/lib/screens/chat/room_detail.dart +++ b/lib/screens/chat/room_detail.dart @@ -10,6 +10,7 @@ import 'package:island/models/chat.dart'; import 'package:island/pods/network.dart'; import 'package:island/screens/chat/chat.dart'; import 'package:island/widgets/account/account_picker.dart'; +import 'package:island/widgets/account/status.dart'; import 'package:island/widgets/alert.dart'; import 'package:island/widgets/app_scaffold.dart'; import 'package:island/widgets/content/cloud_files.dart'; @@ -544,7 +545,7 @@ class ChatMemberListNotifier extends _$ChatMemberListNotifier final apiClient = ref.watch(apiClientProvider); final response = await apiClient.get( '/sphere/chat/$roomId/members', - queryParameters: {'offset': offset, 'take': take}, + queryParameters: {'offset': offset, 'take': take, 'withStatus': true}, ); final total = int.parse(response.headers.value('X-Total') ?? '0'); @@ -672,6 +673,8 @@ class _ChatMemberListSheet extends HookConsumerWidget { spacing: 6, children: [ Flexible(child: Text(member.account.nick)), + if (member.status != null) + AccountStatusLabel(status: member.status!), if (member.joinedAt == null) const Icon(Symbols.pending_actions, size: 20), ], diff --git a/lib/screens/realm/realm_detail.dart b/lib/screens/realm/realm_detail.dart index 35cb1c42..2928b4f8 100644 --- a/lib/screens/realm/realm_detail.dart +++ b/lib/screens/realm/realm_detail.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:island/models/chat.dart'; import 'package:island/services/color.dart'; import 'package:island/services/responsive.dart'; +import 'package:island/widgets/account/status.dart'; import 'package:island/widgets/post/post_list.dart'; import 'package:palette_generator/palette_generator.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -530,7 +531,11 @@ class RealmMemberListNotifier extends _$RealmMemberListNotifier final response = await apiClient.get( '/sphere/realms/$realmSlug/members', - queryParameters: {'offset': offset, 'take': _pageSize}, + queryParameters: { + 'offset': offset, + 'take': _pageSize, + 'withStatus': true, + }, ); final total = int.parse(response.headers.value('X-Total') ?? '0'); @@ -573,7 +578,7 @@ class RealmMemberNotifier extends StateNotifier { try { final response = await _apiClient.get( '/sphere/realms/$realmSlug/members', - queryParameters: {'offset': offset, 'take': take}, + queryParameters: {'offset': offset, 'take': take, 'withStatus': true}, ); final total = int.parse(response.headers.value('X-Total') ?? '0'); @@ -640,7 +645,7 @@ class _RealmMemberListSheet extends HookConsumerWidget { } } - Widget _buildMemberListHeader() { + Widget buildMemberListHeader() { return Padding( padding: EdgeInsets.only(top: 16, left: 20, right: 16, bottom: 12), child: Row( @@ -677,7 +682,7 @@ class _RealmMemberListSheet extends HookConsumerWidget { ); } - Widget _buildMemberListContent() { + Widget buildMemberListContent() { return Expanded( child: PagingHelperView( provider: memberListProvider, @@ -701,6 +706,8 @@ class _RealmMemberListSheet extends HookConsumerWidget { spacing: 6, children: [ Flexible(child: Text(member.account!.nick)), + if (member.status != null) + AccountStatusLabel(status: member.status!), if (member.joinedAt == null) const Icon(Symbols.pending_actions, size: 20), ], @@ -783,9 +790,9 @@ class _RealmMemberListSheet extends HookConsumerWidget { ), child: Column( children: [ - _buildMemberListHeader(), + buildMemberListHeader(), const Divider(height: 1), - _buildMemberListContent(), + buildMemberListContent(), ], ), ); diff --git a/lib/widgets/account/status.dart b/lib/widgets/account/status.dart index 3de97d5b..5b649777 100644 --- a/lib/widgets/account/status.dart +++ b/lib/widgets/account/status.dart @@ -158,3 +158,42 @@ class AccountStatusWidget extends HookConsumerWidget { ).opacity((status.value?.isCustomized ?? false) ? 1 : 0.85); } } + +class AccountStatusLabel extends StatelessWidget { + final SnAccountStatus status; + final TextStyle? style; + final int maxLines; + final TextOverflow overflow; + + const AccountStatusLabel({ + super.key, + required this.status, + this.style, + this.maxLines = 1, + this.overflow = TextOverflow.ellipsis, + }); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon( + Symbols.circle, + fill: 1, + color: status.isOnline ? Colors.green : Colors.grey, + size: 14, + ).padding(right: 4), + Flexible( + child: Text( + status.label, + style: style, + maxLines: maxLines, + overflow: overflow, + ).fontSize(13), + ), + ], + ); + } +}