workMoments

This commit is contained in:
wangchuxiao
2022-04-20 16:25:33 +08:00
parent 3e5d9a394f
commit 071dd46a4c
8 changed files with 651 additions and 727 deletions
+20 -36
View File
@@ -1,47 +1,31 @@
package msg
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/chat"
pbCommon "Open_IM/pkg/proto/sdk_ws"
pbOffice "Open_IM/pkg/proto/office"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"strings"
"github.com/golang/protobuf/proto"
)
func CommentOneWorkMomentNotification(operationID, recvID string, comment db.CommentMsg, user db.User) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", recvID, user, comment)
var req pbChat.SendMsgReq
var msgData pbCommon.MsgData
msgData.SendID = user.UserID
msgData.RecvID = recvID
msgData.ContentType = constant.WorkMomentNewCommentNotification
msgData.SessionType = constant.SingleChatType
msgData.MsgFrom = constant.UserMsgType
bytes, err := json.Marshal(comment)
func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
log.NewInfo(operationID, utils.GetSelfFuncName(), recvID)
bytes, err := proto.Marshal(notificationMsg)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "marshal failed", err.Error())
}
msgData.Content = bytes
msgData.SenderFaceURL = user.FaceURL
msgData.SenderNickname = user.Nickname
msgData.CreateTime = utils.GetCurrentTimestampByMill()
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
req.MsgData = &msgData
req.OperationID = operationID
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
client := pbChat.NewChatClient(etcdConn)
respPb, err := client.SendMsg(context.Background(), &req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
return
}
if respPb.ErrCode != 0 {
log.NewError(operationID, utils.GetSelfFuncName(), "send tag msg failed ", respPb)
log.NewError(operationID, utils.GetSelfFuncName(), "proto marshal failed", err.Error())
}
WorkMomentNotification(operationID, sendID, recvID, bytes)
}
func WorkMomentNotification(operationID, sendID, recvID string, content []byte) {
n := &NotificationMsg{
SendID: sendID,
RecvID: recvID,
Content: content,
MsgFrom: constant.UserMsgType,
ContentType: constant.WorkMomentNotification,
SessionType: constant.UserMsgType,
OperationID: operationID,
}
Notification(n)
}