From d9dbd739ab7b1539af5e81794fba666c39bbeb30 Mon Sep 17 00:00:00 2001 From: withchao <48119764+withchao@users.noreply.github.com> Date: Wed, 2 Aug 2023 10:41:34 +0800 Subject: [PATCH] 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 --- go.mod | 2 +- go.sum | 4 ++-- internal/api/friend.go | 4 ++++ internal/api/msg.go | 47 ++++++++++++++++++++++++++++++++++++++++++ internal/api/route.go | 2 ++ 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9180c49f3..cbaca83b8 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require github.com/google/uuid v1.3.0 require ( github.com/OpenIMSDK/protocol v0.0.3 - github.com/OpenIMSDK/tools v0.0.5 + github.com/OpenIMSDK/tools v0.0.13 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.7.1 diff --git a/go.sum b/go.sum index e804eb461..0e6352156 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OpenIMSDK/protocol v0.0.3 h1:CFQtmnyW+1dYKVFaVaHcJ6oYuMiMdNfU2gC1xz3K/9I= github.com/OpenIMSDK/protocol v0.0.3/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= -github.com/OpenIMSDK/tools v0.0.5 h1:yBVHJ3EpIDcp8VFKPjuGr6MQvFa3t4JByZ+vmeC06/Q= -github.com/OpenIMSDK/tools v0.0.5/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= +github.com/OpenIMSDK/tools v0.0.13 h1:rcw4HS8S2DPZR9UOBxD8/ol9UBMzXBypzOVEytDRIMo= +github.com/OpenIMSDK/tools v0.0.13/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= github.com/Shopify/sarama v1.29.0 h1:ARid8o8oieau9XrHI55f/L3EoRAhm9px6sonbD7yuUE= github.com/Shopify/sarama v1.29.0/go.mod h1:2QpgD79wpdAESqNQMxNc0KYMkycd4slxGdV3TWSVqrU= diff --git a/internal/api/friend.go b/internal/api/friend.go index f64a99ef3..91fc30347 100644 --- a/internal/api/friend.go +++ b/internal/api/friend.go @@ -83,3 +83,7 @@ func (o *FriendApi) ImportFriends(c *gin.Context) { func (o *FriendApi) IsFriend(c *gin.Context) { a2r.Call(friend.FriendClient.IsFriend, o.Client, c) } + +func (o *FriendApi) GetFriendIDs(c *gin.Context) { + a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c) +} diff --git a/internal/api/msg.go b/internal/api/msg.go index e4a8fda17..e7f06dffa 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -16,6 +16,8 @@ package api import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" + "github.com/OpenIMSDK/tools/mcontext" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "github.com/mitchellh/mapstructure" @@ -234,6 +236,51 @@ func (m *MessageApi) SendMessage(c *gin.Context) { apiresp.GinSuccess(c, respPb) } +func (m *MessageApi) SendBusinessNotification(c *gin.Context) { + req := struct { + Key string `json:"key"` + Data string `json:"data"` + SendUserID string `json:"sendUserID"` + RecvUserID string `json:"recvUserID"` + }{} + if err := c.BindJSON(&req); err != nil { + apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) + return + } + if !authverify.IsAppManagerUid(c) { + apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message")) + return + } + sendMsgReq := msg.SendMsgReq{ + MsgData: &sdkws.MsgData{ + SendID: req.SendUserID, + RecvID: req.RecvUserID, + Content: []byte(utils.StructToJsonString(&sdkws.NotificationElem{ + Detail: utils.StructToJsonString(&struct { + Key string `json:"key"` + Data string `json:"data"` + }{Key: req.Key, Data: req.Data}), + })), + MsgFrom: constant.SysMsgType, + ContentType: constant.BusinessNotification, + SessionType: constant.SingleChatType, + CreateTime: utils.GetCurrentTimestampByMill(), + ClientMsgID: utils.GetMsgID(mcontext.GetOpUserID(c)), + Options: config.GetOptionsByNotification(config.NotificationConf{ + IsSendMsg: false, + ReliabilityLevel: 1, + UnreadCount: false, + }), + }, + } + respPb, err := m.Client.SendMsg(c, &sendMsgReq) + if err != nil { + apiresp.GinError(c, err) + return + } + apiresp.GinSuccess(c, respPb) +} + func (m *MessageApi) BatchSendMsg(c *gin.Context) { var ( req apistruct.BatchSendMsgReq diff --git a/internal/api/route.go b/internal/api/route.go index 5dd0c4cc7..5fd3f115a 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -102,6 +102,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive friendRouterGroup.POST("/remove_black", f.RemoveBlack) friendRouterGroup.POST("/import_friend", f.ImportFriends) friendRouterGroup.POST("/is_friend", f.IsFriend) + friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs) } g := NewGroupApi(*groupRpc) groupRouterGroup := r.Group("/group", ParseToken) @@ -167,6 +168,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive msgGroup.POST("/newest_seq", m.GetSeq) msgGroup.POST("/search_msg", m.SearchMsg) msgGroup.POST("/send_msg", m.SendMessage) + msgGroup.POST("/send_business_notification", m.SendBusinessNotification) msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs) msgGroup.POST("/revoke_msg", m.RevokeMsg) msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)