diff --git a/im-platform/src/main/java/com/lx/implatform/controller/GroupController.java b/im-platform/src/main/java/com/lx/implatform/controller/GroupController.java index f1e6015..bb61baf 100644 --- a/im-platform/src/main/java/com/lx/implatform/controller/GroupController.java +++ b/im-platform/src/main/java/com/lx/implatform/controller/GroupController.java @@ -79,5 +79,13 @@ public class GroupController { return ResultUtils.success(); } + @ApiOperation(value = "踢出群聊",notes="将用户踢出群聊") + @DeleteMapping("/kick/{groupId}") + public Result kickGroup(@NotNull(message = "群聊id不能为空") @PathVariable Long groupId, + @NotNull(message = "用户id不能为空") @RequestParam Long userId){ + groupService.kickGroup(groupId,userId); + return ResultUtils.success(); + } + } diff --git a/im-platform/src/main/java/com/lx/implatform/service/IGroupService.java b/im-platform/src/main/java/com/lx/implatform/service/IGroupService.java index 9fb1a77..895870f 100644 --- a/im-platform/src/main/java/com/lx/implatform/service/IGroupService.java +++ b/im-platform/src/main/java/com/lx/implatform/service/IGroupService.java @@ -27,6 +27,8 @@ public interface IGroupService extends IService { void quitGroup(Long groupId); + void kickGroup(Long groupId,Long userId); + List findGroups(); void invite(GroupInviteVO vo); diff --git a/im-platform/src/main/java/com/lx/implatform/service/impl/GroupMessageServiceImpl.java b/im-platform/src/main/java/com/lx/implatform/service/impl/GroupMessageServiceImpl.java index 5e4284d..99e0147 100644 --- a/im-platform/src/main/java/com/lx/implatform/service/impl/GroupMessageServiceImpl.java +++ b/im-platform/src/main/java/com/lx/implatform/service/impl/GroupMessageServiceImpl.java @@ -65,10 +65,7 @@ public class GroupMessageServiceImpl extends ServiceImpl{ - if(id == userId){ - // 自己不需要推送给自己 - return; - } + String key = RedisKey.IM_USER_SERVER_ID + id; Integer serverId = (Integer)redisTemplate.opsForValue().get(key); if(serverId != null){ diff --git a/im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java b/im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java index e930c6c..f4f1eeb 100644 --- a/im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java +++ b/im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java @@ -23,14 +23,11 @@ import com.lx.implatform.vo.GroupMemberVO; import com.lx.implatform.vo.GroupVO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.cache.CacheProperties; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - -import java.lang.reflect.Member; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -80,6 +77,7 @@ public class GroupServiceImpl extends ServiceImpl implements return vo; } + /** * 修改群聊信息 * @@ -109,6 +107,7 @@ public class GroupServiceImpl extends ServiceImpl implements return vo; } + /** * 删除群聊 * @@ -121,9 +120,6 @@ public class GroupServiceImpl extends ServiceImpl implements public void deleteGroup(Long groupId) { UserSession session = SessionContext.getSession(); Group group = this.getById(groupId); - if(group == null){ - throw new GlobalException(ResultCode.PROGRAM_ERROR,"群组不存在"); - } if(group.getOwnerId() != session.getId()){ throw new GlobalException(ResultCode.PROGRAM_ERROR,"只有群主才有权限解除群聊"); } @@ -134,7 +130,7 @@ public class GroupServiceImpl extends ServiceImpl implements /** - *退出群聊 + * 退出群聊 * * @param groupId 群聊id * @return @@ -143,9 +139,6 @@ public class GroupServiceImpl extends ServiceImpl implements public void quitGroup(Long groupId) { UserSession session = SessionContext.getSession(); Group group = this.getById(groupId); - if(group == null){ - throw new GlobalException(ResultCode.PROGRAM_ERROR,"群组不存在"); - } if(group.getOwnerId() == session.getId()){ throw new GlobalException(ResultCode.PROGRAM_ERROR,"您是群主,不可退出群聊"); } @@ -154,13 +147,31 @@ public class GroupServiceImpl extends ServiceImpl implements } + /** + * 将用户踢出群聊 + * + * @param groupId 群聊id + * @param userId 用户id + * @return + */ @Override - public GroupVO findById(Long groupId) { + public void kickGroup(Long groupId, Long userId) { UserSession session = SessionContext.getSession(); - Group group = super.getById(groupId); - if(group == null){ - throw new GlobalException(ResultCode.PROGRAM_ERROR,"群聊不存在"); + Group group = this.getById(groupId); + if(group.getOwnerId() != session.getId()){ + throw new GlobalException(ResultCode.PROGRAM_ERROR,"您不是群主,没有权限踢人"); } + if(userId == session.getId()){ + throw new GlobalException(ResultCode.PROGRAM_ERROR,"亲,不能自己踢自己哟"); + } + // 删除群聊成员 + groupMemberService.removeByGroupAndUserId(groupId,userId); + } + + @Override + public GroupVO findById(Long groupId) { + UserSession session = SessionContext.getSession(); + Group group = this.getById(groupId); GroupMember member = groupMemberService.findByGroupAndUserId(groupId,session.getId()); if(member == null){ throw new GlobalException(ResultCode.PROGRAM_ERROR,"您未加入群聊"); @@ -172,7 +183,7 @@ public class GroupServiceImpl extends ServiceImpl implements } /** - *根据id查找群聊,并进行缓存 + * 根据id查找群聊,并进行缓存 * * @param groupId 群聊id * @return @@ -180,7 +191,14 @@ public class GroupServiceImpl extends ServiceImpl implements @Cacheable(value = "#groupId") @Override public Group GetById(Long groupId){ - return super.getById(groupId); + Group group = super.getById(groupId); + if(group == null){ + throw new GlobalException(ResultCode.PROGRAM_ERROR,"群组不存在"); + } + if(group.getDeleted()){ + throw new GlobalException(ResultCode.PROGRAM_ERROR,"群组已解散"); + } + return group; } @@ -275,5 +293,4 @@ public class GroupServiceImpl extends ServiceImpl implements return vos; } - } diff --git a/im-server/src/main/java/com/lx/implatform/imserver/websocket/processor/GroupMessageProcessor.java b/im-server/src/main/java/com/lx/implatform/imserver/websocket/processor/GroupMessageProcessor.java index b331501..ed429b1 100644 --- a/im-server/src/main/java/com/lx/implatform/imserver/websocket/processor/GroupMessageProcessor.java +++ b/im-server/src/main/java/com/lx/implatform/imserver/websocket/processor/GroupMessageProcessor.java @@ -31,11 +31,14 @@ public class GroupMessageProcessor extends MessageProcessor { for(Long recvId:recvIds){ ChannelHandlerContext channelCtx = WebsocketChannelCtxHloder.getChannelCtx(recvId); if(channelCtx != null){ - // 推送消息到用户 - SendInfo sendInfo = new SendInfo(); - sendInfo.setCmd(WSCmdEnum.GROUP_MESSAGE.getCode()); - sendInfo.setData(data); - channelCtx.channel().writeAndFlush(sendInfo); + // 自己发的消息不用推送 + if(recvId != data.getSendId()){ + // 推送消息到用户 + SendInfo sendInfo = new SendInfo(); + sendInfo.setCmd(WSCmdEnum.GROUP_MESSAGE.getCode()); + sendInfo.setData(data); + channelCtx.channel().writeAndFlush(sendInfo); + } // 设置已读最大id String key = RedisKey.IM_GROUP_READED_POSITION + data.getGroupId()+":"+recvId; redisTemplate.opsForValue().set(key,data.getId()); diff --git a/im-ui/src/components/chat/ChatGroup.vue b/im-ui/src/components/chat/ChatGroup.vue index 56ff9eb..1cbeba7 100644 --- a/im-ui/src/components/chat/ChatGroup.vue +++ b/im-ui/src/components/chat/ChatGroup.vue @@ -250,16 +250,10 @@ } }, - watch: { - 'chat.targetId': { - handler: function(newGroupId, oldGroupId) { - this.loadGroup(newGroupId); - }, - immediate: true - } - }, mounted() { - // this.loadGroup(this.chat.targetId); + console.log("group mount...") + this.loadGroup(this.chat.targetId); + this.scrollToBottom(); } } diff --git a/im-ui/src/components/chat/ChatPrivate.vue b/im-ui/src/components/chat/ChatPrivate.vue index afe83cd..d49f246 100644 --- a/im-ui/src/components/chat/ChatPrivate.vue +++ b/im-ui/src/components/chat/ChatPrivate.vue @@ -215,7 +215,8 @@ } }, mounted() { - console.log(this.chat); + console.log("private mount...") + this.scrollToBottom(); } } diff --git a/im-ui/src/components/common/HeadImage.vue b/im-ui/src/components/common/HeadImage.vue index 1e15465..dcfd1a0 100644 --- a/im-ui/src/components/common/HeadImage.vue +++ b/im-ui/src/components/common/HeadImage.vue @@ -1,23 +1,23 @@ \ No newline at end of file + } + diff --git a/im-ui/src/components/friend/AddFriend.vue b/im-ui/src/components/friend/AddFriend.vue index 007f4a5..65ce74a 100644 --- a/im-ui/src/components/friend/AddFriend.vue +++ b/im-ui/src/components/friend/AddFriend.vue @@ -1,6 +1,6 @@