mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Handles new comments events
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
 | 
			
		||||
import 'package:comunic/models/comment.dart';
 | 
			
		||||
import 'package:event_bus/event_bus.dart';
 | 
			
		||||
 | 
			
		||||
/// Events helper
 | 
			
		||||
@@ -23,6 +24,13 @@ class NewNumberUnreadConversations {
 | 
			
		||||
  NewNumberUnreadConversations(this.newNum);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// New comment
 | 
			
		||||
class NewCommentEvent {
 | 
			
		||||
  final Comment comment;
 | 
			
		||||
 | 
			
		||||
  NewCommentEvent(this.comment);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class EventsHelper {
 | 
			
		||||
  static EventBus _mgr = EventBus();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
import 'dart:convert';
 | 
			
		||||
 | 
			
		||||
import 'package:comunic/helpers/comments_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/events_helper.dart';
 | 
			
		||||
import 'package:comunic/models/api_request.dart';
 | 
			
		||||
import 'package:comunic/models/config.dart';
 | 
			
		||||
@@ -39,8 +40,7 @@ class WebSocketHelper {
 | 
			
		||||
 | 
			
		||||
    // Determine WebSocket URI
 | 
			
		||||
    final wsURL =
 | 
			
		||||
        "${(config().apiServerSecure ? "wss" : "ws")}://${config()
 | 
			
		||||
        .apiServerName}${config().apiServerUri}ws?token=$token";
 | 
			
		||||
        "${(config().apiServerSecure ? "wss" : "ws")}://${config().apiServerName}${config().apiServerUri}ws?token=$token";
 | 
			
		||||
    final wsURI = Uri.parse(wsURL);
 | 
			
		||||
 | 
			
		||||
    // Connect
 | 
			
		||||
@@ -48,7 +48,7 @@ class WebSocketHelper {
 | 
			
		||||
 | 
			
		||||
    _ws.stream.listen(
 | 
			
		||||
      // When we got data
 | 
			
		||||
          (data) {
 | 
			
		||||
      (data) {
 | 
			
		||||
        print("WS New data: $data");
 | 
			
		||||
        _processMessage(data.toString());
 | 
			
		||||
      },
 | 
			
		||||
@@ -110,16 +110,22 @@ class WebSocketHelper {
 | 
			
		||||
  /// Process an unattended message
 | 
			
		||||
  static _processUnattendedMessage(WsMessage msg) {
 | 
			
		||||
    switch (msg.title) {
 | 
			
		||||
    // New number of notifications
 | 
			
		||||
      // New number of notifications
 | 
			
		||||
      case "number_notifs":
 | 
			
		||||
        EventsHelper.emit(NewNumberNotifsEvent(msg.data));
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    // New number of unread conversations
 | 
			
		||||
      // New number of unread conversations
 | 
			
		||||
      case "number_unread_conversations":
 | 
			
		||||
        EventsHelper.emit(NewNumberUnreadConversations(msg.data));
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      // New comment
 | 
			
		||||
      case "new_comment":
 | 
			
		||||
        EventsHelper.emit(
 | 
			
		||||
            NewCommentEvent(CommentsHelper.apiToComment(msg.data)));
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
        throw Exception("Unknown message type: ${msg.title}");
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user