[LLC -> Channel] Segregate sendMessage api call and state handling
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -338,18 +338,9 @@ class Channel {
|
|||||||
message = await attachmentsUploadCompleter.future;
|
message = await attachmentsUploadCompleter.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await _client.post(
|
final response = await _client.sendMessage(message, id, type);
|
||||||
'$_channelURL/message',
|
state?.addMessage(response.message);
|
||||||
data: {
|
return response;
|
||||||
'message': message.toJson(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
final res = _client.decode(response.data, SendMessageResponse.fromJson);
|
|
||||||
|
|
||||||
state?.addMessage(res.message);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error is DioError && error.type != DioErrorType.RESPONSE) {
|
if (error is DioError && error.type != DioErrorType.RESPONSE) {
|
||||||
state?.retryQueue?.add([message]);
|
state?.retryQueue?.add([message]);
|
||||||
|
|||||||
@@ -1246,6 +1246,16 @@ class StreamChatClient {
|
|||||||
return decode(response.data, EmptyResponse.fromJson);
|
return decode(response.data, EmptyResponse.fromJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sends the message to the given channel
|
||||||
|
Future<SendMessageResponse> 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
|
/// Update the given message
|
||||||
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
||||||
final response = await post(
|
final response = await post(
|
||||||
|
|||||||
Reference in New Issue
Block a user