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/internal/rpc/msg/friend_notification.go

272 lines
9.6 KiB

3 years ago
package msg
import (
"Open_IM/pkg/common/constant"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
3 years ago
utils2 "Open_IM/pkg/common/utils"
3 years ago
pbFriend "Open_IM/pkg/proto/friend"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"encoding/json"
3 years ago
"github.com/golang/protobuf/proto"
3 years ago
)
//message MemberInfoChangedTips{
// int32 ChangeType = 1; //1:info changed; 2:mute
// GroupMemberFullInfo OpUser = 2; //who do this
// GroupMemberFullInfo FinalInfo = 3; //
// uint64 MuteTime = 4;
// GroupInfo Group = 5;
//}
//func MemberInfoChangedNotification(operationID string, group *immysql.Group, opUser *immysql.GroupMember, userFinalInfo *immysql.GroupMember) {
//}
//message FriendApplicationAddedTips{
// PublicUserInfo OpUser = 1; //user1
// FriendApplication Application = 2;
// PublicUserInfo OpedUser = 3; //user2
//}
3 years ago
func getFromToUserNickname(fromUserID, toUserID string) (string, string, error) {
from, err := imdb.GetUserByUserID(fromUserID)
if err != nil {
return "", "", utils.Wrap(err, "")
3 years ago
}
3 years ago
to, err := imdb.GetUserByUserID(toUserID)
if err != nil {
return "", "", utils.Wrap(err, "")
3 years ago
}
3 years ago
return from.Nickname, to.Nickname, nil
3 years ago
}
func FriendApplicationAddedNotification(req *pbFriend.AddFriendReq) {
var FriendApplicationAddedTips open_im_sdk.FriendApplicationAddedTips
FriendApplicationAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
FriendApplicationAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "getFromToUserNickname failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
return
}
3 years ago
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(FriendApplicationAddedTips)
tips.DefaultTips = fromUserNickname + " FriendApplicationAddedNotification " + toUserNickname
var n NotificationMsg
n.SendID = req.CommID.FromUserID
n.RecvID = req.CommID.ToUserID
3 years ago
n.ContentType = constant.FriendApplicationAddedNotification
3 years ago
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.CommID.OperationID
3 years ago
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
3 years ago
3 years ago
func FriendApplicationProcessedNotification(req *pbFriend.AddFriendResponseReq) {
3 years ago
var FriendApplicationProcessedTips open_im_sdk.FriendApplicationProcessedTips
FriendApplicationProcessedTips.FromToUserID.FromUserID = req.CommID.FromUserID
FriendApplicationProcessedTips.FromToUserID.ToUserID = req.CommID.ToUserID
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "getFromToUserNickname failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
return
}
3 years ago
var tips open_im_sdk.TipsComm
3 years ago
tips.Detail, err = proto.Marshal(&FriendApplicationProcessedTips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), FriendApplicationProcessedTips)
return
}
3 years ago
tips.DefaultTips = fromUserNickname + " FriendApplicationProcessedNotification " + toUserNickname
var n NotificationMsg
3 years ago
n.SendID = req.CommID.FromUserID
n.RecvID = req.CommID.ToUserID
n.ContentType = constant.FriendApplicationProcessedNotification
3 years ago
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
3 years ago
n.OperationID = req.CommID.OperationID
n.Content, _ = json.Marshal(tips)
3 years ago
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips)
return
}
3 years ago
Notification(&n)
}
3 years ago
3 years ago
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
3 years ago
var FriendAddedTips open_im_sdk.FriendAddedTips
user, err := imdb.GetUserByUserID(opUserID)
if err != nil {
3 years ago
log.NewError(operationID, "GetUserByUserID failed ", err.Error(), opUserID)
return
3 years ago
}
3 years ago
utils.CopyStructFields(FriendAddedTips.OpUser, user)
3 years ago
friend, err := imdb.GetFriendRelationshipFromFriend(fromUserID, toUserID)
if err != nil {
3 years ago
log.NewError(operationID, "GetFriendRelationshipFromFriend failed ", err.Error(), fromUserID, toUserID)
return
3 years ago
}
3 years ago
utils2.FriendDBCopyOpenIM(FriendAddedTips.Friend, friend)
3 years ago
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(fromUserID, toUserID)
3 years ago
if err != nil {
3 years ago
log.Error(operationID, "getFromToUserNickname failed ", err.Error(), fromUserID, toUserID)
return
3 years ago
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(FriendAddedTips)
tips.DefaultTips = fromUserNickname + " FriendAddedNotification " + toUserNickname
3 years ago
var n NotificationMsg
n.SendID = fromUserID
n.RecvID = toUserID
n.ContentType = constant.FriendAddedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
3 years ago
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
//message FriendDeletedTips{
// FriendInfo Friend = 1;
//}
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
var FriendDeletedTips open_im_sdk.FriendDeletedTips
FriendDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
FriendDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "getFromToUserNickname failed ", req.CommID.FromUserID, req.CommID.ToUserID)
return
}
3 years ago
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(FriendDeletedTips)
tips.DefaultTips = fromUserNickname + " FriendDeletedNotification " + toUserNickname
3 years ago
var n NotificationMsg
n.SendID = req.CommID.FromUserID
n.RecvID = req.CommID.ToUserID
n.ContentType = constant.FriendDeletedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.CommID.OperationID
3 years ago
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
//message FriendInfoChangedTips{
// FriendInfo Friend = 1;
// PublicUserInfo OpUser = 2;
// uint64 OperationTime = 3;
//}
func FriendInfoChangedNotification(operationID, opUserID, fromUserID, toUserID string) {
3 years ago
var FriendInfoChangedTips open_im_sdk.FriendInfoChangedTips
FriendInfoChangedTips.FromToUserID.FromUserID = fromUserID
FriendInfoChangedTips.FromToUserID.ToUserID = toUserID
fromUserNickname, toUserNickname, err := getFromToUserNickname(fromUserID, toUserID)
if err != nil {
log.Error(operationID, "getFromToUserNickname failed ", fromUserID, toUserID)
return
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(FriendInfoChangedTips)
tips.DefaultTips = fromUserNickname + " FriendDeletedNotification " + toUserNickname
3 years ago
var n NotificationMsg
n.SendID = fromUserID
n.RecvID = toUserID
n.ContentType = constant.FriendInfoChangedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
var BlackAddedTips open_im_sdk.BlackAddedTips
BlackAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
BlackAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "getFromToUserNickname failed ", req.CommID.FromUserID, req.CommID.ToUserID)
return
}
3 years ago
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(BlackAddedTips)
tips.DefaultTips = fromUserNickname + " BlackAddedNotification " + toUserNickname
3 years ago
var n NotificationMsg
n.SendID = req.CommID.FromUserID
n.RecvID = req.CommID.ToUserID
n.ContentType = constant.BlackAddedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.CommID.OperationID
3 years ago
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
//message BlackDeletedTips{
// BlackInfo Black = 1;
//}
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
3 years ago
var BlackDeletedTips open_im_sdk.BlackDeletedTips
BlackDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
BlackDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
fromUserNickname, toUserNickname, err := getFromToUserNickname(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "getFromToUserNickname failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
return
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(BlackDeletedTips)
tips.DefaultTips = fromUserNickname + " BlackDeletedNotification " + toUserNickname
3 years ago
var n NotificationMsg
n.SendID = req.CommID.FromUserID
n.RecvID = req.CommID.ToUserID
n.ContentType = constant.BlackDeletedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.CommID.OperationID
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
//message SelfInfoUpdatedTips{
// UserInfo SelfUserInfo = 1;
// PublicUserInfo OpUser = 2;
// uint64 OperationTime = 3;
//}
func SelfInfoUpdatedNotification(operationID, userID string) {
3 years ago
var SelfInfoUpdatedTips open_im_sdk.SelfInfoUpdatedTips
SelfInfoUpdatedTips.UserID = userID
u, err := imdb.GetUserByUserID(userID)
if err != nil {
log.NewError(operationID, "FindUserByUID failed ", err.Error(), userID)
return
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(SelfInfoUpdatedTips)
3 years ago
var n NotificationMsg
n.SendID = userID
n.RecvID = userID
n.ContentType = constant.SelfInfoUpdatedNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
tips.DefaultTips = u.Nickname + " SelfInfoUpdatedNotification "
n.Content, _ = json.Marshal(tips)
Notification(&n)
}