ChatBloc constructor
ChatBloc({})
Implementation
ChatBloc(
{required this.appId,
required this.thisMemberId,
required this.blockedMembers,
this.paged = true,
this.orderBy = 'timestamp',
this.descending = true,
this.detailed = true,
this.chatLimit = 100})
: super(ChatLoading()) {
eliudQuery = EliudQuery().withCondition(
EliudQueryCondition('readAccess', arrayContains: thisMemberId));
on<SelectChatEvent>((event, emit) {
_mapLoadChatWithDetailsToState(event.room);
});
on<OpenChatWithAMemberEvent>((event, emit) async {
var roomModel = await RoomHelper.getRoomForMembers(
appId, thisMemberId, [thisMemberId, event.otherMember]);
var otherMemberRoomInfo = await RoomHelper.getOtherMembersRoomInfo(
thisMemberId, appId, roomModel.members!);
var enhancedRoomModel =
EnhancedRoomModel(roomModel, null, otherMemberRoomInfo, null);
_mapLoadChatWithDetailsToState(enhancedRoomModel);
emit(ChatLoaded(room: enhancedRoomModel, mightHaveMore: true));
});
on<OpenChatWithMembersEvent>((event, emit) async {
var roomModel = await RoomHelper.getRoomForMembers(
appId, thisMemberId, event.members);
var otherMemberRoomInfo = await RoomHelper.getOtherMembersRoomInfo(
thisMemberId, appId, roomModel.members!);
var enhancedRoomModel =
EnhancedRoomModel(roomModel, null, otherMemberRoomInfo, null);
_mapLoadChatWithDetailsToState(enhancedRoomModel);
emit(ChatLoaded(room: enhancedRoomModel, mightHaveMore: true));
});
on<UpdateEnhancedRoomModel>((event, emit) {
var theState = state;
if (theState is ChatLoaded) {
if ((theState.room.roomModel.documentID ==
event.model.roomModel.documentID) &&
(theState.room.roomModel.appId == event.model.roomModel.appId)) {
emit(theState.withNewEnhancedRoomModel(event.model));
}
}
});
on<NewChatPage>((event, emit) {
var theState = state;
if (theState is ChatLoaded) {
pages = pages +
1; // it doesn't matter so much if we increase pages beyond the end
_mapLoadChatWithDetailsToState(theState.room);
}
});
on<AddChat>((event, emit) {
var theState = state;
if (theState is ChatLoaded) {
_mapAddChatToState(theState.room, event);
}
});
on<ChatUpdated>((event, emit) {
emit(_mapChatUpdatedToState(event));
});
on<MarkAsRead>((event, emit) {
var room = event.enhancedRoomModel;
var item = event.chat;
markAsRead(room, item);
});
}