2020-04-18 13:48:21 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-04-18 16:35:53 +02:00
|
|
|
import 'package:comunic/models/comment.dart';
|
2020-04-19 13:58:24 +02:00
|
|
|
import 'package:comunic/models/conversation_message.dart';
|
2020-04-18 13:48:21 +02:00
|
|
|
import 'package:event_bus/event_bus.dart';
|
|
|
|
|
|
|
|
/// Events helper
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
/// Main WebSocket closed
|
|
|
|
class WSClosedEvent {}
|
|
|
|
|
2020-04-18 14:14:54 +02:00
|
|
|
/// New number of notifications
|
|
|
|
class NewNumberNotifsEvent {
|
|
|
|
final int newNum;
|
|
|
|
|
|
|
|
NewNumberNotifsEvent(this.newNum);
|
|
|
|
}
|
|
|
|
|
2020-04-18 14:33:07 +02:00
|
|
|
/// New number of unread conversations
|
|
|
|
class NewNumberUnreadConversations {
|
|
|
|
final int newNum;
|
|
|
|
|
|
|
|
NewNumberUnreadConversations(this.newNum);
|
|
|
|
}
|
|
|
|
|
2020-04-18 16:35:53 +02:00
|
|
|
/// New comment
|
|
|
|
class NewCommentEvent {
|
|
|
|
final Comment comment;
|
|
|
|
|
|
|
|
NewCommentEvent(this.comment);
|
|
|
|
}
|
|
|
|
|
2020-04-18 16:46:55 +02:00
|
|
|
/// Updated comment
|
|
|
|
class UpdatedCommentEvent {
|
|
|
|
final Comment comment;
|
|
|
|
|
|
|
|
UpdatedCommentEvent(this.comment);
|
|
|
|
}
|
|
|
|
|
2020-04-18 16:57:00 +02:00
|
|
|
/// Deleted comment
|
|
|
|
class DeletedCommentEvent {
|
|
|
|
final int commentID;
|
|
|
|
|
|
|
|
DeletedCommentEvent(this.commentID);
|
|
|
|
}
|
|
|
|
|
2020-04-19 13:58:24 +02:00
|
|
|
/// New conversation message
|
|
|
|
class NewConversationMessageEvent {
|
|
|
|
final ConversationMessage msg;
|
|
|
|
|
|
|
|
NewConversationMessageEvent(this.msg);
|
|
|
|
}
|
|
|
|
|
2020-04-19 14:16:35 +02:00
|
|
|
/// Updated conversation message
|
|
|
|
class UpdatedConversationMessageEvent {
|
|
|
|
final ConversationMessage msg;
|
|
|
|
|
|
|
|
UpdatedConversationMessageEvent(this.msg);
|
|
|
|
}
|
|
|
|
|
2020-04-19 14:29:01 +02:00
|
|
|
/// Deleted conversation message
|
|
|
|
class DeletedConversationMessageEvent {
|
|
|
|
final ConversationMessage msg;
|
|
|
|
|
|
|
|
DeletedConversationMessageEvent(this.msg);
|
|
|
|
}
|
2020-04-18 16:57:00 +02:00
|
|
|
|
2020-04-18 13:48:21 +02:00
|
|
|
class EventsHelper {
|
|
|
|
static EventBus _mgr = EventBus();
|
|
|
|
|
|
|
|
/// Listen to event
|
|
|
|
///
|
|
|
|
/// Do not use this method directly. You should instead prefer to use
|
|
|
|
/// [SafeState.listen] to handle safely widgets lifecycle...
|
|
|
|
///
|
|
|
|
/// You can not register to global events
|
|
|
|
static StreamSubscription<T> on<T>(void onData(T event)) {
|
|
|
|
if (T == dynamic) throw Exception("Do not register to all events!");
|
|
|
|
|
|
|
|
final stream = _mgr.on<T>();
|
|
|
|
return stream.listen(onData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Propagate an event
|
|
|
|
static void emit<T>(T event) {
|
|
|
|
_mgr.fire(event);
|
|
|
|
}
|
|
|
|
}
|