startLoading method

void startLoading()

Mark messages as seen, need to provide a roomId and a list of messageIds React to a message with a reactionBody Currently one user can react once, so if the user already reacted to a message the reaction will be removed instead If the user did not react to the message yet, the reaction will be added Private method to add a reaction to a message Dispatches loading state, helpful for displaying loading indicator

Implementation

// Future<MessageSeen?> markMessagesAsSeen({
//   required int roomId,
//   required List<String> messageIds,
// }) async {
//   final result = (await _chatApi.chatRoomsMessagesSeenCreate(
//     roomPk: roomId,
//     messageSeenRequest: MessageSeenRequest(messageIds: messageIds),
//   ))
//       .data;

//   return result;
// }

/// React to a message with a [reactionBody]
/// Currently one user can react once, so if the user already reacted to a message
/// the reaction will be removed instead
/// If the user did not react to the message yet, the reaction will be added
// Future<void> reactToAMessage({
//   /// The reaction body, e.g. 'like emoji'
//   required String reactionBody,

//   /// The message id to react to
//   required String messageId,

//   /// The reaction metadata, e.g. `{ 'like emoji': 1 }`
//   required Map<String, int> reactionMetadata,
// }) async {
//   if (reactionMetadata.containsKey(reactionBody)) {
//     final message = (await _chatApi.chatRoomsMessagesRetrieve(
//       id: messageId,
//       roomPk: state.roomId,
//     ))
//         .data;

//     final messageCurrentReactions = message?.reactions ?? [];
//     final existingReaction = (messageCurrentReactions.firstWhereOrNull(
//       (element) => element.body == reactionBody && element.isMe == true,
//     ));
//     if (existingReaction != null) {
//       if (existingReaction.id != null) {
//         await _removeReaction(messageId: existingReaction.id!);
//       } else {
//         throw Exception('Could not find message id for reaction');
//       }
//     } else {
//       await _addReaction(
//         messageId: messageId,
//         reactionBody: reactionBody,
//       );
//     }
//   } else {
//     await _addReaction(
//       messageId: messageId,
//       reactionBody: reactionBody,
//     );
//   }
// }

/// Private method to add a reaction to a message
// Future<void> _addReaction({
//   required String messageId,
//   required String reactionBody,
// }) async {
//   await _chatApi.chatRoomsMessagesCreate(
//     roomPk: state.roomId,
//     messageRequest: MessageRequest(
//       body: reactionBody,
//       isReaction: true,
//       parentId: messageId,
//     ),
//   );
// }

// /// Private method to remove a reaction from a message
// Future<void> _removeReaction({required String messageId}) async {
//   await _chatApi.chatRoomsMessagesDestroy(
//     roomPk: state.roomId,
//     id: messageId,
//   );
// }

/// Dispatches loading state, helpful for displaying loading indicator
void startLoading() => emit(state.copyWith(loading: true));