初始化
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'package:hgdj/tools_base/net/base_resp_bean.dart';
|
||||
import 'package:hgdj/tools_base/net/http_manager.dart';
|
||||
|
||||
import '../../hj_page/community/group_chat/model/im_group_list_model.dart';
|
||||
import '../../hj_page/community/group_chat/model/im_message_resp.dart';
|
||||
|
||||
class GroupService {
|
||||
///获取im群组列表
|
||||
static Future<IMGroupListModel?> getList(int pageNumber,
|
||||
{int pageSize = 10}) async {
|
||||
final result = await httpManager.fetchResponseByGET('/imgroup/list',
|
||||
param: {'pageNumber': pageNumber, 'pageSize': pageSize},
|
||||
jsonTransformation: (json) => IMGroupListModel.fromJson(json));
|
||||
|
||||
return result.isSuccess ? result.data : null;
|
||||
}
|
||||
|
||||
///获取是否加入群组详情
|
||||
static Future<BaseRespBean> getHasJoin(int? groupId) async {
|
||||
return httpManager
|
||||
.fetchResponseByGET('/imgroup/hasjoin', param: {'groupId': groupId});
|
||||
}
|
||||
|
||||
///获取im消息列表
|
||||
static Future<IMMessageResp> getMessages(
|
||||
int? groupId, int pageNumber, int pageSize) async {
|
||||
final result = await httpManager.fetchResponseByGET('/immessage/list',
|
||||
param: {
|
||||
'groupId': groupId,
|
||||
'pageNumber': pageNumber,
|
||||
'pageSize': pageSize
|
||||
},
|
||||
jsonTransformation: (json) => IMMessageResp.fromJson(json));
|
||||
//返回类型非空,给不了 null:失败时这里抛,由调用方 try/catch 兜底(改可空要连调用方一起改)
|
||||
return result.data;
|
||||
}
|
||||
|
||||
///发送im消息
|
||||
static Future<BaseRespBean> sendMessage(
|
||||
int? groupId, String? content, String? image) async {
|
||||
final data = {'groupId': groupId, 'content': content, 'image': image};
|
||||
data.removeWhere((k, v) => v == null);
|
||||
return httpManager.fetchResponseByPOST('/immessage/send', param: data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user