⚡ Optimize loading speed of chat
✨ Support new subscribe channel
			
			
This commit is contained in:
		
							
								
								
									
										11
									
								
								api/Nexus/Check Status.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								api/Nexus/Check Status.bru
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
meta {
 | 
			
		||||
  name: Check Status
 | 
			
		||||
  type: http
 | 
			
		||||
  seq: 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get {
 | 
			
		||||
  url: {{endpoint}}/directory/status
 | 
			
		||||
  body: none
 | 
			
		||||
  auth: none
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								api/Nexus/List Services.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								api/Nexus/List Services.bru
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
meta {
 | 
			
		||||
  name: List Services
 | 
			
		||||
  type: http
 | 
			
		||||
  seq: 2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get {
 | 
			
		||||
  url: {{endpoint}}/directory/services
 | 
			
		||||
  body: none
 | 
			
		||||
  auth: none
 | 
			
		||||
}
 | 
			
		||||
@@ -38,6 +38,7 @@ class ChatMessageController extends ChangeNotifier {
 | 
			
		||||
 | 
			
		||||
  bool isPending = true;
 | 
			
		||||
  bool isLoading = false;
 | 
			
		||||
  bool isAggressiveLoading = false;
 | 
			
		||||
 | 
			
		||||
  int? messageTotal;
 | 
			
		||||
 | 
			
		||||
@@ -320,7 +321,7 @@ class ChatMessageController extends ChangeNotifier {
 | 
			
		||||
  /// Check the local storage is up to date with the server.
 | 
			
		||||
  /// If the local storage is not up to date, it will be updated.
 | 
			
		||||
  Future<void> checkUpdate() async {
 | 
			
		||||
    isLoading = true;
 | 
			
		||||
    isAggressiveLoading = true;
 | 
			
		||||
    notifyListeners();
 | 
			
		||||
 | 
			
		||||
    final mostRecentMessage = await (_dt.db.snLocalChatMessage.select()
 | 
			
		||||
@@ -357,7 +358,7 @@ class ChatMessageController extends ChangeNotifier {
 | 
			
		||||
      rethrow;
 | 
			
		||||
    } finally {
 | 
			
		||||
      await loadMessages();
 | 
			
		||||
      isLoading = false;
 | 
			
		||||
      isAggressiveLoading = false;
 | 
			
		||||
 | 
			
		||||
      isCheckedUpdate = true;
 | 
			
		||||
      _saveMessageToLocal(incomeStrandedQueue).then((_) {
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ class WebSocketProvider extends ChangeNotifier {
 | 
			
		||||
  Future<void> connect({noRetry = false}) async {
 | 
			
		||||
    if (_connectCompleter != null) {
 | 
			
		||||
      await _connectCompleter!.future;
 | 
			
		||||
      _connectCompleter = null;
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!_ua.isAuthorized) return;
 | 
			
		||||
 
 | 
			
		||||
@@ -89,6 +89,12 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
 | 
			
		||||
      if (!mounted) return;
 | 
			
		||||
      final nty = context.read<NotificationProvider>();
 | 
			
		||||
      nty.skippableNotifyChannel = _channel!.id;
 | 
			
		||||
      final ws = context.read<WebSocketProvider>();
 | 
			
		||||
      if (_channel != null) {
 | 
			
		||||
        ws.conn?.sink.add({
 | 
			
		||||
          'channel_id': _channel?.id,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
      if (!mounted) return;
 | 
			
		||||
      context.showErrorDialog(err);
 | 
			
		||||
@@ -239,6 +245,12 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
 | 
			
		||||
    _messageController.dispose();
 | 
			
		||||
    final nty = context.read<NotificationProvider>();
 | 
			
		||||
    nty.skippableNotifyChannel = null;
 | 
			
		||||
    final ws = context.read<WebSocketProvider>();
 | 
			
		||||
    if (_channel != null) {
 | 
			
		||||
      ws.conn?.sink.add({
 | 
			
		||||
        'channel_id': _channel?.id,
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    super.dispose();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -289,7 +301,9 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
 | 
			
		||||
        builder: (context, _) {
 | 
			
		||||
          return Column(
 | 
			
		||||
            children: [
 | 
			
		||||
              LoadingIndicator(isActive: _isBusy),
 | 
			
		||||
              LoadingIndicator(
 | 
			
		||||
                isActive: _isBusy || _messageController.isAggressiveLoading,
 | 
			
		||||
              ),
 | 
			
		||||
              SingleChildScrollView(
 | 
			
		||||
                physics: const NeverScrollableScrollPhysics(),
 | 
			
		||||
                child: MaterialBanner(
 | 
			
		||||
@@ -315,8 +329,8 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
 | 
			
		||||
              if (_messageController.isPending)
 | 
			
		||||
                Expanded(
 | 
			
		||||
                  child: const CircularProgressIndicator().center(),
 | 
			
		||||
                ),
 | 
			
		||||
              if (!_messageController.isPending)
 | 
			
		||||
                )
 | 
			
		||||
              else
 | 
			
		||||
                Expanded(
 | 
			
		||||
                  child: InfiniteList(
 | 
			
		||||
                    reverse: true,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user