Skip to content

Commit d9dbd73

Browse files
authored
feat: Perfect with rpc but no api (#747)
* feat: add get_group_member_user_id api * feat: add SendBusinessNotification api * feat: add GetFriendIDs api * update pkg
1 parent 31cd19a commit d9dbd73

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require github.com/google/uuid v1.3.0
3838

3939
require (
4040
github.com/OpenIMSDK/protocol v0.0.3
41-
github.com/OpenIMSDK/tools v0.0.5
41+
github.com/OpenIMSDK/tools v0.0.13
4242
github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible
4343
github.com/go-redis/redis v6.15.9+incompatible
4444
github.com/go-sql-driver/mysql v1.7.1

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
1919
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2020
github.com/OpenIMSDK/protocol v0.0.3 h1:CFQtmnyW+1dYKVFaVaHcJ6oYuMiMdNfU2gC1xz3K/9I=
2121
github.com/OpenIMSDK/protocol v0.0.3/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
22-
github.com/OpenIMSDK/tools v0.0.5 h1:yBVHJ3EpIDcp8VFKPjuGr6MQvFa3t4JByZ+vmeC06/Q=
23-
github.com/OpenIMSDK/tools v0.0.5/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
22+
github.com/OpenIMSDK/tools v0.0.13 h1:rcw4HS8S2DPZR9UOBxD8/ol9UBMzXBypzOVEytDRIMo=
23+
github.com/OpenIMSDK/tools v0.0.13/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
2424
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
2525
github.com/Shopify/sarama v1.29.0 h1:ARid8o8oieau9XrHI55f/L3EoRAhm9px6sonbD7yuUE=
2626
github.com/Shopify/sarama v1.29.0/go.mod h1:2QpgD79wpdAESqNQMxNc0KYMkycd4slxGdV3TWSVqrU=

Diff for: internal/api/friend.go

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ func (o *FriendApi) ImportFriends(c *gin.Context) {
8383
func (o *FriendApi) IsFriend(c *gin.Context) {
8484
a2r.Call(friend.FriendClient.IsFriend, o.Client, c)
8585
}
86+
87+
func (o *FriendApi) GetFriendIDs(c *gin.Context) {
88+
a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c)
89+
}

Diff for: internal/api/msg.go

+47
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package api
1616

1717
import (
1818
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
19+
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
20+
"github.com/OpenIMSDK/tools/mcontext"
1921
"github.com/gin-gonic/gin"
2022
"github.com/go-playground/validator/v10"
2123
"github.com/mitchellh/mapstructure"
@@ -234,6 +236,51 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
234236
apiresp.GinSuccess(c, respPb)
235237
}
236238

239+
func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
240+
req := struct {
241+
Key string `json:"key"`
242+
Data string `json:"data"`
243+
SendUserID string `json:"sendUserID"`
244+
RecvUserID string `json:"recvUserID"`
245+
}{}
246+
if err := c.BindJSON(&req); err != nil {
247+
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
248+
return
249+
}
250+
if !authverify.IsAppManagerUid(c) {
251+
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
252+
return
253+
}
254+
sendMsgReq := msg.SendMsgReq{
255+
MsgData: &sdkws.MsgData{
256+
SendID: req.SendUserID,
257+
RecvID: req.RecvUserID,
258+
Content: []byte(utils.StructToJsonString(&sdkws.NotificationElem{
259+
Detail: utils.StructToJsonString(&struct {
260+
Key string `json:"key"`
261+
Data string `json:"data"`
262+
}{Key: req.Key, Data: req.Data}),
263+
})),
264+
MsgFrom: constant.SysMsgType,
265+
ContentType: constant.BusinessNotification,
266+
SessionType: constant.SingleChatType,
267+
CreateTime: utils.GetCurrentTimestampByMill(),
268+
ClientMsgID: utils.GetMsgID(mcontext.GetOpUserID(c)),
269+
Options: config.GetOptionsByNotification(config.NotificationConf{
270+
IsSendMsg: false,
271+
ReliabilityLevel: 1,
272+
UnreadCount: false,
273+
}),
274+
},
275+
}
276+
respPb, err := m.Client.SendMsg(c, &sendMsgReq)
277+
if err != nil {
278+
apiresp.GinError(c, err)
279+
return
280+
}
281+
apiresp.GinSuccess(c, respPb)
282+
}
283+
237284
func (m *MessageApi) BatchSendMsg(c *gin.Context) {
238285
var (
239286
req apistruct.BatchSendMsgReq

Diff for: internal/api/route.go

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
102102
friendRouterGroup.POST("/remove_black", f.RemoveBlack)
103103
friendRouterGroup.POST("/import_friend", f.ImportFriends)
104104
friendRouterGroup.POST("/is_friend", f.IsFriend)
105+
friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs)
105106
}
106107
g := NewGroupApi(*groupRpc)
107108
groupRouterGroup := r.Group("/group", ParseToken)
@@ -167,6 +168,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
167168
msgGroup.POST("/newest_seq", m.GetSeq)
168169
msgGroup.POST("/search_msg", m.SearchMsg)
169170
msgGroup.POST("/send_msg", m.SendMessage)
171+
msgGroup.POST("/send_business_notification", m.SendBusinessNotification)
170172
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
171173
msgGroup.POST("/revoke_msg", m.RevokeMsg)
172174
msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)

0 commit comments

Comments
 (0)