Skip to content

Commit

Permalink
Merge pull request #155 from Kkuil/main
Browse files Browse the repository at this point in the history
fix: 修复退出群聊bug
  • Loading branch information
zongzibinbin authored Nov 13, 2023
2 parents 2bb70c4 + 1bf5ad3 commit 6876aac
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ mybatis-generator-config.xml
ChannelBizRankClient.java
ChannelBizBrandWallClient.java
/*/rebel.xml

# yml
*.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.Message;
import com.abin.mallchat.common.chat.mapper.ContactMapper;
Expand Down Expand Up @@ -96,12 +97,17 @@ public void refreshOrCreateActiveTime(Long roomId, List<Long> memberUidList, Lon
/**
* 根据房间ID删除会话
*
* @param roomId 房间ID
* @param roomId 房间ID
* @param uidList 群成员列表
* @return 是否删除成功
*/
public Boolean removeByRoomId(Long roomId) {
LambdaQueryWrapper<Contact> wrapper = new QueryWrapper<Contact>().lambda()
.eq(Contact::getRoomId, roomId);
return this.remove(wrapper);
public Boolean removeByRoomId(Long roomId, List<Long> uidList) {
if (CollectionUtil.isNotEmpty(uidList)) {
LambdaQueryWrapper<Contact> wrapper = new QueryWrapper<Contact>().lambda()
.eq(Contact::getRoomId, roomId)
.in(Contact::getUid, uidList);
return this.remove(wrapper);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.abin.mallchat.common.chat.dao;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.abin.mallchat.common.chat.domain.entity.Contact;
import com.abin.mallchat.common.chat.domain.entity.GroupMember;
Expand Down Expand Up @@ -177,12 +178,17 @@ public void revokeAdmin(Long id, List<Long> uidList) {
* 根据群组ID删除群成员
*
* @param groupId 群组ID
* @param uidList 群成员列表
* @return 是否删除成功
*/
public Boolean removeByGroupId(Long groupId) {
LambdaQueryWrapper<GroupMember> wrapper = new QueryWrapper<GroupMember>()
.lambda()
.eq(GroupMember::getGroupId, groupId);
return this.remove(wrapper);
public Boolean removeByGroupId(Long groupId, List<Long> uidList) {
if (CollectionUtil.isNotEmpty(uidList)) {
LambdaQueryWrapper<GroupMember> wrapper = new QueryWrapper<GroupMember>()
.lambda()
.eq(GroupMember::getGroupId, groupId)
.in(GroupMember::getUid, uidList);
return this.remove(wrapper);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.Message;
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
Expand All @@ -15,6 +16,7 @@
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -72,13 +74,18 @@ public Integer getUnReadCount(Long roomId, Date readTime) {
/**
* 根据房间ID逻辑删除消息
*
* @param roomId 房间ID
* @param roomId 房间ID
* @param uidList 群成员列表
* @return 是否删除成功
*/
public Boolean removeByRoomId(Long roomId) {
LambdaUpdateWrapper<Message> wrapper = new UpdateWrapper<Message>().lambda()
.eq(Message::getRoomId, roomId)
.set(Message::getStatus, MessageStatusEnum.DELETE.getStatus());
return this.update(wrapper);
public Boolean removeByRoomId(Long roomId, List<Long> uidList) {
if (CollectionUtil.isNotEmpty(uidList)) {
LambdaUpdateWrapper<Message> wrapper = new UpdateWrapper<Message>().lambda()
.eq(Message::getRoomId, roomId)
.in(Message::getFromUid, uidList)
.set(Message::getStatus, MessageStatusEnum.DELETE.getStatus());
return this.update(wrapper);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ public interface IGroupMemberService {
*/
void revokeAdmin(Long uid, AdminRevokeReq request);

/**
* 退出群聊
*
* @param uid 用户ID
* @param request 请求信息
*/
void exitGroup(Long uid, MemberExitReq request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,23 @@ public void exitGroup(Long uid, MemberExitReq request) {
boolean isDelRoom = roomDao.removeById(roomId);
AssertUtil.isTrue(isDelRoom, CommonErrorEnum.SYSTEM_ERROR);
// 4.2 删除会话
Boolean isDelContact = contactDao.removeByRoomId(roomId);
Boolean isDelContact = contactDao.removeByRoomId(roomId, Collections.EMPTY_LIST);
AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR);
// 4.3 删除群成员
Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId());
Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId(), Collections.EMPTY_LIST);
AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR);
// 4.4 删除消息记录 (逻辑删除)
Boolean isDelMessage = messageDao.removeByRoomId(roomId);
Boolean isDelMessage = messageDao.removeByRoomId(roomId, Collections.EMPTY_LIST);
AssertUtil.isTrue(isDelMessage, CommonErrorEnum.SYSTEM_ERROR);
// TODO 这里也可以告知群成员 群聊已被删除的消息
} else {
// 4.5 删除成员
groupMemberDao.removeById(uid);
// 发送移除事件告知群成员
// 4.5 删除会话
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());
WSBaseResp<WSMemberChange> ws = MemberAdapter.buildMemberRemoveWS(roomGroup.getRoomId(), uid);
pushService.sendPushMsg(ws, memberUidList);
Expand Down

0 comments on commit 6876aac

Please sign in to comment.