quitTeam static method
退出群
Implementation
static Future<bool> quitTeam(String teamId) async {
var teamResult = await NimCore.instance.teamService.queryTeam(teamId);
// 讨论组的退出逻辑
//1,判断是否为讨论组,非讨论组直接退出
//2, 判断是否为创建者,非创建者直接退出
//3, 判断是否成员数大于1,如果不大于1直接解散
//4,请求成员列表,将群转给第一个成员,并退出
if (getIt<TeamProvider>().isGroupTeam(teamResult.data)) {
var team = teamResult.data;
if (team?.creator == getIt<LoginService>().userInfo?.userId) {
if ((team?.memberCount ?? 0) > 1) {
var members =
(await NimCore.instance.teamService.queryMemberList(teamId)).data;
if (members?.isNotEmpty == true) {
var newOwner = members?.firstWhere((element) =>
element.account != getIt<LoginService>().userInfo?.userId);
if (newOwner != null) {
var resTrans = await NimCore.instance.teamService
.transferTeam(teamId, newOwner.account!, true);
return resTrans.isSuccess;
}
}
} else {
var resDismiss =
await NimCore.instance.teamService.dismissTeam(teamId);
return resDismiss.isSuccess;
}
}
}
var res = await NimCore.instance.teamService.quitTeam(teamId);
return res.isSuccess;
}