diff --git a/packages/stream_chat/lib/src/api/channel.dart b/packages/stream_chat/lib/src/api/channel.dart index b9104e93..24b08b3f 100644 --- a/packages/stream_chat/lib/src/api/channel.dart +++ b/packages/stream_chat/lib/src/api/channel.dart @@ -338,18 +338,9 @@ class Channel { message = await attachmentsUploadCompleter.future; } - final response = await _client.post( - '$_channelURL/message', - data: { - 'message': message.toJson(), - }, - ); - - final res = _client.decode(response.data, SendMessageResponse.fromJson); - - state?.addMessage(res.message); - - return res; + final response = await _client.sendMessage(message, id, type); + state?.addMessage(response.message); + return response; } catch (error) { if (error is DioError && error.type != DioErrorType.RESPONSE) { state?.retryQueue?.add([message]); diff --git a/packages/stream_chat/lib/src/client.dart b/packages/stream_chat/lib/src/client.dart index 81d3bc26..5118d6b8 100644 --- a/packages/stream_chat/lib/src/client.dart +++ b/packages/stream_chat/lib/src/client.dart @@ -1246,6 +1246,16 @@ class StreamChatClient { return decode(response.data, EmptyResponse.fromJson); } + /// Sends the message to the given channel + Future sendMessage( + Message message, String channelId, String channelType) async { + final response = await post( + '/channels/$channelType/$channelId/message', + data: {'message': message}, + ); + return decode(response.data, SendMessageResponse.fromJson); + } + /// Update the given message Future updateMessage(Message message) async { final response = await post(