updateMessage method

Future<UpdateMessageResponse> updateMessage (
  1. Message message,
  2. [String cid]
)

Update the given message

Implementation

Future<UpdateMessageResponse> updateMessage(
  Message message, [
  String cid,
]) async {
  message = message.copyWith(
    status: MessageSendingStatus.UPDATING,
    updatedAt: message.updatedAt ?? DateTime.now(),
  );

  final channel = state?.channels != null ? state?.channels[cid] : null;
  channel?.state?.addMessage(message);

  return post('/messages/${message.id}', data: {'message': message})
      .then((res) {
    final updateMessageResponse = decode(
      res?.data,
      UpdateMessageResponse.fromJson,
    );

    channel?.state?.addMessage(updateMessageResponse?.message);

    return updateMessageResponse;
  }).catchError((error) {
    if (state?.channels != null) {
      channel?.state?.retryQueue?.add([message]);
    }
    throw error;
  });
}