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
20d354e8
Commit
20d354e8
authored
Apr 27, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
退出聊天室
parent
4754b4ea
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
0 deletions
+95
-0
core/src/main/java/com/wecloud/im/param/ExitChatRoomParam.java
+32
-0
core/src/main/java/com/wecloud/im/service/ImConversationService.java
+8
-0
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+55
-0
No files found.
core/src/main/java/com/wecloud/im/param/ExitChatRoomParam.java
0 → 100644
View file @
20d354e8
package
com
.
wecloud
.
im
.
param
;
import
io.geekidea.springbootplus.framework.common.entity.BaseEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* @Author wenzhida
* @Date 2022/4/27 11:44
* @Description 用户退出聊天室入参
*/
@Data
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"用户退出聊天室入参"
)
public
class
ExitChatRoomParam
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
-
3602523207000275557L
;
@ApiModelProperty
(
"聊天室id"
)
private
Long
chatRoomId
;
@ApiModelProperty
(
"离开聊天室的clientId"
)
private
String
clientId
;
@ApiModelProperty
(
"客户端平台: 1 web, 2 安卓, 3 ios, 4 pc-win, 5 pc-macOs, 需与生成sign时的值一致"
)
private
Integer
platform
;
}
core/src/main/java/com/wecloud/im/service/ImConversationService.java
View file @
20d354e8
package
com
.
wecloud
.
im
.
service
;
import
com.wecloud.im.param.ExitChatRoomParam
;
import
com.wecloud.im.param.IntoChatRoomParam
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
...
...
@@ -213,5 +214,12 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/
Boolean
intoChatRoom
(
IntoChatRoomParam
param
);
/**
* 用户离开聊天室
* @param param
* @return
*/
Boolean
exitRoom
(
ExitChatRoomParam
param
);
}
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
20d354e8
package
com
.
wecloud
.
im
.
service
.
impl
;
import
com.wecloud.im.chatroom.cache.ChatRoomCacheManager
;
import
com.wecloud.im.param.ExitChatRoomParam
;
import
com.wecloud.im.param.IntoChatRoomParam
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
...
...
@@ -1217,4 +1218,58 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return
true
;
}
@Override
public
Boolean
exitRoom
(
ExitChatRoomParam
param
)
{
// 获取当前client
ImClient
currentClient
=
contextService
.
getImClientIfNotNullOrThrow
();
// 根据appId查询application
ImApplication
imApplication
=
contextService
.
getImApplicationIfNotNullOrThrow
(
currentClient
.
getFkAppid
());
ImConversation
imConversation
=
imConversationService
.
getById
(
param
.
getChatRoomId
());
if
(
imConversation
==
null
)
{
throw
new
BusinessException
(
"查无会话消息"
);
}
// 获取房间所有成员 key是 client的主键id:platform, val是 ip
Map
<
String
,
String
>
chatRoomMembers
=
chatRoomCacheManager
.
findOnlineClientsByChatRoomId
(
param
.
getChatRoomId
());
if
(
chatRoomMembers
.
isEmpty
())
{
throw
new
BusinessException
(
"会话中查无群人员"
);
}
Boolean
inRoom
=
Boolean
.
FALSE
;
for
(
String
key
:
chatRoomMembers
.
keySet
())
{
if
(
currentClient
.
getId
().
toString
().
equals
(
key
.
split
(
RedisUtils
.
SPLIT
)[
0
]))
{
inRoom
=
Boolean
.
TRUE
;
continue
;
}
}
if
(!
inRoom
)
{
// 不在房间
return
Boolean
.
FALSE
;
}
// 将群成员数量减1
imConversationMapper
.
addMemberCount
(
currentClient
.
getFkAppid
(),
param
.
getChatRoomId
(),
-
1
);
chatRoomCacheManager
.
exitRoom
(
currentClient
.
getId
(),
param
.
getChatRoomId
(),
param
.
getPlatform
());
// ws 退出事件通知给房间内其他人 ----------
// 生成消息id
long
messageId
=
SnowflakeUtil
.
getId
();
ImMessage
imMessage
=
new
ImMessage
();
// 保存消息至消息表
imMessage
.
setId
(
messageId
);
imMessage
.
setMsgType
(
MsgTypeEnum
.
LEAVE_CONVERSATION
.
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
(
param
.
getChatRoomId
());
// 遍历发送给已在群内的成员
for
(
String
key
:
chatRoomMembers
.
keySet
())
{
Long
fkClientId
=
Long
.
valueOf
(
key
.
split
(
RedisUtils
.
SPLIT
)[
0
]);
sendEventMsgToMember
(
imApplication
,
fkClientId
,
imMessage
,
currentClient
);
}
return
true
;
}
}
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