You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/rpcclient/msg.go

82 lines
2.4 KiB

2 years ago
package rpcclient
import (
"context"
2 years ago
"encoding/json"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
2 years ago
"github.com/golang/protobuf/proto"
2 years ago
)
type MsgClient struct {
*MetaClient
}
func NewMsgClient(zk discoveryregistry.SvcDiscoveryRegistry) *MsgClient {
return &MsgClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImMsgName)}
}
func (m *MsgClient) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
cc, err := m.getConn()
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).SendMsg(ctx, req)
return resp, err
}
func (m *MsgClient) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
cc, err := m.getConn()
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).GetMaxAndMinSeq(ctx, req)
return resp, err
}
func (m *MsgClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
cc, err := m.getConn()
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).PullMessageBySeqs(ctx, req)
return resp, err
}
2 years ago
func (c *MsgClient) Notification(ctx context.Context, sendID, recvID string, contentType, sessionType int32, m proto.Message, cfg config.NotificationConf, opts ...utils.OptionsOpt) error {
content, err := json.Marshal(m)
if err != nil {
return err
}
2 years ago
var req msg.SendMsgReq
var msg sdkws.MsgData
var offlineInfo sdkws.OfflinePushInfo
var title, desc, ex string
2 years ago
msg.SendID = sendID
msg.RecvID = recvID
msg.Content = content
msg.MsgFrom = constant.SysMsgType
msg.ContentType = contentType
msg.SessionType = sessionType
2 years ago
msg.CreateTime = utils.GetCurrentTimestampByMill()
2 years ago
msg.ClientMsgID = utils.GetMsgID(sendID)
// msg.Options = make(map[string]bool, 7)
// todo notification get sender name and face url
// msg.SenderNickname, msg.SenderFaceURL, err = c.getFaceURLAndName(sendID)
options := config.GetOptionsByNotification(cfg)
options = utils.WithOptions(options, opts...)
msg.Options = options
2 years ago
offlineInfo.Title = title
offlineInfo.Desc = desc
offlineInfo.Ex = ex
msg.OfflinePushInfo = &offlineInfo
req.MsgData = &msg
_, err = c.SendMsg(ctx, &req)
return err
}