Skip to content

Commit 0d8382b

Browse files
committed
chore: fixing
1 parent 5da49ed commit 0d8382b

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

lib/models/message_model.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ class ChatMessage {
237237

238238
static bool _sameMedia(MessageMedia? a, MessageMedia? b) {
239239
if (a == null || b == null) return a == b;
240+
241+
// 如果 bytes 都存在且相同,那么 fileHash 和 path 的变化不影响渲染
242+
// (pending→uploaded 时保持渲染一致性,避免气泡重建)
243+
final aBytes = a.bytes;
244+
final bBytes = b.bytes;
245+
if (aBytes != null && bBytes != null) {
246+
final bytesMatch = identical(aBytes, bBytes) ||
247+
_sameIntList(aBytes, bBytes);
248+
if (bytesMatch) {
249+
// bytes 相同时,只比较渲染相关字段(fileName/fileSize/mimeType/aspectRatio)
250+
return a.fileName == b.fileName &&
251+
a.fileSize == b.fileSize &&
252+
a.mimeType == b.mimeType &&
253+
a.aspectRatio == b.aspectRatio;
254+
}
255+
}
256+
257+
// bytes 不同或不存在时,比较所有字段
240258
if (a.path != b.path ||
241259
a.fileName != b.fileName ||
242260
a.fileSize != b.fileSize ||
@@ -245,8 +263,8 @@ class ChatMessage {
245263
a.fileHash != b.fileHash) {
246264
return false;
247265
}
248-
return identical(a.bytes, b.bytes) ||
249-
(a.bytes != null && b.bytes != null && _sameIntList(a.bytes!, b.bytes!));
266+
return identical(aBytes, bBytes) ||
267+
(aBytes != null && bBytes != null && _sameIntList(aBytes, bBytes));
250268
}
251269

252270
ChatMessage copyWith({

0 commit comments

Comments
 (0)