mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 17:15:58 +08:00
tag
This commit is contained in:
@@ -10,20 +10,24 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TagSendMessage(operationID, sendID, recvID, content string, contentType int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", sendID, recvID, content, contentType)
|
||||
func TagSendMessage(operationID, sendID, recvID, content string, senderPlatformID int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", sendID, recvID, content)
|
||||
var req pbChat.SendMsgReq
|
||||
var msgData pbCommon.MsgData
|
||||
msgData.SendID = sendID
|
||||
msgData.RecvID = recvID
|
||||
msgData.ContentType = contentType
|
||||
msgData.ContentType = constant.Custom
|
||||
msgData.SessionType = constant.SingleChatType
|
||||
msgData.MsgFrom = constant.UserMsgType
|
||||
msgData.Content = []byte(content)
|
||||
msgData.Options = map[string]bool{}
|
||||
msgData.Options[constant.IsSenderConversationUpdate] = false
|
||||
msgData.SendTime = time.Now().Unix()
|
||||
msgData.CreateTime = time.Now().Unix()
|
||||
msgData.SenderPlatformID = senderPlatformID
|
||||
req.MsgData = &msgData
|
||||
req.OperationID = operationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
|
||||
@@ -147,10 +147,39 @@ func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp
|
||||
func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagReq) (resp *pbOffice.SendMsg2TagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SendMsg2TagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
userIDList, err := db.DB.GetUserIDListByTagID(req.SendID, req.TagID)
|
||||
for _, userID := range userIDList {
|
||||
msg.TagSendMessage(req.OperationID, req.SendID, userID, req.Content, req.ContentType)
|
||||
var tagUserIDList []string
|
||||
for _, tagID := range req.TagList {
|
||||
userIDList, err := db.DB.GetUserIDListByTagID(req.SendID, tagID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserIDListByTagID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tagUserIDList = append(tagUserIDList, userIDList...)
|
||||
}
|
||||
var groupUserIDList []string
|
||||
for _, groupID := range req.GroupList {
|
||||
userIDList, err := im_mysql_model.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
groupUserIDList = append(groupUserIDList, userIDList...)
|
||||
}
|
||||
var userIDList []string
|
||||
userIDList = append(groupUserIDList, tagUserIDList...)
|
||||
userIDList = append(groupUserIDList, groupUserIDList...)
|
||||
userIDList = append(groupUserIDList, req.UserList...)
|
||||
userIDList = utils.RemoveUserIDRepByMap(userIDList)
|
||||
for i, userID := range userIDList {
|
||||
if userID == req.SendID {
|
||||
userIDList = append(userIDList[:i], userIDList[i+1:]...)
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList)
|
||||
for _, userID := range userIDList {
|
||||
msg.TagSendMessage(req.OperationID, req.SendID, userID, req.Content, req.SenderPlatformID)
|
||||
}
|
||||
|
||||
if err := db.DB.SaveTagSendLog(req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
|
||||
@@ -72,6 +72,32 @@ func (s *userServer) Run() {
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func syncPeerUserConversation(conversation *pbUser.Conversation, operationID string) error {
|
||||
if conversation.ConversationType == constant.SingleChatType {
|
||||
peerUserConversation := db.Conversation{
|
||||
OwnerUserID: conversation.UserID,
|
||||
ConversationID: "single_" + conversation.OwnerUserID,
|
||||
ConversationType: constant.SingleChatType,
|
||||
UserID: conversation.OwnerUserID,
|
||||
GroupID: "",
|
||||
RecvMsgOpt: 0,
|
||||
UnreadCount: 0,
|
||||
DraftTextTime: 0,
|
||||
IsPinned: false,
|
||||
IsPrivateChat: conversation.IsPrivateChat,
|
||||
AttachedInfo: "",
|
||||
Ex: "",
|
||||
}
|
||||
err := imdb.CreateConversationIfNotExist(peerUserConversation)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
return err
|
||||
}
|
||||
chat.SetConversationNotification(operationID, conversation.UserID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||
var userInfoList []*sdkws.UserInfo
|
||||
@@ -113,6 +139,9 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
|
||||
continue
|
||||
}
|
||||
resp.Success = append(resp.Success, v.ConversationID)
|
||||
//if err := syncPeerUserConversation(v, req.OperationID); err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
//}
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
@@ -189,6 +218,10 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
// sync peer user conversation if conversation is singleChatType
|
||||
//if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
//}
|
||||
chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
|
||||
Reference in New Issue
Block a user