mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix: 修复退出群聊bug
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -72,3 +72,6 @@ mybatis-generator-config.xml
|
|||||||
ChannelBizRankClient.java
|
ChannelBizRankClient.java
|
||||||
ChannelBizBrandWallClient.java
|
ChannelBizBrandWallClient.java
|
||||||
/*/rebel.xml
|
/*/rebel.xml
|
||||||
|
|
||||||
|
# yml
|
||||||
|
*.yml
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.abin.mallchat.common.chat.dao;
|
package com.abin.mallchat.common.chat.dao;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import com.abin.mallchat.common.chat.mapper.ContactMapper;
|
import com.abin.mallchat.common.chat.mapper.ContactMapper;
|
||||||
@@ -97,11 +98,16 @@ public class ContactDao extends ServiceImpl<ContactMapper, Contact> {
|
|||||||
* 根据房间ID删除会话
|
* 根据房间ID删除会话
|
||||||
*
|
*
|
||||||
* @param roomId 房间ID
|
* @param roomId 房间ID
|
||||||
|
* @param uidList 群成员列表
|
||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
public Boolean removeByRoomId(Long roomId) {
|
public Boolean removeByRoomId(Long roomId, List<Long> uidList) {
|
||||||
|
if (CollectionUtil.isNotEmpty(uidList)) {
|
||||||
LambdaQueryWrapper<Contact> wrapper = new QueryWrapper<Contact>().lambda()
|
LambdaQueryWrapper<Contact> wrapper = new QueryWrapper<Contact>().lambda()
|
||||||
.eq(Contact::getRoomId, roomId);
|
.eq(Contact::getRoomId, roomId)
|
||||||
|
.in(Contact::getUid, uidList);
|
||||||
return this.remove(wrapper);
|
return this.remove(wrapper);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.abin.mallchat.common.chat.dao;
|
package com.abin.mallchat.common.chat.dao;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.GroupMember;
|
import com.abin.mallchat.common.chat.domain.entity.GroupMember;
|
||||||
@@ -177,12 +178,17 @@ public class GroupMemberDao extends ServiceImpl<GroupMemberMapper, GroupMember>
|
|||||||
* 根据群组ID删除群成员
|
* 根据群组ID删除群成员
|
||||||
*
|
*
|
||||||
* @param groupId 群组ID
|
* @param groupId 群组ID
|
||||||
|
* @param uidList 群成员列表
|
||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
public Boolean removeByGroupId(Long groupId) {
|
public Boolean removeByGroupId(Long groupId, List<Long> uidList) {
|
||||||
|
if (CollectionUtil.isNotEmpty(uidList)) {
|
||||||
LambdaQueryWrapper<GroupMember> wrapper = new QueryWrapper<GroupMember>()
|
LambdaQueryWrapper<GroupMember> wrapper = new QueryWrapper<GroupMember>()
|
||||||
.lambda()
|
.lambda()
|
||||||
.eq(GroupMember::getGroupId, groupId);
|
.eq(GroupMember::getGroupId, groupId)
|
||||||
|
.in(GroupMember::getUid, uidList);
|
||||||
return this.remove(wrapper);
|
return this.remove(wrapper);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.abin.mallchat.common.chat.dao;
|
package com.abin.mallchat.common.chat.dao;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
import com.abin.mallchat.common.chat.domain.entity.Contact;
|
||||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||||
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
||||||
@@ -15,6 +16,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,12 +75,17 @@ public class MessageDao extends ServiceImpl<MessageMapper, Message> {
|
|||||||
* 根据房间ID逻辑删除消息
|
* 根据房间ID逻辑删除消息
|
||||||
*
|
*
|
||||||
* @param roomId 房间ID
|
* @param roomId 房间ID
|
||||||
|
* @param uidList 群成员列表
|
||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
public Boolean removeByRoomId(Long roomId) {
|
public Boolean removeByRoomId(Long roomId, List<Long> uidList) {
|
||||||
|
if (CollectionUtil.isNotEmpty(uidList)) {
|
||||||
LambdaUpdateWrapper<Message> wrapper = new UpdateWrapper<Message>().lambda()
|
LambdaUpdateWrapper<Message> wrapper = new UpdateWrapper<Message>().lambda()
|
||||||
.eq(Message::getRoomId, roomId)
|
.eq(Message::getRoomId, roomId)
|
||||||
|
.in(Message::getFromUid, uidList)
|
||||||
.set(Message::getStatus, MessageStatusEnum.DELETE.getStatus());
|
.set(Message::getStatus, MessageStatusEnum.DELETE.getStatus());
|
||||||
return this.update(wrapper);
|
return this.update(wrapper);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,11 @@ public interface IGroupMemberService {
|
|||||||
*/
|
*/
|
||||||
void revokeAdmin(Long uid, AdminRevokeReq request);
|
void revokeAdmin(Long uid, AdminRevokeReq request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出群聊
|
||||||
|
*
|
||||||
|
* @param uid 用户ID
|
||||||
|
* @param request 请求信息
|
||||||
|
*/
|
||||||
void exitGroup(Long uid, MemberExitReq request);
|
void exitGroup(Long uid, MemberExitReq request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,19 +139,23 @@ public class GroupMemberServiceImpl implements IGroupMemberService {
|
|||||||
boolean isDelRoom = roomDao.removeById(roomId);
|
boolean isDelRoom = roomDao.removeById(roomId);
|
||||||
AssertUtil.isTrue(isDelRoom, CommonErrorEnum.SYSTEM_ERROR);
|
AssertUtil.isTrue(isDelRoom, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
// 4.2 删除会话
|
// 4.2 删除会话
|
||||||
Boolean isDelContact = contactDao.removeByRoomId(roomId);
|
Boolean isDelContact = contactDao.removeByRoomId(roomId, Collections.EMPTY_LIST);
|
||||||
AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR);
|
AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
// 4.3 删除群成员
|
// 4.3 删除群成员
|
||||||
Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId());
|
Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId(), Collections.EMPTY_LIST);
|
||||||
AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR);
|
AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
// 4.4 删除消息记录 (逻辑删除)
|
// 4.4 删除消息记录 (逻辑删除)
|
||||||
Boolean isDelMessage = messageDao.removeByRoomId(roomId);
|
Boolean isDelMessage = messageDao.removeByRoomId(roomId, Collections.EMPTY_LIST);
|
||||||
AssertUtil.isTrue(isDelMessage, CommonErrorEnum.SYSTEM_ERROR);
|
AssertUtil.isTrue(isDelMessage, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
// TODO 这里也可以告知群成员 群聊已被删除的消息
|
// TODO 这里也可以告知群成员 群聊已被删除的消息
|
||||||
} else {
|
} else {
|
||||||
// 4.5 删除成员
|
// 4.5 删除会话
|
||||||
groupMemberDao.removeById(uid);
|
Boolean isDelContact = contactDao.removeByRoomId(roomId, Collections.singletonList(uid));
|
||||||
// 发送移除事件告知群成员
|
AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
|
// 4.6 删除群成员
|
||||||
|
Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId(), Collections.singletonList(uid));
|
||||||
|
AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR);
|
||||||
|
// 4.7 发送移除事件告知群成员
|
||||||
List<Long> memberUidList = groupMemberCache.getMemberUidList(roomGroup.getRoomId());
|
List<Long> memberUidList = groupMemberCache.getMemberUidList(roomGroup.getRoomId());
|
||||||
WSBaseResp<WSMemberChange> ws = MemberAdapter.buildMemberRemoveWS(roomGroup.getRoomId(), uid);
|
WSBaseResp<WSMemberChange> ws = MemberAdapter.buildMemberRemoveWS(roomGroup.getRoomId(), uid);
|
||||||
pushService.sendPushMsg(ws, memberUidList);
|
pushService.sendPushMsg(ws, memberUidList);
|
||||||
|
|||||||
Reference in New Issue
Block a user