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

321 lines
11 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"
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) {
3 years ago
log.Info(req.CommID.OperationID, utils.GetSelfFuncName(), "args: ", req.String())
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
3 years ago
tips.Detail, err = proto.Marshal(&friendApplicationAddedTips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), friendApplicationAddedTips.String())
return
}
3 years ago
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, err = proto.Marshal(&tips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
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)
3 years ago
if err != nil {
3 years ago
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), friendApplicationProcessedTips.String())
3 years ago
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
3 years ago
n.Content, err = proto.Marshal(&tips)
if err != nil {
3 years ago
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips.String())
3 years ago
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
3 years ago
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
utils2.UserDBCopyOpenIMPublicUser(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
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
3 years ago
tips.Detail, err = proto.Marshal(&friendAddedTips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), friendAddedTips)
return
}
3 years ago
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, _ = proto.Marshal(&tips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
Notification(&n)
}
//message FriendDeletedTips{
// FriendInfo Friend = 1;
//}
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
3 years ago
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
3 years ago
tips.Detail, err = proto.Marshal(&friendDeletedTips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), friendDeletedTips.String())
return
}
3 years ago
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, err = proto.Marshal(&tips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
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
3 years ago
fromUserNickname, toUserNickname, err := getFromToUserNickname(fromUserID, toUserID)
if err != nil {
log.Error(operationID, "getFromToUserNickname failed ", fromUserID, toUserID)
return
}
var tips open_im_sdk.TipsComm
3 years ago
tips.Detail, err = proto.Marshal(&friendInfoChangedTips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), friendInfoChangedTips.String())
return
}
3 years ago
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
3 years ago
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
Notification(&n)
}
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
3 years ago
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
3 years ago
tips.Detail, err = proto.Marshal(&blackAddedTips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), blackAddedTips.String())
return
}
3 years ago
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, err = proto.Marshal(&tips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
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
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
}
var tips open_im_sdk.TipsComm
3 years ago
tips.Detail, err = proto.Marshal(&blackDeletedTips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), blackDeletedTips.String())
return
}
3 years ago
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
3 years ago
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(req.CommID.OperationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
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
3 years ago
u, err := imdb.GetUserByUserID(userID)
if err != nil {
log.NewError(operationID, "FindUserByUID failed ", err.Error(), userID)
return
}
var tips open_im_sdk.TipsComm
3 years ago
tips.Detail, err = proto.Marshal(&selfInfoUpdatedTips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), selfInfoUpdatedTips.String())
return
}
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 "
3 years ago
n.Content, err = proto.Marshal(&tips)
if err != nil {
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
return
}
3 years ago
Notification(&n)
}