Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
dfe10aa3
Commit
dfe10aa3
authored
Feb 17, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
群禁言,消息改顺序推送
parent
8103d6cb
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
230 additions
and
49 deletions
+230
-49
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
+60
-2
core/src/main/java/com/wecloud/im/controller/ImConversationController.java
+14
-3
core/src/main/java/com/wecloud/im/controller/ImConversationMembersController.java
+4
-4
core/src/main/java/com/wecloud/im/friend/service/FriendEventSender.java
+2
-2
core/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
+2
-2
core/src/main/java/com/wecloud/im/mapper/ImConversationMembersMapper.java
+3
-4
core/src/main/java/com/wecloud/im/mq/MqSender.java
+15
-0
core/src/main/java/com/wecloud/im/mq/RocketMqProducerService.java
+3
-4
core/src/main/java/com/wecloud/im/param/ImConversationQueryVo.java
+7
-0
core/src/main/java/com/wecloud/im/param/ListConversationMembersParam.java
+7
-2
core/src/main/java/com/wecloud/im/service/ImConversationMembersService.java
+3
-3
core/src/main/java/com/wecloud/im/service/ImConversationService.java
+16
-0
core/src/main/java/com/wecloud/im/service/impl/ImConversationMembersServiceImpl.java
+3
-3
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+56
-15
core/src/main/java/com/wecloud/im/vo/ConversationMemberVo.java
+14
-1
core/src/main/java/com/wecloud/im/vo/ConversationVo.java
+7
-0
core/src/main/resources/mapper/ImConversationMapper.xml
+5
-3
core/src/main/resources/mapper/ImConversationMembersMapper.xml
+9
-1
No files found.
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
View file @
dfe10aa3
package
com
.
wecloud
.
im
.
action
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.google.common.collect.Lists
;
import
com.wecloud.dispatch.annotation.ActionMapping
;
import
com.wecloud.dispatch.common.BaseRequest
;
import
com.wecloud.dispatch.extend.ActionRequest
;
...
...
@@ -10,6 +11,8 @@ import com.wecloud.im.entity.ImConversationMembers;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.enums.GroupRoleEnum
;
import
com.wecloud.im.enums.MutedEnum
;
import
com.wecloud.im.mq.MqSender
;
import
com.wecloud.im.param.ChatContentVo
;
import
com.wecloud.im.param.ImClientSimpleDto
;
...
...
@@ -24,7 +27,6 @@ import com.wecloud.im.service.ImInboxService;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.sender.AsyncPush
;
import
com.wecloud.im.ws.sender.ChannelSender
;
import
com.wecloud.pushserver.client.model.constant.MqConstant
;
import
com.wecloud.pushserver.client.model.dto.PushDTO
;
...
...
@@ -35,6 +37,7 @@ import io.geekidea.springbootplus.framework.common.api.ApiResult;
import
io.netty.channel.Channel
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -42,6 +45,7 @@ import java.util.Date;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @Description 处理Cmd请求
...
...
@@ -121,6 +125,9 @@ public class NormalChatAction {
if
(
beKickOut
(
reqId
,
imClientSender
,
membersList
,
request
.
getSenderChannel
()))
{
return
;
}
if
(
muted
(
conversation
,
reqId
,
imClientSender
,
membersList
,
request
.
getSenderChannel
()))
{
return
;
}
ImMessageOnlineSend
imMessageOnlineSend
=
assembleImMessageOnlineSend
(
data
,
imClientSender
,
imApplication
.
getId
());
// 再给所有人发 todo 需要改成批量
...
...
@@ -145,7 +152,7 @@ public class NormalChatAction {
// 异步推送系统通知消息
PushDTO
pushDTO
=
mqSender
.
buildPushDto
(
data
.
getPush
(),
imClientReceiver
,
imApplication
);
mqSender
.
sendAsync
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
);
mqSender
.
orderSend
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
,
conversation
.
getId
()
);
}
// 响应发送方消息id等信息
...
...
@@ -298,6 +305,14 @@ public class NormalChatAction {
return
false
;
}
/**
* 判断被踢出逻辑
* @param reqId
* @param imClientSender
* @param membersList
* @param channel
* @return
*/
private
boolean
beKickOut
(
String
reqId
,
ImClient
imClientSender
,
List
<
ImConversationMembers
>
membersList
,
Channel
channel
)
{
Long
senderId
=
imClientSender
.
getId
();
// 判断是否被踢出
...
...
@@ -316,4 +331,47 @@ public class NormalChatAction {
}
return
false
;
}
/**
* 是否禁言判断
* @param conversation
* @param reqId
* @param imClientSender
* @param membersList
* @param channel
* @return 是-ture 否-false
*/
private
boolean
muted
(
ImConversationQueryVo
conversation
,
String
reqId
,
ImClient
imClientSender
,
List
<
ImConversationMembers
>
membersList
,
Channel
channel
)
{
Long
senderId
=
imClientSender
.
getId
();
if
(
imConversationService
.
isBelongToRole
(
imClientSender
.
getClientId
(),
conversation
.
getId
(),
Lists
.
newArrayList
(
GroupRoleEnum
.
OWNER
.
getCode
(),
GroupRoleEnum
.
ADMIN
.
getCode
())))
{
// 当前操作人属于群主或管理人员 - 不做禁言处理
return
false
;
}
boolean
result
=
false
;
if
(
MutedEnum
.
YES
.
getCode
().
equals
(
conversation
.
getMuted
()))
{
// 设置了群禁言 - 普通成员全部禁言
result
=
true
;
}
if
(
MutedEnum
.
NO
.
getCode
().
equals
(
conversation
.
getMuted
()))
{
// 未设置群禁言 判断自己是否被禁言
List
<
ImConversationMembers
>
self
=
membersList
.
stream
().
filter
(
m
->
senderId
.
equals
(
m
.
getFkClientId
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
self
)
||
MutedEnum
.
YES
.
getCode
().
equals
(
self
.
get
(
0
).
getMuted
()))
{
result
=
true
;
}
}
if
(
result
)
{
log
.
info
(
"发送方: {}, 已被禁言"
,
senderId
);
// 响应发送方
WsResponse
<
HashMap
<
String
,
Long
>>
responseModel
=
new
WsResponse
<>();
ApiResult
<
Boolean
>
apiResult
=
ApiResult
.
result
(
ApiCode
.
IS_BE_KICK_OUT
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
());
responseModel
.
setCode
(
apiResult
.
getCode
());
responseModel
.
setMsg
(
apiResult
.
getMessage
());
responseModel
.
setReqId
(
reqId
);
channelSender
.
sendMsgLocal
((
NioSocketChannel
)
channel
,
responseModel
);
}
return
result
;
}
}
core/src/main/java/com/wecloud/im/controller/ImConversationController.java
View file @
dfe10aa3
...
...
@@ -127,16 +127,27 @@ public class ImConversationController extends BaseController {
}
/**
* 群禁言
* 群禁言
、取消群禁言
*/
@PostMapping
(
"/mutedGroup"
)
@ApiOperation
(
value
=
"群禁言"
,
notes
=
"权限:群主和管理员有权限操作"
)
@ApiOperation
(
value
=
"群禁言
、取消群禁言
"
,
notes
=
"权限:群主和管理员有权限操作"
)
public
ApiResult
<
Boolean
>
mutedGroup
(
@RequestBody
@Validated
MutedGroupParam
param
)
{
Boolean
result
=
imConversationService
.
mutedGroup
(
param
);
return
ApiResult
.
ok
(
result
);
}
/**
* 选择禁言
*/
@PostMapping
(
"/mutedGroupMember"
)
@ApiOperation
(
value
=
"选择禁言"
,
notes
=
"权限:群主和管理员有权限操作"
)
public
ApiResult
<
Boolean
>
mutedGroupMember
(
@RequestBody
@Validated
MutedGroupParam
param
)
{
if
(
CollectionUtils
.
isEmpty
(
param
.
getClientIds
()))
{
return
ApiResult
.
fail
(
ApiCode
.
PARAMETER_EXCEPTION
,
null
);
}
Boolean
result
=
imConversationService
.
mutedGroupMember
(
param
);
return
ApiResult
.
ok
(
result
);
}
/**
* 查询用户加入的所有会话 与每个会话的未读条数 成员
...
...
core/src/main/java/com/wecloud/im/controller/ImConversationMembersController.java
View file @
dfe10aa3
package
com
.
wecloud
.
im
.
controller
;
import
com.wecloud.im.param.ImConvMemeClientRemarkNameParam
;
import
com.wecloud.im.param.
ImConversationMembersList
Param
;
import
com.wecloud.im.param.
ListConversationMembers
Param
;
import
com.wecloud.im.param.add.ImConversationMemAttrUpdate
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.vo.
ImConversationMemberList
Vo
;
import
com.wecloud.im.vo.
ConversationMember
Vo
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
import
io.swagger.annotations.Api
;
...
...
@@ -59,10 +59,10 @@ public class ImConversationMembersController extends BaseController {
*/
@PostMapping
(
"/getList"
)
@ApiOperation
(
value
=
"获取会话中成员表列表"
)
public
ApiResult
<
List
<
ImConversationMemberListVo
>>
getImConversationMembersList
(
@Validated
@RequestBody
ImConversationMembersListParam
imConversationMembersList
Param
)
throws
Exception
{
public
ApiResult
<
List
<
ConversationMemberVo
>>
getImConversationMembersList
(
@Validated
@RequestBody
ListConversationMembersParam
listConversationMembers
Param
)
throws
Exception
{
// Paging<ImConversationMembersQueryVo> paging = imConversationMembersService.getImConversationMembersPageList(imConversationMembersPageParam);
// return ApiResult.ok(paging);
return
ApiResult
.
ok
(
imConversationMembersService
.
getImConversationMembersList
(
imConversationMembersList
Param
));
return
ApiResult
.
ok
(
imConversationMembersService
.
getImConversationMembersList
(
listConversationMembers
Param
));
}
}
...
...
core/src/main/java/com/wecloud/im/friend/service/FriendEventSender.java
View file @
dfe10aa3
...
...
@@ -66,7 +66,7 @@ public class FriendEventSender {
pushVO
.
setTitle
(
FRIEND_APPLY_TITLE
);
pushVO
.
setSubTitle
(
FRIEND_APPLY_TITLE_SUB
);
PushDTO
pushDTO
=
mqSender
.
buildPushDto
(
pushVO
,
receiveClient
,
app
);
mqSender
.
sendAsync
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
);
mqSender
.
orderSend
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
,
1L
);
}
public
void
sendFriendApproveEventMsg
(
ImClient
claimerClient
,
ImClient
receiveClient
,
boolean
isAgree
,
String
rejectRemark
)
{
...
...
@@ -94,6 +94,6 @@ public class FriendEventSender {
pushVO
.
setTitle
(
FRIEND_APPROVE_TITLE
);
pushVO
.
setSubTitle
(
isAgree
?
FRIEND_APPROVE_TITLE_AGREE
:
FRIEND_APPROVE_TITLE_REJECT
);
PushDTO
pushDTO
=
mqSender
.
buildPushDto
(
pushVO
,
receiveClient
,
app
);
mqSender
.
sendAsync
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
);
mqSender
.
orderSend
(
MqConstant
.
Topic
.
IM_MSG_TOPIC
,
MqConstant
.
Tag
.
IM_MSG_TAG
,
pushDTO
,
1L
);
}
}
core/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
View file @
dfe10aa3
...
...
@@ -43,10 +43,10 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
/**
* 查询用户加入的所有会话 与每个会话的未读条数 成员
*
* @param clientId
* @param c
urrentC
lientId
* @return
*/
List
<
ConversationVo
>
getMyImConversationListAndMsgCount
(
@Param
(
"c
lientId"
)
Long
c
lientId
,
@Param
(
"conversationId"
)
Long
conversationId
);
List
<
ConversationVo
>
getMyImConversationListAndMsgCount
(
@Param
(
"c
urrentClientId"
)
Long
currentC
lientId
,
@Param
(
"conversationId"
)
Long
conversationId
);
/**
* 查询用户加入的所有会话
...
...
core/src/main/java/com/wecloud/im/mapper/ImConversationMembersMapper.java
View file @
dfe10aa3
...
...
@@ -5,11 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.param.ApiImConversationMembersQueryVo
;
import
com.wecloud.im.param.
ImConversationMembersList
Param
;
import
com.wecloud.im.param.
ListConversationMembers
Param
;
import
com.wecloud.im.param.ImConversationMembersPageParam
;
import
com.wecloud.im.param.ImConversationMembersQueryVo
;
import
com.wecloud.im.param.SetAdminsParam
;
import
com.wecloud.im.vo.ImConversationMemberListVo
;
import
com.wecloud.im.vo.ConversationMemberVo
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
...
...
@@ -41,7 +40,7 @@ public interface ImConversationMembersMapper extends BaseMapper<ImConversationMe
* @param param 入参
* @return
*/
List
<
ImConversationMemberListVo
>
getImConversationMembersList
(
@Param
(
"param"
)
ImConversationMembersList
Param
param
);
List
<
ConversationMemberVo
>
getImConversationMembersList
(
@Param
(
"param"
)
ListConversationMembers
Param
param
);
/**
...
...
core/src/main/java/com/wecloud/im/mq/MqSender.java
View file @
dfe10aa3
...
...
@@ -47,6 +47,7 @@ public class MqSender {
log
.
info
(
"mq同步推送topic: {} tag: {} 返回结果: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
sendResult
));
return
sendResult
;
}
/**
* mq异步推送方法
* @param topic
...
...
@@ -59,6 +60,20 @@ public class MqSender {
rocketMqProducerService
.
sendAsyncDefault
(
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
));
}
/**
* mq按顺序发送
* @param topic
* @param tag
* @param pushDTO
* @return
*/
public
SendResult
orderSend
(
String
topic
,
String
tag
,
PushDTO
pushDTO
,
Long
conversationId
)
{
log
.
info
(
"mq按顺序发送topic: {} tag: {} 推送内容: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
));
SendResult
sendResult
=
rocketMqProducerService
.
orderSend
(
topic
,
tag
,
JSON
.
toJSONString
(
pushDTO
),
conversationId
);
log
.
info
(
"mq按顺序发送topic: {} tag: {} 返回结果: {}"
,
topic
,
tag
,
JSON
.
toJSONString
(
sendResult
));
return
sendResult
;
}
public
PushDTO
buildPushDto
(
PushVO
pushVO
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
PushDTO
pushDTO
=
new
PushDTO
();
...
...
core/src/main/java/com/wecloud/im/mq/RocketMqProducerService.java
View file @
dfe10aa3
...
...
@@ -149,7 +149,7 @@ public class RocketMqProducerService implements SendCallback {
*
* @param orderId 相同的orderId 的消息会被有顺序的消费
*/
public
SendResult
orderSend
(
String
topic
,
String
tag
,
String
content
,
int
orderId
)
{
public
SendResult
orderSend
(
String
topic
,
String
tag
,
String
content
,
long
orderId
)
{
return
this
.
orderSend
(
topic
,
tag
,
""
,
content
,
orderId
);
}
...
...
@@ -158,12 +158,11 @@ public class RocketMqProducerService implements SendCallback {
* 有顺序发送
*/
public
SendResult
orderSend
(
String
topic
,
String
tag
,
String
keys
,
String
content
,
int
orderId
)
{
long
orderId
)
{
Message
msg
=
getMessage
(
topic
,
tag
,
keys
,
content
);
try
{
SendResult
sendResult
=
rocketProducer
.
send
(
msg
,
(
List
<
MessageQueue
>
mqs
,
Message
message
,
Object
arg
)
->
{
SendResult
sendResult
=
rocketProducer
.
send
(
msg
,
(
List
<
MessageQueue
>
mqs
,
Message
message
,
Object
arg
)
->
{
Integer
id
=
(
Integer
)
arg
;
int
index
=
id
%
mqs
.
size
();
return
mqs
.
get
(
index
);
...
...
core/src/main/java/com/wecloud/im/param/ImConversationQueryVo.java
View file @
dfe10aa3
...
...
@@ -54,4 +54,11 @@ public class ImConversationQueryVo implements Serializable {
@ApiModelProperty
(
"会话属性,1:单聊,2:普通群,3:万人群"
)
private
Integer
chatType
;
/**
* 禁言开关
* @see com.wecloud.im.enums.MutedEnum
*/
@ApiModelProperty
(
"禁言开关 1-未禁言 2-禁言"
)
private
Integer
muted
;
}
core/src/main/java/com/wecloud/im/param/
ImConversationMembersList
Param.java
→
core/src/main/java/com/wecloud/im/param/
ListConversationMembers
Param.java
View file @
dfe10aa3
...
...
@@ -19,12 +19,17 @@ import java.util.List;
@Data
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"ImConversationMembersListParam"
)
public
class
ImConversationMembersListParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
class
ListConversationMembersParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1445614972142934174L
;
@ApiModelProperty
(
value
=
"会话表id"
,
required
=
true
)
private
Long
conversationId
;
@ApiModelProperty
(
value
=
"角色列表 可多选,不传则查全部"
,
required
=
true
)
private
List
<
Integer
>
roles
;
@ApiModelProperty
(
value
=
"clientId列表,传了则只查询指定入参群成员"
,
required
=
true
)
private
List
<
String
>
clientIds
;
}
core/src/main/java/com/wecloud/im/service/ImConversationMembersService.java
View file @
dfe10aa3
...
...
@@ -5,12 +5,12 @@ import com.wecloud.im.entity.ImConversationMembers;
import
com.wecloud.im.param.ApiImConversationMembersPageParam
;
import
com.wecloud.im.param.ApiImConversationMembersQueryVo
;
import
com.wecloud.im.param.ImConvMemeClientRemarkNameParam
;
import
com.wecloud.im.param.
ImConversationMembersList
Param
;
import
com.wecloud.im.param.
ListConversationMembers
Param
;
import
com.wecloud.im.param.ImConversationMembersPageParam
;
import
com.wecloud.im.param.ImConversationMembersQueryVo
;
import
com.wecloud.im.param.SetAdminsParam
;
import
com.wecloud.im.param.add.ImConversationMemAttrUpdate
;
import
com.wecloud.im.vo.
ImConversationMemberList
Vo
;
import
com.wecloud.im.vo.
ConversationMember
Vo
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
...
...
@@ -46,7 +46,7 @@ public interface ImConversationMembersService extends BaseService<ImConversation
* @return
* @throws Exception
*/
List
<
ImConversationMemberListVo
>
getImConversationMembersList
(
ImConversationMembersList
Param
param
);
List
<
ConversationMemberVo
>
getImConversationMembersList
(
ListConversationMembers
Param
param
);
ApiResult
<
Boolean
>
saveOrUpdateAttr
(
ImConversationMemAttrUpdate
imConversationMemAttrUpdate
);
...
...
core/src/main/java/com/wecloud/im/service/ImConversationService.java
View file @
dfe10aa3
...
...
@@ -94,6 +94,22 @@ public interface ImConversationService extends BaseService<ImConversation> {
Boolean
mutedGroup
(
@RequestBody
MutedGroupParam
param
);
/**
* 选择禁言
* @param param
* @return
*/
Boolean
mutedGroupMember
(
@RequestBody
MutedGroupParam
param
);
/**
* 判断当前操作人是否为指定角色成员
* @param currentClientId
* @param conversationId
* @param roles
* @return
*/
Boolean
isBelongToRole
(
String
currentClientId
,
Long
conversationId
,
List
<
Integer
>
roles
);
/**
* 添加或修改会话名称
*/
ApiResult
<
Boolean
>
saveOrUpdateName
(
ImConversationNameUpdate
imConversationNameUpdate
)
throws
Exception
;
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationMembersServiceImpl.java
View file @
dfe10aa3
...
...
@@ -12,7 +12,7 @@ import com.wecloud.im.mapper.ImConversationMembersMapper;
import
com.wecloud.im.param.ApiImConversationMembersPageParam
;
import
com.wecloud.im.param.ApiImConversationMembersQueryVo
;
import
com.wecloud.im.param.ImConvMemeClientRemarkNameParam
;
import
com.wecloud.im.param.
ImConversationMembersList
Param
;
import
com.wecloud.im.param.
ListConversationMembers
Param
;
import
com.wecloud.im.param.ImConversationMembersPageParam
;
import
com.wecloud.im.param.ImConversationMembersQueryVo
;
import
com.wecloud.im.param.SetAdminsParam
;
...
...
@@ -22,7 +22,7 @@ import com.wecloud.im.service.ImClientService;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.vo.
ImConversationMemberList
Vo
;
import
com.wecloud.im.vo.
ConversationMember
Vo
;
import
com.wecloud.im.ws.sender.ChannelSender
;
import
com.wecloud.utils.JsonUtils
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
...
...
@@ -129,7 +129,7 @@ public class ImConversationMembersServiceImpl extends BaseServiceImpl<ImConversa
}
@Override
public
List
<
ImConversationMemberListVo
>
getImConversationMembersList
(
ImConversationMembersList
Param
param
)
{
public
List
<
ConversationMemberVo
>
getImConversationMembersList
(
ListConversationMembers
Param
param
)
{
return
imConversationMembersMapper
.
getImConversationMembersList
(
param
);
}
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
dfe10aa3
...
...
@@ -16,7 +16,7 @@ import com.wecloud.im.enums.ChatTypeEnum;
import
com.wecloud.im.enums.GroupRoleEnum
;
import
com.wecloud.im.mapper.ImConversationMapper
;
import
com.wecloud.im.param.ImClientSimpleDto
;
import
com.wecloud.im.param.
ImConversationMembersList
Param
;
import
com.wecloud.im.param.
ListConversationMembers
Param
;
import
com.wecloud.im.param.ImConversationPageParam
;
import
com.wecloud.im.param.ImConversationQueryParam
;
import
com.wecloud.im.param.ImConversationQueryVo
;
...
...
@@ -36,7 +36,7 @@ import com.wecloud.im.service.ImConversationService;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.vo.ConversationVo
;
import
com.wecloud.im.vo.ImConversationCreateVo
;
import
com.wecloud.im.vo.
ImConversationMemberList
Vo
;
import
com.wecloud.im.vo.
ConversationMember
Vo
;
import
com.wecloud.im.vo.OfflineMsgDto
;
import
com.wecloud.im.ws.enums.MsgTypeEnum
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
...
...
@@ -675,26 +675,67 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
public
Boolean
mutedGroup
(
MutedGroupParam
param
)
{
ImClient
currentClient
=
imClientService
.
getCurentClient
();
// 获取 群主和群成员列表
ImConversationMembersListParam
getAdminsParam
=
new
ImConversationMembersListParam
();
getAdminsParam
.
setConversationId
(
param
.
getConversationId
());
getAdminsParam
.
setRoles
(
Lists
.
newArrayList
(
GroupRoleEnum
.
OWNER
.
getCode
(),
GroupRoleEnum
.
ADMIN
.
getCode
()));
List
<
ImConversationMemberListVo
>
adminMembers
=
imConversationMembersService
.
getImConversationMembersList
(
getAdminsParam
);
if
(
CollectionUtils
.
isEmpty
(
adminMembers
))
{
throw
new
BusinessException
(
"该群未查找到管理员信息"
);
}
// 判断操作人是否为群主或管理员
List
<
ImConversationMemberListVo
>
admins
=
adminMembers
.
stream
().
filter
(
a
->
currentClient
.
getClientId
().
equals
(
a
.
getClientId
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
admins
))
{
if
(!
imConversationService
.
isBelongToRole
(
currentClient
.
getClientId
(),
param
.
getConversationId
(),
Lists
.
newArrayList
(
GroupRoleEnum
.
OWNER
.
getCode
(),
GroupRoleEnum
.
ADMIN
.
getCode
())))
{
// 当前操作人不属于群主或管理人员
throw
new
BusinessException
(
"操作人既不是群主也不是群管理员,无权限操作"
);
}
ImConversation
muteGroupParam
=
new
ImConversation
();
muteGroupParam
.
setId
(
param
.
getConversationId
());
muteGroupParam
.
setUpdateTime
(
new
Date
());
muteGroupParam
.
setMuted
(
param
.
getMutedType
());
imConversationMapper
.
updateById
(
muteGroupParam
);
return
true
;
}
@Override
public
Boolean
mutedGroupMember
(
MutedGroupParam
param
)
{
ImClient
currentClient
=
imClientService
.
getCurentClient
();
if
(!
imConversationService
.
isBelongToRole
(
currentClient
.
getClientId
(),
param
.
getConversationId
(),
Lists
.
newArrayList
(
GroupRoleEnum
.
OWNER
.
getCode
(),
GroupRoleEnum
.
ADMIN
.
getCode
())))
{
// 当前操作人不属于群主或管理人员
throw
new
BusinessException
(
"操作人既不是群主也不是群管理员,无权限操作"
);
}
ListConversationMembersParam
getMutedMemberParam
=
new
ListConversationMembersParam
();
getMutedMemberParam
.
setConversationId
(
param
.
getConversationId
());
getMutedMemberParam
.
setClientIds
(
param
.
getClientIds
());
List
<
ConversationMemberVo
>
mutedMembers
=
imConversationMembersService
.
getImConversationMembersList
(
getMutedMemberParam
);
List
<
ImConversationMembers
>
mutedMemberList
=
Lists
.
newArrayList
();
for
(
ConversationMemberVo
mutedMember
:
mutedMembers
)
{
ImConversationMembers
saveMutedMember
=
new
ImConversationMembers
();
saveMutedMember
.
setId
(
mutedMember
.
getId
());
saveMutedMember
.
setUpdateTime
(
new
Date
());
saveMutedMember
.
setMuted
(
param
.
getMutedType
());
mutedMemberList
.
add
(
saveMutedMember
);
}
imConversationMembersService
.
updateBatchById
(
mutedMemberList
);
return
true
;
}
/**
* 判断当前操作人是否为指定角色成员
* @param currentClientId
* @param conversationId
* @return
*/
@Override
public
Boolean
isBelongToRole
(
String
currentClientId
,
Long
conversationId
,
List
<
Integer
>
roles
)
{
// 获取 群主和群管理员列表
ListConversationMembersParam
getMemberParam
=
new
ListConversationMembersParam
();
getMemberParam
.
setConversationId
(
conversationId
);
getMemberParam
.
setRoles
(
roles
);
List
<
ConversationMemberVo
>
members
=
imConversationMembersService
.
getImConversationMembersList
(
getMemberParam
);
if
(
CollectionUtils
.
isEmpty
(
members
))
{
return
false
;
}
for
(
ConversationMemberVo
member
:
members
)
{
if
(
currentClientId
.
equals
(
member
.
getClientId
()))
{
return
true
;
}
}
return
false
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
...
@@ -914,10 +955,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
public
List
<
ConversationVo
>
getMyImConversationListAndMsgCount
()
throws
Exception
{
ImClient
client
=
imClientService
.
getCurentClient
();
ImClient
c
urrentC
lient
=
imClientService
.
getCurentClient
();
// 查询用户加入的所有会话 与每个会话的未读条数 成员
List
<
ConversationVo
>
myImConversationListAndMsgCount
=
imConversationMapper
.
getMyImConversationListAndMsgCount
(
client
.
getId
(),
null
);
List
<
ConversationVo
>
myImConversationListAndMsgCount
=
imConversationMapper
.
getMyImConversationListAndMsgCount
(
c
urrentC
lient
.
getId
(),
null
);
// 返回的
List
<
ConversationVo
>
myImConversationListAndMsgCountNew
=
new
ArrayList
<>();
...
...
core/src/main/java/com/wecloud/im/vo/
ImConversationMemberList
Vo.java
→
core/src/main/java/com/wecloud/im/vo/
ConversationMember
Vo.java
View file @
dfe10aa3
...
...
@@ -10,7 +10,12 @@ import java.io.Serializable;
@Data
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"ImConversationMemberListVo"
)
public
class
ImConversationMemberListVo
implements
Serializable
{
public
class
ConversationMemberVo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
7278014943001080361L
;
@ApiModelProperty
(
"主键id"
)
private
Long
id
;
@ApiModelProperty
(
"会话中client的备注名"
)
private
String
clientRemarkName
;
...
...
@@ -31,4 +36,12 @@ public class ImConversationMemberListVo implements Serializable {
*/
@ApiModelProperty
(
"群内角色"
)
private
Integer
role
;
/**
* 禁言开关
* @see com.wecloud.im.enums.MutedEnum
*/
@ApiModelProperty
(
"禁言开关 1-未禁言 2-禁言"
)
private
Integer
muted
;
}
core/src/main/java/com/wecloud/im/vo/ConversationVo.java
View file @
dfe10aa3
...
...
@@ -61,4 +61,11 @@ public class ConversationVo implements Serializable {
@ApiModelProperty
(
"会话最后一条消息"
)
private
OfflineMsgDto
lastMsg
;
/**
* 禁言开关
* @see com.wecloud.im.enums.MutedEnum
*/
@ApiModelProperty
(
"禁言开关 1-未禁言 2-禁言"
)
private
Integer
muted
;
}
core/src/main/resources/mapper/ImConversationMapper.xml
View file @
dfe10aa3
...
...
@@ -5,7 +5,7 @@
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
id
, create_time, update_time, last_message, member_count, chat_type, fk_appid, creator, name, attributes, system_flag
, create_time, update_time, last_message, member_count, chat_type, fk_appid, creator, name, attributes, system_flag
,muted
</sql>
<select
id=
"getImConversationById"
resultType=
"com.wecloud.im.param.ImConversationQueryVo"
>
...
...
@@ -20,6 +20,7 @@
<include
refid=
"Base_Column_List"
/>
from im_conversation
</select>
<select
id=
"getMyImConversationListAndMsgCount"
resultType=
"com.wecloud.im.vo.ConversationVo"
>
SELECT imConversation.id,
imConversation.create_time,
...
...
@@ -28,11 +29,12 @@
imConversation.member_count,
imConversation.attributes as attribute,
imConversation.system_flag,
imConversation.muted as muted,
im_client.client_id AS creator,
(SELECT COUNT(im_inbox.id)
FROM im_inbox
WHERE im_inbox.fk_conversation_id = imConversation.id
AND im_inbox.receiver = #{clientId}
AND im_inbox.receiver = #{c
urrentC
lientId}
AND im_inbox.read_msg_status = 0) AS msg_not_read_count,
(
SELECT GROUP_CONCAT(im_client.client_id)
...
...
@@ -44,7 +46,7 @@
INNER JOIN im_conversation AS imConversation
ON imConversation.id = imConversationMembers.fk_conversation_id
INNER JOIN im_client AS im_client ON im_client.id = imConversation.creator
WHERE imConversationMembers.fk_client_id = #{clientId}
WHERE imConversationMembers.fk_client_id = #{c
urrentC
lientId}
AND imConversationMembers.display_status = 1
<if
test=
"conversationId != null"
>
AND imConversation.id = #{conversationId}
...
...
core/src/main/resources/mapper/ImConversationMembersMapper.xml
View file @
dfe10aa3
...
...
@@ -29,14 +29,16 @@
WHERE fk_conversation_id = #{conversationId}
</select>
<select
id=
"getImConversationMembersList"
resultType=
"com.wecloud.im.vo.
ImConversationMemberList
Vo"
>
<select
id=
"getImConversationMembersList"
resultType=
"com.wecloud.im.vo.
ConversationMember
Vo"
>
SELECT im_client.client_id as clientId,
im_conversation_members.id as id,
im_conversation_members.client_remark_name as clientRemarkName,
im_client.head_portrait as headPortrait,
im_client.nickname,
im_conversation_members.attributes AS memberAttributes,
im_conversation_members.role AS role,
im_conversation_members.muted AS muted,
im_client.attributes AS clientAttributes
FROM im_conversation_members AS im_conversation_members
INNER JOIN im_client AS im_client ON im_client.id = im_conversation_members.fk_client_id
...
...
@@ -47,6 +49,12 @@
#{role}
</foreach>
</if>
<if
test=
"param.clientIds != null and param.clientIds.size() > 0"
>
and im_client.client_id in
<foreach
collection=
"param.clientIds"
item=
"clientId"
index=
"index"
open=
"("
close=
")"
separator=
","
>
#{clientId}
</foreach>
</if>
</select>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment