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
f4be314b
Commit
f4be314b
authored
May 16, 2022
by
罗长华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成sdk修改好友备注、删除好友接口
parent
e5b6633f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
174 additions
and
34 deletions
+174
-34
core/src/main/java/com/wecloud/im/friend/controller/ImFriendController.java
+25
-5
core/src/main/java/com/wecloud/im/friend/param/FriendRemarkParam.java
+30
-0
core/src/main/java/com/wecloud/im/friend/param/UnfriendParam.java
+1
-1
core/src/main/java/com/wecloud/im/friend/service/ImFriendService.java
+29
-13
im-sdk/src/main/java/com/wecloud/im/sdk/ResourcePathConstants.java
+6
-1
im-sdk/src/main/java/com/wecloud/im/sdk/WecloudIm.java
+12
-3
im-sdk/src/main/java/com/wecloud/im/sdk/WecloudImClient.java
+10
-2
im-sdk/src/main/java/com/wecloud/im/sdk/internal/WecloudImContactsOperation.java
+28
-3
im-sdk/src/main/java/com/wecloud/im/sdk/model/Conversation.java
+0
-5
im-sdk/src/main/java/com/wecloud/im/sdk/model/RemarkFriendRequest.java
+32
-0
im-sdk/src/main/java/com/wecloud/im/sdk/model/UnfriendRequest.java
+1
-1
No files found.
core/src/main/java/com/wecloud/im/friend/controller/ImFriendController.java
View file @
f4be314b
...
...
@@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.alibaba.fastjson.JSON
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.friend.param.FriendRemarkParam
;
import
com.wecloud.im.friend.param.ImCreateRecommendParam
;
import
com.wecloud.im.friend.param.ImDeleteFriendParam
;
import
com.wecloud.im.friend.param.ImDeleteRecommendParam
;
...
...
@@ -234,23 +235,42 @@ public class ImFriendController extends BaseController {
/**
* 批量删除好友 sdk用
*/
@PostMapping
(
"/unfriends"
)
@PostMapping
(
"/
sdk/
unfriends"
)
@ApiOperation
(
value
=
"删除好友"
)
public
ApiResult
<
Boolean
>
unfriends
(
@RequestBody
UnfriendParam
param
)
{
log
.
info
(
"删除好友入参 {}"
,
JSON
.
toJSONString
(
param
));
if
(
StringUtils
.
isBlank
(
param
.
getUserId
()))
{
throw
new
BusinessException
(
"参数userId不能为空"
);
}
if
(
StringUtils
.
isBlank
(
param
.
getFriendIds
()))
{
throw
new
BusinessException
(
"参数friends不能为空"
);
if
(
StringUtils
.
isBlank
(
param
.
getFriend
User
Ids
()))
{
throw
new
BusinessException
(
"参数friend
UserId
s不能为空"
);
}
imFriendService
.
unfriends
(
param
);
return
ApiResult
.
ok
();
}
/**
* 好友备注
* @Author luozh
* @Date 2022年05月16日 11:07:53
* @param param
* @Return
*/
@PostMapping
(
"/sdk/remark"
)
@ApiOperation
(
value
=
"备注"
)
public
ApiResult
<
Boolean
>
remark
(
@RequestBody
FriendRemarkParam
param
)
{
log
.
info
(
"删除好友入参 {}"
,
JSON
.
toJSONString
(
param
));
if
(
StringUtils
.
isBlank
(
param
.
getUserId
()))
{
throw
new
BusinessException
(
"参数userId不能为空"
);
}
if
(
StringUtils
.
isBlank
(
param
.
getFriendUserId
()))
{
throw
new
BusinessException
(
"参数friendUserId不能为空"
);
}
imFriendService
.
remark
(
param
);
return
ApiResult
.
ok
();
}
/**
* 好友分页列表
*/
@PostMapping
(
"/getPageList"
)
...
...
core/src/main/java/com/wecloud/im/friend/param/FriendRemarkParam.java
0 → 100644
View file @
f4be314b
package
com
.
wecloud
.
im
.
friend
.
param
;
import
lombok.Data
;
/**
* 好友备注请求
* @Author luozh
* @Date 2022年05月16日 11:09
* @Version 1.0
*/
@Data
public
class
FriendRemarkParam
{
/**
* 用户id
*/
private
String
userId
;
/**
* 朋友用户id
*/
private
String
friendUserId
;
/**
* 备注
*/
private
String
friendRemark
;
}
core/src/main/java/com/wecloud/im/friend/param/UnfriendParam.java
View file @
f4be314b
...
...
@@ -22,5 +22,5 @@ public class UnfriendParam {
* 朋友id 多个用,隔开
*/
@ApiModelProperty
(
"朋友id 多个用,隔开"
)
private
String
friendIds
;
private
String
friend
User
Ids
;
}
core/src/main/java/com/wecloud/im/friend/service/ImFriendService.java
View file @
f4be314b
...
...
@@ -23,12 +23,14 @@ import org.springframework.transaction.annotation.Transactional;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.friend.entity.ImFriend
;
import
com.wecloud.im.friend.entity.ImFriendRecommend
;
import
com.wecloud.im.friend.mapper.ImFriendMapper
;
import
com.wecloud.im.friend.mapper.ImFriendRecommendMapper
;
import
com.wecloud.im.friend.param.FriendRemarkParam
;
import
com.wecloud.im.friend.param.ImFriendApplyDto
;
import
com.wecloud.im.friend.param.ImFriendBaseDto
;
import
com.wecloud.im.friend.param.ImFriendPageParam
;
...
...
@@ -114,11 +116,11 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
my
.
setFriendName
(
friendName
);
my
.
setRequestRemark
(
requestRemark
);
my
.
setState
(
FriendStateEnum
.
UNSURE
.
getCode
());
if
(
getByKey
(
currentClient
.
getClientId
(),
friendClient
.
getClientId
())
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
requestRemark
))
{
if
(
getByKey
(
currentClient
.
getClientId
(),
friendClient
.
getClientId
())
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
requestRemark
))
{
my
.
setRequestRemark
(
requestRemark
);
}
if
(
StringUtils
.
isNotEmpty
(
friendName
))
{
if
(
StringUtils
.
isNotEmpty
(
friendName
))
{
my
.
setFriendName
(
friendName
);
}
this
.
updateByKey
(
my
);
...
...
@@ -135,8 +137,8 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
friend
.
setClientIdClaimer
(
currentClient
.
getClientId
());
friend
.
setRequestRemark
(
requestRemark
);
friend
.
setState
(
FriendStateEnum
.
UNSURE
.
getCode
());
if
(
getByKey
(
friendClient
.
getClientId
(),
currentClient
.
getClientId
())
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
requestRemark
))
{
if
(
getByKey
(
friendClient
.
getClientId
(),
currentClient
.
getClientId
())
!=
null
)
{
if
(
StringUtils
.
isNotEmpty
(
requestRemark
))
{
friend
.
setRequestRemark
(
requestRemark
);
}
this
.
updateByKey
(
friend
);
...
...
@@ -203,7 +205,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
*/
@Transactional
public
boolean
approveFriend
(
ImClient
currentClient
,
ImClient
friendClient
,
boolean
agree
,
String
rejectRemark
)
{
if
(
agree
)
{
if
(
agree
)
{
rejectRemark
=
null
;
}
//好友关系有维护两条,我和他,他和我
...
...
@@ -213,7 +215,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
friend
.
setClientIdFriend
(
currentClient
.
getClientId
());
friend
.
setClientIdClaimer
(
friendClient
.
getClientId
());
friend
.
setState
(
agree
?
FriendStateEnum
.
CONFORM
.
getCode
()
:
FriendStateEnum
.
REJECT
.
getCode
());
if
(
StringUtils
.
isNotEmpty
(
rejectRemark
))
{
if
(
StringUtils
.
isNotEmpty
(
rejectRemark
))
{
friend
.
setRejectRemark
(
rejectRemark
);
}
boolean
ok1
=
this
.
updateByKey
(
friend
);
...
...
@@ -223,7 +225,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
my
.
setClientIdFriend
(
friendClient
.
getClientId
());
my
.
setClientIdClaimer
(
friendClient
.
getClientId
());
my
.
setState
(
agree
?
FriendStateEnum
.
CONFORM
.
getCode
()
:
FriendStateEnum
.
REJECT
.
getCode
());
if
(
StringUtils
.
isNotEmpty
(
rejectRemark
))
{
if
(
StringUtils
.
isNotEmpty
(
rejectRemark
))
{
my
.
setRejectRemark
(
rejectRemark
);
}
boolean
ok2
=
this
.
updateByKey
(
my
);
...
...
@@ -232,7 +234,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
}
public
void
batchDeleteFriend
(
ImClient
currentClient
,
List
<
String
>
friendClientIds
)
{
if
(
CollectionUtils
.
isEmpty
(
friendClientIds
))
{
if
(
CollectionUtils
.
isEmpty
(
friendClientIds
))
{
return
;
}
imFriendMapper
.
batchDeleteFriend
(
currentClient
.
getClientId
(),
currentClient
.
getFkAppid
(),
friendClientIds
);
...
...
@@ -251,7 +253,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
}
public
void
batchDeleteRecommend
(
ImClient
currentClient
,
List
<
String
>
friendClientIds
)
{
if
(
CollectionUtils
.
isEmpty
(
friendClientIds
))
{
if
(
CollectionUtils
.
isEmpty
(
friendClientIds
))
{
return
;
}
imFriendRecommendMapper
.
batchDeleteRecommend
(
currentClient
.
getClientId
(),
currentClient
.
getFkAppid
(),
friendClientIds
);
...
...
@@ -268,7 +270,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
List
<
String
>
friendClientIds
=
friends
.
stream
().
map
(
ImFriendRecommendDto:
:
getFriendClientId
).
collect
(
Collectors
.
toList
());
// 批量获取clientId 对应的内表 id主键
List
<
ImClientSimpleDto
>
simpleFriendClients
=
imClientService
.
getSimpleClients
(
currentClient
.
getFkAppid
(),
friendClientIds
);
if
(
CollectionUtils
.
isEmpty
(
simpleFriendClients
))
{
if
(
CollectionUtils
.
isEmpty
(
simpleFriendClients
))
{
return
;
}
//对已经存在的好友过滤掉
...
...
@@ -282,7 +284,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
for
(
ImFriendRecommendDto
p
:
friends
)
{
String
friendClientId
=
friendClientIdMap
.
get
(
p
.
getFriendClientId
());
// 只有client存在的数据才是真数据
if
(
friendClientId
==
null
)
{
if
(
friendClientId
==
null
)
{
continue
;
}
// 如果推荐的人已经是好友,则忽略。
...
...
@@ -308,10 +310,24 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
public
void
unfriends
(
UnfriendParam
param
)
{
Long
appId
=
SecurityUtils
.
getCurrentAppId
();
ImClient
client
=
imClientService
.
getCacheImClient
(
appId
,
param
.
getUserId
());
List
<
String
>
friendClientIds
=
Arrays
.
asList
(
param
.
getFriendIds
().
split
(
","
));
List
<
String
>
friendClientIds
=
Arrays
.
asList
(
param
.
getFriend
User
Ids
().
split
(
","
));
if
(
CollectionUtils
.
isEmpty
(
friendClientIds
))
{
return
;
}
imFriendMapper
.
batchDeleteFriend
(
client
.
getClientId
(),
appId
,
friendClientIds
);
}
public
Boolean
remark
(
FriendRemarkParam
param
)
{
Long
appId
=
SecurityUtils
.
getCurrentAppId
();
ImClient
client
=
imClientService
.
getCacheImClient
(
appId
,
param
.
getUserId
());
ImClient
friendClient
=
imClientService
.
getCacheImClient
(
appId
,
param
.
getFriendUserId
());
ImFriend
friendInfo
=
getOne
(
Wrappers
.<
ImFriend
>
lambdaQuery
().
eq
(
ImFriend:
:
getClientId
,
param
.
getUserId
())
.
eq
(
ImFriend:
:
getClientIdFriend
,
param
.
getFriendUserId
()));
if
(
friendInfo
==
null
)
{
throw
new
BusinessException
(
"未找到好友信息"
);
}
friendInfo
.
setFriendName
(
param
.
getFriendRemark
());
return
this
.
updateById
(
friendInfo
);
}
}
im-sdk/src/main/java/com/wecloud/im/sdk/ResourcePathConstants.java
View file @
f4be314b
...
...
@@ -124,7 +124,12 @@ public class ResourcePathConstants {
/**
* 删除好友请求
*/
public
static
final
String
UNFRIEND_REQUEST
=
"/api/friend/unfriends"
;
public
static
final
String
UNFRIEND_REQUEST
=
"/api/friend/sdk/unfriends"
;
/**
* 好友备注请求
*/
public
static
final
String
REMARK_FRIEND_REQUEST
=
"/api/friend/sdk/remark"
;
}
im-sdk/src/main/java/com/wecloud/im/sdk/WecloudIm.java
View file @
f4be314b
...
...
@@ -262,10 +262,19 @@ public interface WecloudIm {
* @Author luozh
* @Date 2022年05月16日 10:14:07
* @param userId
* @param friendIds
* @param friend
User
Ids
* @Return
*/
Boolean
unfriend
(
String
userId
,
String
friendIds
);
Boolean
unfriend
(
String
userId
,
String
friendUserIds
);
/**
* 备注好友
* @Author luozh
* @Date 2022年05月16日 11:13:35
* @param userId
* @param friendUserId
* @param remark
* @Return
*/
Boolean
remarkFriend
(
String
userId
,
String
friendUserId
,
String
remark
);
}
im-sdk/src/main/java/com/wecloud/im/sdk/WecloudImClient.java
View file @
f4be314b
...
...
@@ -43,6 +43,7 @@ import com.wecloud.im.sdk.model.PublishGroupChatStatusMessageRequest;
import
com.wecloud.im.sdk.model.PublishPrivateChatMessageRequest
;
import
com.wecloud.im.sdk.model.PublishPrivateChatStatusMessageRequest
;
import
com.wecloud.im.sdk.model.RegisterClientRequest
;
import
com.wecloud.im.sdk.model.RemarkFriendRequest
;
import
com.wecloud.im.sdk.model.SetConversationDoNotDisturbRequest
;
import
com.wecloud.im.sdk.model.SetConversationTopRequest
;
import
com.wecloud.im.sdk.model.Token
;
...
...
@@ -280,11 +281,18 @@ public class WecloudImClient implements WecloudIm {
}
@Override
public
Boolean
unfriend
(
String
userId
,
String
friendIds
)
{
UnfriendRequest
unfriendRequest
=
UnfriendRequest
.
builder
().
userId
(
userId
).
friend
Ids
(
friend
Ids
).
build
();
public
Boolean
unfriend
(
String
userId
,
String
friend
User
Ids
)
{
UnfriendRequest
unfriendRequest
=
UnfriendRequest
.
builder
().
userId
(
userId
).
friend
UserIds
(
friendUser
Ids
).
build
();
return
imContactsOperation
.
unfriend
(
unfriendRequest
);
}
@Override
public
Boolean
remarkFriend
(
String
userId
,
String
friendUserId
,
String
remark
)
{
RemarkFriendRequest
remarkFriendRequest
=
RemarkFriendRequest
.
builder
().
userId
(
userId
).
friendUserId
(
friendUserId
).
remark
(
remark
).
build
();
return
imContactsOperation
.
remarkFriend
(
remarkFriendRequest
);
}
private
void
initOperations
()
{
this
.
imClientOperation
=
new
WecloudImClientOperation
(
apiDomain
,
appKey
,
appSecret
);
this
.
imConversationOperation
=
new
WecloudImConversationOperation
(
apiDomain
,
appKey
,
appSecret
);
...
...
im-sdk/src/main/java/com/wecloud/im/sdk/internal/WecloudImContactsOperation.java
View file @
f4be314b
...
...
@@ -18,6 +18,7 @@ import com.wecloud.im.sdk.model.GetUnsureFriendsRequest;
import
com.wecloud.im.sdk.model.GroupMembersFriendRequestRequest
;
import
com.wecloud.im.sdk.model.PageBlacklistRequest
;
import
com.wecloud.im.sdk.model.PageResult
;
import
com.wecloud.im.sdk.model.RemarkFriendRequest
;
import
com.wecloud.im.sdk.model.UnfriendRequest
;
import
com.wecloud.im.sdk.model.UnsureFriend
;
...
...
@@ -26,6 +27,7 @@ import static com.wecloud.im.sdk.ResourcePathConstants.GET_FRIENDS;
import
static
com
.
wecloud
.
im
.
sdk
.
ResourcePathConstants
.
GET_UNSURE_FRIENDS
;
import
static
com
.
wecloud
.
im
.
sdk
.
ResourcePathConstants
.
GROUP_MEMBERS_FRIEND_REQUEST
;
import
static
com
.
wecloud
.
im
.
sdk
.
ResourcePathConstants
.
PAGE_BLACKLIST_REQUEST
;
import
static
com
.
wecloud
.
im
.
sdk
.
ResourcePathConstants
.
REMARK_FRIEND_REQUEST
;
import
static
com
.
wecloud
.
im
.
sdk
.
ResourcePathConstants
.
UNFRIEND_REQUEST
;
import
static
com
.
wecloud
.
im
.
sdk
.
utils
.
CodingUtils
.
assertParameterNotBlank
;
import
static
com
.
wecloud
.
im
.
sdk
.
utils
.
CodingUtils
.
assertParameterNotNull
;
...
...
@@ -189,14 +191,14 @@ public class WecloudImContactsOperation extends WecloudImOperation {
public
Boolean
unfriend
(
UnfriendRequest
unfriendRequest
)
{
String
userId
=
unfriendRequest
.
getUserId
();
String
friend
Ids
=
unfriendRequest
.
getFriend
Ids
();
String
friend
UserIds
=
unfriendRequest
.
getFriendUser
Ids
();
// 参数校验
assertParameterNotBlank
(
userId
,
"userId"
);
assertParameterNotBlank
(
friend
Ids
,
"friend
Ids"
);
assertParameterNotBlank
(
friend
UserIds
,
"friendUser
Ids"
);
// 校验通过 构建参数
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"userId"
,
userId
);
param
.
put
(
"friendIds"
,
friendIds
);
param
.
put
(
"friendIds"
,
friend
User
Ids
);
// 发送请求
RequestMessage
request
=
new
WecloudRequestMessageBuilder
().
setEndpoint
(
UNFRIEND_REQUEST
)
.
setMethod
(
HttpMethod
.
POST
).
setParameters
(
param
)
...
...
@@ -207,4 +209,27 @@ public class WecloudImContactsOperation extends WecloudImOperation {
return
flag
;
}
public
Boolean
remarkFriend
(
RemarkFriendRequest
remarkFriendRequest
)
{
String
userId
=
remarkFriendRequest
.
getUserId
();
String
friendUserId
=
remarkFriendRequest
.
getFriendUserId
();
String
remark
=
remarkFriendRequest
.
getRemark
();
// 参数校验
assertParameterNotBlank
(
userId
,
"userId"
);
assertParameterNotBlank
(
friendUserId
,
"friendUserId"
);
// 校验通过 构建参数
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"userId"
,
userId
);
param
.
put
(
"friendUserId"
,
friendUserId
);
param
.
put
(
"remark"
,
remark
);
// 发送请求
RequestMessage
request
=
new
WecloudRequestMessageBuilder
().
setEndpoint
(
REMARK_FRIEND_REQUEST
)
.
setMethod
(
HttpMethod
.
POST
).
setParameters
(
param
)
.
setOriginalRequest
(
remarkFriendRequest
).
build
();
Object
result
=
doOperation
(
request
);
Boolean
flag
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
result
),
Boolean
.
class
);
return
flag
;
}
}
im-sdk/src/main/java/com/wecloud/im/sdk/model/Conversation.java
View file @
f4be314b
...
...
@@ -101,11 +101,6 @@ public class Conversation implements Serializable {
private
Boolean
forbidAddFriend
;
/**
* "禁止发红包"
*/
private
Boolean
forbidSendRedPackets
;
/**
* "禁止发图片"
*/
private
Boolean
forbidSendPic
;
...
...
im-sdk/src/main/java/com/wecloud/im/sdk/model/RemarkFriendRequest.java
0 → 100644
View file @
f4be314b
package
com
.
wecloud
.
im
.
sdk
.
model
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
*
* @Author luozh
* @Date 2022年05月16日 11:14
* @Version 1.0
*/
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Builder
public
class
RemarkFriendRequest
extends
WebServiceRequest
{
/**
* 用户Id
*/
private
String
userId
;
/**
* 好友userId
*/
private
String
friendUserId
;
/**
* 备注
*/
private
String
remark
;
}
im-sdk/src/main/java/com/wecloud/im/sdk/model/UnfriendRequest.java
View file @
f4be314b
...
...
@@ -23,7 +23,7 @@ public class UnfriendRequest extends WebServiceRequest {
/**
* 朋友id
*/
private
String
friendIds
;
private
String
friend
User
Ids
;
}
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