💄 Optimize (idk what i did)

This commit is contained in:
2025-02-23 00:50:37 +08:00
parent 0bf614a75c
commit 2188b8b2e2
20 changed files with 325 additions and 687 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:math' as math;
import 'package:dio/dio.dart';
@ -499,9 +500,38 @@ class ChatMessageController extends ChangeNotifier {
}
}
Timer? _readEventDebounce;
int? _readEventAnchor;
void readEvent(int id) {
if (_readEventAnchor != null) {
_readEventAnchor = math.max(_readEventAnchor!, id);
} else {
_readEventAnchor = id;
}
if (_readEventDebounce?.isActive ?? false) {
_readEventDebounce?.cancel();
}
_readEventDebounce = Timer(const Duration(milliseconds: 500), () {
_ws.conn?.sink.add(jsonEncode(
WebSocketPackage(
method: 'events.read',
endpoint: 'im',
payload: {
'channel_member_id': profile!.id,
'event_id': _readEventAnchor,
},
).toJson(),
));
log('[Messaging] Send read event request: $_readEventAnchor');
});
}
@override
void dispose() {
_wsSubscription?.cancel();
_readEventDebounce?.cancel();
super.dispose();
}
}