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
35335d3a
Commit
35335d3a
authored
Sep 27, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消息已读修改调整
parent
1859e55a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
234 deletions
+8
-234
core/src/main/java/com/wecloud/im/service/ImInboxService.java
+0
-46
core/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
+8
-188
No files found.
core/src/main/java/com/wecloud/im/service/ImInboxService.java
View file @
35335d3a
...
@@ -15,52 +15,6 @@ import io.geekidea.springbootplus.framework.common.service.BaseService;
...
@@ -15,52 +15,6 @@ import io.geekidea.springbootplus.framework.common.service.BaseService;
*/
*/
public
interface
ImInboxService
extends
BaseService
<
ImInbox
>
{
public
interface
ImInboxService
extends
BaseService
<
ImInbox
>
{
// /**
// * 保存
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean saveImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 修改
// *
// * @param imInbox
// * @return
// * @throws Exception
// */
// boolean updateImInbox(ImInbox imInbox) throws Exception;
//
// /**
// * 删除
// *
// * @param id
// * @return
// * @throws Exception
// */
// boolean deleteImInbox(Long id) throws Exception;
//
// /**
// * 根据ID获取查询对象
// *
// * @param id
// * @return
// * @throws Exception
// */
// ImInboxQueryVo getImInboxById(Long id) throws Exception;
//
// /**
// * 获取分页对象
// *
// * @param imInboxPageParam
// * @return
// * @throws Exception
// */
// Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception;
/**
/**
* 消息修改为已接收状态
* 消息修改为已接收状态
*
*
...
...
core/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
View file @
35335d3a
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.google.common.collect.Maps
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.mapper.ImInboxMapper
;
import
com.wecloud.im.mapper.ImInboxMapper
;
import
com.wecloud.im.param.ImMsgReceivedStatusUpdate
;
import
com.wecloud.im.param.ImMsgReceivedStatusUpdate
;
import
com.wecloud.im.param.MsgReadStatusUpdateParam
;
import
com.wecloud.im.param.MsgReadStatusUpdateParam
;
import
com.wecloud.im.param.UpdateMsgReadStatusByConversationParam
;
import
com.wecloud.im.param.UpdateMsgReadStatusByConversationParam
;
import
com.wecloud.im.sdk.enums.ReadMsgStatusEnum
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImMessageService
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
com.wecloud.im.ws.enums.MsgTypeEnum
;
import
lombok.extern.slf4j.Slf4j
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.wecloud.im.ws.model.WsRespons
e
;
import
org.springframework.stereotype.Servic
e
;
import
com.wecloud.im.ws.sender.ChannelSender
;
import
org.springframework.transaction.annotation.Transactional
;
/**
/**
* 消息收件箱表 服务实现类
* 消息收件箱表 服务实现类
...
@@ -54,73 +30,10 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
...
@@ -54,73 +30,10 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Autowired
@Autowired
private
ImClientService
imClientService
;
private
ImClientService
imClientService
;
@Autowired
private
ImMessageService
imMessageService
;
@Autowired
private
ImConversationMembersService
imConversationMembersService
;
@Autowired
private
ChannelSender
channelSender
;
@Autowired
private
ImApplicationService
imApplicationService
;
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean saveImInbox(ImInbox imInbox) throws Exception {
// return super.save(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean updateImInbox(ImInbox imInbox) throws Exception {
// return super.updateById(imInbox);
// }
//
// @Transactional(rollbackFor = Exception.class)
// @Override
// public boolean deleteImInbox(Long id) throws Exception {
// return super.removeById(id);
// }
//
// @Override
// public ImInboxQueryVo getImInboxById(Long id) throws Exception {
// return imInboxMapper.getImInboxById(id);
// }
//
// @Override
// public Paging<ImInboxQueryVo> getImInboxPageList(ImInboxPageParam imInboxPageParam) throws Exception {
// Page<ImInboxQueryVo> page = new PageInfo<>(imInboxPageParam, OrderItem.desc(getLambdaColumn(ImInbox::getCreateTime)));
// IPage<ImInboxQueryVo> iPage = imInboxMapper.getImInboxPageList(page, imInboxPageParam);
// return new Paging<ImInboxQueryVo>(iPage);
// }
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
updateImMsgReceived
(
ImMsgReceivedStatusUpdate
imMsgReceivedUpdate
)
{
public
Boolean
updateImMsgReceived
(
ImMsgReceivedStatusUpdate
imMsgReceivedUpdate
)
{
ImClient
curentClient
=
imClientService
.
getCurrentClient
();
// 不做接收事件处理
// 修改已接收状态
Long
aLong
=
imInboxMapper
.
updateImMsgReceivedByIds
(
curentClient
.
getId
(),
imMsgReceivedUpdate
.
getMsgIds
());
// 根据appKey查询appid
ImApplication
application
=
imApplicationService
.
getCacheById
(
curentClient
.
getFkAppid
());
// 内容
HashMap
<
String
,
String
>
contentMap
=
new
HashMap
<>();
contentMap
.
put
(
"receiverId"
,
curentClient
.
getClientId
());
// 推送给接收方
sendMsgStatus
(
curentClient
,
MsgTypeEnum
.
CLIENT_RECEIVED_MSG
,
contentMap
,
imMsgReceivedUpdate
.
getMsgIds
());
// 是否同时修改为已读状态
if
(
imMsgReceivedUpdate
.
getReadStatus
())
{
MsgReadStatusUpdateParam
msgReadStatusUpdateParam
=
new
MsgReadStatusUpdateParam
();
msgReadStatusUpdateParam
.
setMsgIds
(
imMsgReceivedUpdate
.
getMsgIds
());
this
.
updateImMsgRead
(
msgReadStatusUpdateParam
);
}
return
true
;
return
true
;
}
}
...
@@ -138,19 +51,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
...
@@ -138,19 +51,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
updateImMsgRead
(
MsgReadStatusUpdateParam
msgReadStatusUpdateParam
)
{
public
Boolean
updateImMsgRead
(
MsgReadStatusUpdateParam
msgReadStatusUpdateParam
)
{
ImClient
curentClient
=
imClientService
.
getCurrentClient
();
// 小虎豆不做单条消息修改已读
// 修改已读状态
Long
aLong
=
imInboxMapper
.
updateImMsgReadByIds
(
curentClient
.
getId
(),
msgReadStatusUpdateParam
.
getMsgIds
());
// 根据appKey查询appid
ImApplication
application
=
imApplicationService
.
getCacheById
(
curentClient
.
getFkAppid
());
// 内容
HashMap
<
String
,
String
>
contentMap
=
new
HashMap
<>();
contentMap
.
put
(
"receiverId"
,
curentClient
.
getClientId
());
sendMsgStatus
(
curentClient
,
MsgTypeEnum
.
CLIENT_READ_MSG
,
contentMap
,
msgReadStatusUpdateParam
.
getMsgIds
());
return
true
;
return
true
;
}
}
...
@@ -158,93 +59,12 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
...
@@ -158,93 +59,12 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
@Override
@Override
public
Boolean
updateMsgReadStatusByConversation
(
UpdateMsgReadStatusByConversationParam
param
)
{
public
Boolean
updateMsgReadStatusByConversation
(
UpdateMsgReadStatusByConversationParam
param
)
{
ImClient
currentClient
=
imClientService
.
getCurrentClient
();
ImClient
currentClient
=
imClientService
.
getCurrentClient
();
// 获取该用户该会话所有未读消息 msgId 列表
this
.
remove
(
new
QueryWrapper
<
ImInbox
>().
lambda
()
List
<
ImInbox
>
imInboxList
=
this
.
list
(
new
QueryWrapper
<
ImInbox
>().
lambda
()
.
eq
(
ImInbox:
:
getFkConversationId
,
param
.
getConversationId
())
.
eq
(
ImInbox:
:
getFkConversationId
,
param
.
getConversationId
())
.
eq
(
ImInbox:
:
getReadMsgStatus
,
ReadMsgStatusEnum
.
UNREAD
.
getCode
())
.
le
(
ImInbox:
:
getFkMsgId
,
param
.
getMsgIdEnd
())
.
le
(
ImInbox:
:
getFkMsgId
,
param
.
getMsgIdEnd
())
.
eq
(
ImInbox:
:
getReceiver
,
currentClient
.
getId
()));
.
eq
(
ImInbox:
:
getReceiver
,
currentClient
.
getId
()));
if
(
CollectionUtils
.
isEmpty
(
imInboxList
))
{
return
true
;
}
List
<
Long
>
msgIds
=
imInboxList
.
stream
().
map
(
i
->
i
.
getFkMsgId
()).
collect
(
Collectors
.
toList
());
// 修改已读状态
imInboxMapper
.
updateImMsgReadByIds
(
currentClient
.
getId
(),
msgIds
);
// 内容
HashMap
<
String
,
String
>
contentMap
=
Maps
.
newHashMap
();
contentMap
.
put
(
"receiverId"
,
currentClient
.
getClientId
());
sendMsgStatus
(
currentClient
,
MsgTypeEnum
.
CLIENT_READ_MSG
,
contentMap
,
msgIds
);
return
true
;
return
true
;
}
}
/**
* 下发状态类型消息
*
* @param currentClient 当前客户端
* @param msgTypeEnum 消息类型枚举
* @param contentMap 消息content内容
* @param msgIds 消息id集合
*/
private
void
sendMsgStatus
(
ImClient
currentClient
,
MsgTypeEnum
msgTypeEnum
,
HashMap
<
String
,
String
>
contentMap
,
List
<
Long
>
msgIds
)
{
// 遍历消息id集合
for
(
Long
msgId
:
msgIds
)
{
// 查询该消息
ImMessage
imMessageDb
=
imMessageService
.
getById
(
msgId
);
if
(
imMessageDb
==
null
)
{
log
.
info
(
"查无消息内容: {}"
,
msgId
);
continue
;
}
// 根据会话id查询该会话所有成员
List
<
ImConversationMembers
>
membersList
=
imConversationMembersService
.
list
(
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
.
eq
(
ImConversationMembers:
:
getFkConversationId
,
imMessageDb
.
getFkConversationId
())
.
notIn
(
ImConversationMembers:
:
getFkClientId
,
currentClient
.
getId
())
);
// 遍历发送给该会话的每个成员
for
(
ImConversationMembers
conversationMember
:
membersList
)
{
// 消息实体
ImMessage
imMessage
=
new
ImMessage
();
imMessage
.
setId
(
msgId
);
imMessage
.
setMsgType
(
msgTypeEnum
.
getUriCode
());
imMessage
.
setCreateTime
(
new
Date
());
imMessage
.
setFkAppid
(
currentClient
.
getFkAppid
());
imMessage
.
setSender
(
currentClient
.
getId
());
imMessage
.
setWithdraw
(
false
);
imMessage
.
setEvent
(
true
);
imMessage
.
setSystemFlag
(
false
);
imMessage
.
setSendStatus
(
2
);
imMessage
.
setFkConversationId
(
conversationMember
.
getFkConversationId
());
// 封装响应的实体
ImMessageOnlineSend
imMessageOnlineSend
=
new
ImMessageOnlineSend
();
BeanUtils
.
copyProperties
(
imMessage
,
imMessageOnlineSend
);
imMessageOnlineSend
.
setType
(
msgTypeEnum
.
getUriCode
());
imMessageOnlineSend
.
setMsgId
(
imMessage
.
getId
());
imMessageOnlineSend
.
setCreateTime
(
new
Date
());
imMessageOnlineSend
.
setSender
(
currentClient
.
getClientId
());
imMessageOnlineSend
.
setContent
(
contentMap
);
imMessageOnlineSend
.
setConversationId
(
conversationMember
.
getFkConversationId
());
// 查询接收方
ImClient
imClientReceiver
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
currentClient
.
getFkAppid
())
.
eq
(
ImClient:
:
getId
,
conversationMember
.
getFkClientId
()));
if
(
imClientReceiver
==
null
)
{
continue
;
}
// 向接收方推送
WsResponse
<
ImMessageOnlineSend
>
responseModel
=
new
WsResponse
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_EVENT_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
channelSender
.
sendMsg
(
responseModel
,
imClientReceiver
.
getId
());
}
}
}
}
}
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