💥 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
- Flutter
- Flutter (1.0.0)
- flutter_native_splash (0.0.1):
- flutter_native_splash (2.4.3):
- Flutter
- flutter_secure_storage (6.0.0):
- Flutter
@ -123,7 +123,7 @@ SPEC CHECKSUMS:
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778
flutter_native_splash: e8a1e01082d97a8099d973f919f57904c925008a
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073

View File

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

View File

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

View File

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

View File

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

View File

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