forked from eatvio/eatvio_app
feat(chat): add chat lazy loading, send message and websocket init for notifications and new chat messages
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -11,10 +13,22 @@ abstract class ChatService {
|
||||
factory ChatService(Dio dio, {String baseUrl}) = _ChatService;
|
||||
|
||||
@GET('/chat/show/{id}')
|
||||
Future<Map<String, ChatRoomModel>> getChatRoom(@Path() String id);
|
||||
Future<Map<String, ChatRoomModel>> getChatRoom({
|
||||
@Path() required String id,
|
||||
});
|
||||
|
||||
@POST('/chat/{id}/message/send')
|
||||
Future<void> sendMessage({
|
||||
@Path() required String id,
|
||||
@Part() String? data,
|
||||
@Part() List<File>? filesList,
|
||||
});
|
||||
|
||||
@GET('/chat/show/{id}/messages?page={page}')
|
||||
Future<ChatMessagesModel> getChatMessages(@Path() String id, @Path() int page);
|
||||
Future<ChatMessagesModel> getChatMessages({
|
||||
@Path() required String id,
|
||||
@Path() required int page,
|
||||
});
|
||||
|
||||
@GET('/profile/ws/params')
|
||||
Future<WebsocketInfoModel> getWebsocket();
|
||||
|
||||
@@ -19,7 +19,7 @@ class _ChatService implements ChatService {
|
||||
String? baseUrl;
|
||||
|
||||
@override
|
||||
Future<Map<String, ChatRoomModel>> getChatRoom(String id) async {
|
||||
Future<Map<String, ChatRoomModel>> getChatRoom({required String id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
@@ -47,10 +47,53 @@ class _ChatService implements ChatService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChatMessagesModel> getChatMessages(
|
||||
String id,
|
||||
int page,
|
||||
) async {
|
||||
Future<void> sendMessage({
|
||||
required String id,
|
||||
String? data,
|
||||
List<File>? filesList,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = FormData();
|
||||
if (data != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'data',
|
||||
data,
|
||||
));
|
||||
}
|
||||
if (filesList != null) {
|
||||
_data.files.addAll(filesList.map((i) => MapEntry(
|
||||
'filesList',
|
||||
MultipartFile.fromFileSync(
|
||||
i.path,
|
||||
filename: i.path.split(Platform.pathSeparator).last,
|
||||
))));
|
||||
}
|
||||
await _dio.fetch<void>(_setStreamType<void>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/chat/${id}/message/send',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChatMessagesModel> getChatMessages({
|
||||
required String id,
|
||||
required int page,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
|
||||
Reference in New Issue
Block a user