💥 Use quoteEventId column instead of quote_event in message body

This commit is contained in:
LittleSheep 2024-11-18 23:04:36 +08:00
parent ce414d92a2
commit 6c5377d9fa
6 changed files with 51 additions and 19 deletions

View File

@ -41,7 +41,7 @@ PODS:
- DKImagePickerController/PhotoGallery - DKImagePickerController/PhotoGallery
- Flutter - Flutter
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_native_splash (0.0.1): - flutter_native_splash (2.4.3):
- Flutter - Flutter
- flutter_secure_storage (6.0.0): - flutter_secure_storage (6.0.0):
- Flutter - Flutter
@ -123,7 +123,7 @@ SPEC CHECKSUMS:
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60 DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655 file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778 flutter_native_splash: e8a1e01082d97a8099d973f919f57904c925008a
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12 flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1 image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073 isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073

View File

@ -120,8 +120,8 @@ class ChatMessageController extends ChangeNotifier {
Future<void> _addUnconfirmedMessage(SnChatMessage message) async { Future<void> _addUnconfirmedMessage(SnChatMessage message) async {
SnChatMessage? quoteEvent; SnChatMessage? quoteEvent;
if (message.body['quote_event'] != null) { if (message.quoteEventId != null) {
quoteEvent = await getMessage(message.body['quote_event'] as int); quoteEvent = await getMessage(message.quoteEventId as int);
} }
final attachmentRid = List<String>.from( final attachmentRid = List<String>.from(
@ -142,8 +142,8 @@ class ChatMessageController extends ChangeNotifier {
Future<void> _addMessage(SnChatMessage message) async { Future<void> _addMessage(SnChatMessage message) async {
SnChatMessage? quoteEvent; SnChatMessage? quoteEvent;
if (message.body['quote_event'] != null) { if (message.quoteEventId != null) {
quoteEvent = await getMessage(message.body['quote_event'] as int); quoteEvent = await getMessage(message.quoteEventId as int);
} }
final attachmentRid = List<String>.from( final attachmentRid = List<String>.from(
@ -234,6 +234,7 @@ class ChatMessageController extends ChangeNotifier {
channelId: channel!.id, channelId: channel!.id,
sender: profile!, sender: profile!,
senderId: profile!.id, senderId: profile!.id,
quoteEventId: quoteId,
); );
_addUnconfirmedMessage(message); _addUnconfirmedMessage(message);
@ -357,8 +358,8 @@ class ChatMessageController extends ChangeNotifier {
for (var i = 0; i < out.length; i++) { for (var i = 0; i < out.length; i++) {
// Preload related events (quoted) // Preload related events (quoted)
SnChatMessage? quoteEvent; SnChatMessage? quoteEvent;
if (out[i].body['quote_event'] != null) { if (out[i].quoteEventId != null) {
quoteEvent = await getMessage(out[i].body['quote_event'] as int); quoteEvent = await getMessage(out[i].quoteEventId as int);
} }
out[i] = out[i].copyWith( out[i] = out[i].copyWith(

View File

@ -28,15 +28,15 @@ class SnNetworkProvider {
SnNetworkProvider() { SnNetworkProvider() {
client = Dio(); client = Dio();
// client.interceptors.add(RetryInterceptor( client.interceptors.add(RetryInterceptor(
// dio: client, dio: client,
// retries: 3, retries: 3,
// retryDelays: const [ retryDelays: const [
// Duration(milliseconds: 300), Duration(milliseconds: 300),
// Duration(milliseconds: 1000), Duration(milliseconds: 1000),
// Duration(milliseconds: 3000), Duration(milliseconds: 3000),
// ], ],
// )); ));
client.interceptors.add( client.interceptors.add(
InterceptorsWrapper( InterceptorsWrapper(

View File

@ -80,6 +80,7 @@ class SnChatMessage with _$SnChatMessage {
@HiveField(8) required SnChannelMember sender, @HiveField(8) required SnChannelMember sender,
@HiveField(9) required int channelId, @HiveField(9) required int channelId,
@HiveField(10) required int senderId, @HiveField(10) required int senderId,
@HiveField(11) required int? quoteEventId,
SnChatMessagePreload? preload, SnChatMessagePreload? preload,
}) = _SnChatMessage; }) = _SnChatMessage;

View File

@ -1083,6 +1083,8 @@ mixin _$SnChatMessage {
int get channelId => throw _privateConstructorUsedError; int get channelId => throw _privateConstructorUsedError;
@HiveField(10) @HiveField(10)
int get senderId => throw _privateConstructorUsedError; int get senderId => throw _privateConstructorUsedError;
@HiveField(11)
int? get quoteEventId => throw _privateConstructorUsedError;
SnChatMessagePreload? get preload => throw _privateConstructorUsedError; SnChatMessagePreload? get preload => throw _privateConstructorUsedError;
/// Serializes this SnChatMessage to a JSON map. /// Serializes this SnChatMessage to a JSON map.
@ -1113,6 +1115,7 @@ abstract class $SnChatMessageCopyWith<$Res> {
@HiveField(8) SnChannelMember sender, @HiveField(8) SnChannelMember sender,
@HiveField(9) int channelId, @HiveField(9) int channelId,
@HiveField(10) int senderId, @HiveField(10) int senderId,
@HiveField(11) int? quoteEventId,
SnChatMessagePreload? preload}); SnChatMessagePreload? preload});
$SnChannelCopyWith<$Res> get channel; $SnChannelCopyWith<$Res> get channel;
@ -1146,6 +1149,7 @@ class _$SnChatMessageCopyWithImpl<$Res, $Val extends SnChatMessage>
Object? sender = null, Object? sender = null,
Object? channelId = null, Object? channelId = null,
Object? senderId = null, Object? senderId = null,
Object? quoteEventId = freezed,
Object? preload = freezed, Object? preload = freezed,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
@ -1193,6 +1197,10 @@ class _$SnChatMessageCopyWithImpl<$Res, $Val extends SnChatMessage>
? _value.senderId ? _value.senderId
: senderId // ignore: cast_nullable_to_non_nullable : senderId // ignore: cast_nullable_to_non_nullable
as int, as int,
quoteEventId: freezed == quoteEventId
? _value.quoteEventId
: quoteEventId // ignore: cast_nullable_to_non_nullable
as int?,
preload: freezed == preload preload: freezed == preload
? _value.preload ? _value.preload
: preload // ignore: cast_nullable_to_non_nullable : preload // ignore: cast_nullable_to_non_nullable
@ -1255,6 +1263,7 @@ abstract class _$$SnChatMessageImplCopyWith<$Res>
@HiveField(8) SnChannelMember sender, @HiveField(8) SnChannelMember sender,
@HiveField(9) int channelId, @HiveField(9) int channelId,
@HiveField(10) int senderId, @HiveField(10) int senderId,
@HiveField(11) int? quoteEventId,
SnChatMessagePreload? preload}); SnChatMessagePreload? preload});
@override @override
@ -1289,6 +1298,7 @@ class __$$SnChatMessageImplCopyWithImpl<$Res>
Object? sender = null, Object? sender = null,
Object? channelId = null, Object? channelId = null,
Object? senderId = null, Object? senderId = null,
Object? quoteEventId = freezed,
Object? preload = freezed, Object? preload = freezed,
}) { }) {
return _then(_$SnChatMessageImpl( return _then(_$SnChatMessageImpl(
@ -1336,6 +1346,10 @@ class __$$SnChatMessageImplCopyWithImpl<$Res>
? _value.senderId ? _value.senderId
: senderId // ignore: cast_nullable_to_non_nullable : senderId // ignore: cast_nullable_to_non_nullable
as int, as int,
quoteEventId: freezed == quoteEventId
? _value.quoteEventId
: quoteEventId // ignore: cast_nullable_to_non_nullable
as int?,
preload: freezed == preload preload: freezed == preload
? _value.preload ? _value.preload
: preload // ignore: cast_nullable_to_non_nullable : preload // ignore: cast_nullable_to_non_nullable
@ -1360,6 +1374,7 @@ class _$SnChatMessageImpl extends _SnChatMessage {
@HiveField(8) required this.sender, @HiveField(8) required this.sender,
@HiveField(9) required this.channelId, @HiveField(9) required this.channelId,
@HiveField(10) required this.senderId, @HiveField(10) required this.senderId,
@HiveField(11) required this.quoteEventId,
this.preload}) this.preload})
: _body = body, : _body = body,
super._(); super._();
@ -1407,11 +1422,14 @@ class _$SnChatMessageImpl extends _SnChatMessage {
@HiveField(10) @HiveField(10)
final int senderId; final int senderId;
@override @override
@HiveField(11)
final int? quoteEventId;
@override
final SnChatMessagePreload? preload; final SnChatMessagePreload? preload;
@override @override
String toString() { String toString() {
return 'SnChatMessage(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, uuid: $uuid, body: $body, type: $type, channel: $channel, sender: $sender, channelId: $channelId, senderId: $senderId, preload: $preload)'; return 'SnChatMessage(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, uuid: $uuid, body: $body, type: $type, channel: $channel, sender: $sender, channelId: $channelId, senderId: $senderId, quoteEventId: $quoteEventId, preload: $preload)';
} }
@override @override
@ -1435,6 +1453,8 @@ class _$SnChatMessageImpl extends _SnChatMessage {
other.channelId == channelId) && other.channelId == channelId) &&
(identical(other.senderId, senderId) || (identical(other.senderId, senderId) ||
other.senderId == senderId) && other.senderId == senderId) &&
(identical(other.quoteEventId, quoteEventId) ||
other.quoteEventId == quoteEventId) &&
(identical(other.preload, preload) || other.preload == preload)); (identical(other.preload, preload) || other.preload == preload));
} }
@ -1453,6 +1473,7 @@ class _$SnChatMessageImpl extends _SnChatMessage {
sender, sender,
channelId, channelId,
senderId, senderId,
quoteEventId,
preload); preload);
/// Create a copy of SnChatMessage /// Create a copy of SnChatMessage
@ -1484,6 +1505,7 @@ abstract class _SnChatMessage extends SnChatMessage {
@HiveField(8) required final SnChannelMember sender, @HiveField(8) required final SnChannelMember sender,
@HiveField(9) required final int channelId, @HiveField(9) required final int channelId,
@HiveField(10) required final int senderId, @HiveField(10) required final int senderId,
@HiveField(11) required final int? quoteEventId,
final SnChatMessagePreload? preload}) = _$SnChatMessageImpl; final SnChatMessagePreload? preload}) = _$SnChatMessageImpl;
const _SnChatMessage._() : super._(); const _SnChatMessage._() : super._();
@ -1524,6 +1546,9 @@ abstract class _SnChatMessage extends SnChatMessage {
@HiveField(10) @HiveField(10)
int get senderId; int get senderId;
@override @override
@HiveField(11)
int? get quoteEventId;
@override
SnChatMessagePreload? get preload; SnChatMessagePreload? get preload;
/// Create a copy of SnChatMessage /// Create a copy of SnChatMessage

View File

@ -162,13 +162,14 @@ class SnChatMessageImplAdapter extends TypeAdapter<_$SnChatMessageImpl> {
sender: fields[8] as SnChannelMember, sender: fields[8] as SnChannelMember,
channelId: fields[9] as int, channelId: fields[9] as int,
senderId: fields[10] as int, senderId: fields[10] as int,
quoteEventId: fields[11] as int?,
); );
} }
@override @override
void write(BinaryWriter writer, _$SnChatMessageImpl obj) { void write(BinaryWriter writer, _$SnChatMessageImpl obj) {
writer writer
..writeByte(11) ..writeByte(12)
..writeByte(0) ..writeByte(0)
..write(obj.id) ..write(obj.id)
..writeByte(1) ..writeByte(1)
@ -189,6 +190,8 @@ class SnChatMessageImplAdapter extends TypeAdapter<_$SnChatMessageImpl> {
..write(obj.channelId) ..write(obj.channelId)
..writeByte(10) ..writeByte(10)
..write(obj.senderId) ..write(obj.senderId)
..writeByte(11)
..write(obj.quoteEventId)
..writeByte(5) ..writeByte(5)
..write(obj.body); ..write(obj.body);
} }
@ -309,6 +312,7 @@ _$SnChatMessageImpl _$$SnChatMessageImplFromJson(Map<String, dynamic> json) =>
sender: SnChannelMember.fromJson(json['sender'] as Map<String, dynamic>), sender: SnChannelMember.fromJson(json['sender'] as Map<String, dynamic>),
channelId: (json['channel_id'] as num).toInt(), channelId: (json['channel_id'] as num).toInt(),
senderId: (json['sender_id'] as num).toInt(), senderId: (json['sender_id'] as num).toInt(),
quoteEventId: (json['quote_event_id'] as num?)?.toInt(),
preload: json['preload'] == null preload: json['preload'] == null
? null ? null
: SnChatMessagePreload.fromJson( : SnChatMessagePreload.fromJson(
@ -328,6 +332,7 @@ Map<String, dynamic> _$$SnChatMessageImplToJson(_$SnChatMessageImpl instance) =>
'sender': instance.sender.toJson(), 'sender': instance.sender.toJson(),
'channel_id': instance.channelId, 'channel_id': instance.channelId,
'sender_id': instance.senderId, 'sender_id': instance.senderId,
'quote_event_id': instance.quoteEventId,
'preload': instance.preload?.toJson(), 'preload': instance.preload?.toJson(),
}; };