Files
open-im-server/internal/rpc/msg/conversation_notification.go
T

85 lines
2.9 KiB
Go
Raw Normal View History

2022-02-15 14:11:20 +08:00
package msg
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
2023-02-10 18:13:58 +08:00
sdkws "Open_IM/pkg/proto/sdkws"
2022-02-15 14:11:20 +08:00
"Open_IM/pkg/utils"
2023-02-02 19:47:21 +08:00
"context"
2022-02-15 14:11:20 +08:00
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
2023-02-10 18:13:58 +08:00
func SetConversationNotification(operationID, sendID, recvID string, contentType int, m proto.Message, tips sdkws.TipsComm) {
2022-03-31 14:50:02 +08:00
log.NewInfo(operationID, "args: ", sendID, recvID, contentType, m.String(), tips.String())
2022-02-15 14:11:20 +08:00
var err error
tips.Detail, err = proto.Marshal(m)
if err != nil {
2022-03-31 14:50:02 +08:00
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
2022-02-15 14:11:20 +08:00
return
}
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
var n NotificationMsg
2022-03-31 14:50:02 +08:00
n.SendID = sendID
n.RecvID = recvID
n.ContentType = int32(contentType)
2022-02-15 14:11:20 +08:00
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(operationID, utils.GetSelfFuncName(), "Marshal failed ", err.Error(), tips.String())
return
}
Notification(&n)
}
2022-03-31 14:50:02 +08:00
// SetPrivate调用
2023-02-10 20:57:45 +08:00
func ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
2022-03-31 14:50:02 +08:00
log.NewInfo(operationID, utils.GetSelfFuncName())
2023-02-10 18:13:58 +08:00
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
2022-03-31 14:50:02 +08:00
RecvID: recvID,
SendID: sendID,
IsPrivate: isPrivateChat,
}
2023-02-10 18:13:58 +08:00
var tips sdkws.TipsComm
2022-04-01 14:43:31 +08:00
var tipsMsg string
if isPrivateChat == true {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
} else {
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
}
tips.DefaultTips = tipsMsg
2022-03-31 14:50:02 +08:00
SetConversationNotification(operationID, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
}
// 会话改变
2023-02-02 19:47:21 +08:00
func ConversationChangeNotification(ctx context.Context, userID string) {
2022-03-31 14:50:02 +08:00
log.NewInfo(operationID, utils.GetSelfFuncName())
2023-02-10 18:13:58 +08:00
ConversationChangedTips := &sdkws.ConversationUpdateTips{
2022-02-15 14:11:20 +08:00
UserID: userID,
}
2023-02-10 18:13:58 +08:00
var tips sdkws.TipsComm
2022-03-31 14:50:02 +08:00
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
SetConversationNotification(operationID, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
2022-02-15 14:11:20 +08:00
}
2022-08-05 12:08:00 +08:00
//会话未读数同步
2023-02-10 20:57:45 +08:00
func ConversationUnreadChangeNotification(context context.Context, userID, conversationID string, updateUnreadCountTime int64) {
2022-08-05 12:08:00 +08:00
log.NewInfo(operationID, utils.GetSelfFuncName())
2023-02-10 18:13:58 +08:00
ConversationChangedTips := &sdkws.ConversationUpdateTips{
2022-09-05 19:07:16 +08:00
UserID: userID,
ConversationIDList: []string{conversationID},
UpdateUnreadCountTime: updateUnreadCountTime,
2022-08-05 12:08:00 +08:00
}
2023-02-10 18:13:58 +08:00
var tips sdkws.TipsComm
2022-08-05 12:08:00 +08:00
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
SetConversationNotification(operationID, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
}