commit
0ed5f8081a
@ -0,0 +1,154 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func getFromToUserNickname(fromUserID, toUserID string) (string, string, error) {
|
||||
from, err := imdb.GetUserByUserID(fromUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
}
|
||||
to, err := imdb.GetUserByUserID(toUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
}
|
||||
return from.Nickname, to.Nickname, nil
|
||||
}
|
||||
|
||||
func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Message) {
|
||||
log.Info(commID.OperationID, utils.GetSelfFuncName(), "args: ", commID, contentType)
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
fromUserNickname, toUserNickname, err := getFromToUserNickname(commID.FromUserID, commID.ToUserID)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "getFromToUserNickname failed ", err.Error(), commID.FromUserID, commID.ToUserID)
|
||||
return
|
||||
}
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.FriendApplicationNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplication.DefaultTips.Tips
|
||||
case constant.FriendApplicationApprovedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationApproved.DefaultTips.Tips
|
||||
case constant.FriendApplicationRejectedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationRejected.DefaultTips.Tips
|
||||
case constant.FriendAddedNotification:
|
||||
tips.DefaultTips = cn.FriendAdded.DefaultTips.Tips
|
||||
case constant.FriendDeletedNotification:
|
||||
tips.DefaultTips = cn.FriendDeleted.DefaultTips.Tips + toUserNickname
|
||||
case constant.FriendRemarkSetNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendRemarkSet.DefaultTips.Tips
|
||||
case constant.BlackAddedNotification:
|
||||
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips + toUserNickname
|
||||
case constant.BlackDeletedNotification:
|
||||
tips.DefaultTips = cn.BlackDeleted.DefaultTips.Tips + toUserNickname
|
||||
default:
|
||||
log.Error(commID.OperationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = commID.FromUserID
|
||||
n.RecvID = commID.ToUserID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = commID.OperationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func FriendApplicationNotification(req *pbFriend.AddFriendReq) {
|
||||
FriendApplicationTips := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
}
|
||||
|
||||
func FriendApplicationApprovedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendApplicationRejectedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
friendAddedTips := open_im_sdk.FriendAddedTips{Friend: &open_im_sdk.FriendInfo{}, OpUser: &open_im_sdk.PublicUserInfo{}}
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetUserByUserID failed ", err.Error(), opUserID)
|
||||
return
|
||||
}
|
||||
utils2.UserDBCopyOpenIMPublicUser(friendAddedTips.OpUser, user)
|
||||
friend, err := imdb.GetFriendRelationshipFromFriend(fromUserID, toUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetFriendRelationshipFromFriend failed ", err.Error(), fromUserID, toUserID)
|
||||
return
|
||||
}
|
||||
utils2.FriendDBCopyOpenIM(friendAddedTips.Friend, friend)
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendAddedNotification, &friendAddedTips)
|
||||
}
|
||||
|
||||
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
friendDeletedTips := open_im_sdk.FriendDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
friendDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendDeletedNotification, &friendDeletedTips)
|
||||
}
|
||||
|
||||
func FriendRemarkSetNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
friendInfoChangedTips := open_im_sdk.FriendInfoChangedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendInfoChangedTips.FromToUserID.FromUserID = fromUserID
|
||||
friendInfoChangedTips.FromToUserID.ToUserID = toUserID
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendRemarkSetNotification, &friendInfoChangedTips)
|
||||
}
|
||||
|
||||
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
blackAddedTips := open_im_sdk.BlackAddedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackAddedNotification, &blackAddedTips)
|
||||
}
|
||||
|
||||
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
blackDeletedTips := open_im_sdk.BlackDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||
}
|
||||
|
||||
func UserInfoUpdatedNotification(operationID, userID string, needNotifiedUserID string) {
|
||||
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: userID}
|
||||
commID := pbFriend.CommID{FromUserID: userID, ToUserID: userID, OpUserID: needNotifiedUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
@ -0,0 +1,368 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
//message GroupCreatedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo Creator = 2;
|
||||
// repeated GroupMemberFullInfo MemberList = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
if token_verify.IsMangerUserID(opUserID) {
|
||||
u, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetUserByUserID failed")
|
||||
}
|
||||
utils.CopyStructFields(groupMemberInfo, u)
|
||||
groupMemberInfo.GroupID = groupID
|
||||
} else {
|
||||
u, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupMemberInfoByGroupIDAndUserID failed")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, u); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupInfoByGroupID failed")
|
||||
}
|
||||
err = utils2.GroupDBCopyOpenIM(groupInfo, group)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupMemberNumByGroupID failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
groupMember, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupOwnerInfo(groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setPublicUserInfo(userID string, publicUserInfo *open_im_sdk.PublicUserInfo) error {
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
utils2.UserDBCopyOpenIMPublicUser(publicUserInfo, user)
|
||||
return nil
|
||||
}
|
||||
|
||||
func groupNotification(contentType int32, m proto.Message, sendID, groupID, recvUserID, operationID string) {
|
||||
log.Info(operationID, utils.GetSelfFuncName(), "args: ", contentType)
|
||||
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
tips.DefaultTips = cn.GroupCreated.DefaultTips.Tips
|
||||
case constant.GroupInfoSetNotification:
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
case constant.MemberQuitNotification:
|
||||
case constant.GroupApplicationAcceptedNotification:
|
||||
case constant.GroupApplicationRejectedNotification:
|
||||
case constant.GroupOwnerTransferredNotification:
|
||||
case constant.MemberKickedNotification:
|
||||
case constant.MemberInvitedNotification:
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
n.SessionType = constant.GroupChatType
|
||||
} else {
|
||||
n.RecvID = recvUserID
|
||||
n.SessionType = constant.SingleChatType
|
||||
}
|
||||
n.ContentType = contentType
|
||||
n.OperationID = operationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
//创建群后调用
|
||||
func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberList []string) {
|
||||
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, GroupOwnerUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setOpUserInfo(opUserID, groupID, GroupCreatedTips.OpUser); err != nil {
|
||||
log.NewError(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID, GroupCreatedTips.OpUser)
|
||||
return
|
||||
}
|
||||
err := setGroupInfo(groupID, GroupCreatedTips.Group)
|
||||
if err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", groupID, GroupCreatedTips.Group)
|
||||
return
|
||||
}
|
||||
imdb.GetGroupOwnerInfoByGroupID(groupID)
|
||||
if err := setGroupOwnerInfo(groupID, GroupCreatedTips.GroupOwnerUser); err != nil {
|
||||
log.Error(operationID, "setGroupOwnerInfo failed", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
for _, v := range initMemberList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, v)
|
||||
continue
|
||||
}
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
}
|
||||
groupNotification(constant.GroupCreatedNotification, &GroupCreatedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//群信息改变后掉用
|
||||
func GroupInfoSetNotification(operationID, opUserID, groupID string) {
|
||||
GroupInfoChangedTips := open_im_sdk.GroupInfoSetTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, GroupInfoChangedTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, GroupInfoChangedTips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupInfoSetNotification, &GroupInfoChangedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
//} apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
// ReqMessage string `protobuf:"bytes,2,opt,name=ReqMessage" json:"ReqMessage,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,3,opt,name=OpUserID" json:"OpUserID,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//申请进群后调用
|
||||
func JoinGroupApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}}
|
||||
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err = setPublicUserInfo(req.OpUserID, JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(req.OperationID, "setPublicUserInfo failed ", err.Error(), req.OpUserID)
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, req.OpUserID, "", v.UserID, req.OperationID)
|
||||
log.NewInfo(req.OperationID, "Notification ", v)
|
||||
}
|
||||
}
|
||||
|
||||
func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
|
||||
MemberQuitTips := open_im_sdk.MemberQuitTips{Group: &open_im_sdk.GroupInfo{}, QuitUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberQuitTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberQuitTips.QuitUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID)
|
||||
return
|
||||
}
|
||||
|
||||
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, "", req.OpUserID, req.OperationID)
|
||||
|
||||
}
|
||||
|
||||
//message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
//}
|
||||
//处理进群请求后调用
|
||||
func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := open_im_sdk.GroupApplicationAcceptedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := setGroupInfo(req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationAcceptedTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
|
||||
}
|
||||
|
||||
func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationRejectedTips := open_im_sdk.GroupApplicationRejectedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := setGroupInfo(req.GroupID, GroupApplicationRejectedTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationRejectedTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupApplicationRejectedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationRejectedTips.OpUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
|
||||
}
|
||||
|
||||
func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
|
||||
GroupOwnerTransferredTips := open_im_sdk.GroupOwnerTransferredTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, NewGroupOwner: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, GroupOwnerTransferredTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupOwnerTransferredTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(req.GroupID, req.NewOwnerUserID, GroupOwnerTransferredTips.NewGroupOwner); err != nil {
|
||||
log.Error(req.OperationID, "setGroupMemberInfo failed", req.GroupID, req.NewOwnerUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, "", req.NewOwnerUserID, req.OperationID)
|
||||
}
|
||||
|
||||
//message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := open_im_sdk.MemberKickedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberKickedTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberKickedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID)
|
||||
return
|
||||
}
|
||||
for _, v := range kickedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(req.GroupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(req.OperationID, "setGroupMemberInfo failed ", err.Error(), req.GroupID, v)
|
||||
continue
|
||||
}
|
||||
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
|
||||
}
|
||||
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
|
||||
for _, v := range kickedUserIDList {
|
||||
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, "", v, req.OperationID)
|
||||
}
|
||||
}
|
||||
|
||||
//message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被邀请进群后调用
|
||||
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
|
||||
MemberInvitedTips := open_im_sdk.MemberInvitedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, MemberInvitedTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, MemberInvitedTips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
for _, v := range invitedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
MemberInvitedTips.InvitedUserList = append(MemberInvitedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
|
||||
groupNotification(constant.MemberInvitedNotification, &MemberInvitedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message GroupInfoChangedTips{
|
||||
// int32 ChangedType = 1; //bitwise operators: 1:groupName; 10:Notification 100:Introduction; 1000:FaceUrl
|
||||
// GroupInfo Group = 2;
|
||||
// GroupMemberFullInfo OpUser = 3;
|
||||
//}
|
||||
|
||||
//message MemberLeaveTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo LeaverUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
|
||||
//群成员退群后调用
|
||||
|
||||
//message MemberEnterTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo EntrantUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
//群成员主动申请进群,管理员同意后调用,
|
||||
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberEnterTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberEnterTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.MemberEnterNotification, &MemberEnterTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
|
||||
}
|
@ -1,616 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
//message GroupCreatedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo Creator = 2;
|
||||
// repeated GroupMemberFullInfo MemberList = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(operationID, opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) {
|
||||
return
|
||||
if token_verify.IsMangerUserID(opUserID) {
|
||||
u, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), opUserID)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(groupMemberInfo, u)
|
||||
groupMemberInfo.AppMangerLevel = 1
|
||||
} else {
|
||||
u, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), groupID, opUserID)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(groupMemberInfo, u)
|
||||
}
|
||||
}
|
||||
|
||||
func setGroupInfo(operationID, groupID string, groupInfo *open_im_sdk.GroupInfo, ownerUserID string) {
|
||||
return
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindGroupInfoByGroupId failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(groupInfo, group)
|
||||
|
||||
if ownerUserID != "" {
|
||||
groupInfo.OwnerUserID = ownerUserID
|
||||
// setGroupPublicUserInfo(operationID, groupID, ownerUserID, groupInfo.Owner)
|
||||
}
|
||||
}
|
||||
|
||||
func setGroupMemberInfo(operationID, groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) {
|
||||
return
|
||||
group, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), groupID, userID)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(groupMemberInfo, group)
|
||||
}
|
||||
|
||||
//func setGroupPublicUserInfo(operationID, groupID, userID string, publicUserInfo *open_im_sdk.PublicUserInfo) {
|
||||
// group, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
// if err != nil {
|
||||
// log.NewError(operationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), groupID, userID)
|
||||
// return
|
||||
// }
|
||||
// utils.CopyStructFields(publicUserInfo, group)
|
||||
//}
|
||||
|
||||
//创建群后调用
|
||||
func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string, initMemberList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.RecvID = groupID
|
||||
n.ContentType = constant.GroupCreatedNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
Creator: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setOpUserInfo(operationID, GroupCreatedTips.Creator.UserID, groupID, GroupCreatedTips.Creator)
|
||||
|
||||
setGroupInfo(operationID, groupID, GroupCreatedTips.Group, OwnerUserID)
|
||||
|
||||
for _, v := range initMemberList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
setGroupMemberInfo(operationID, groupID, v, &groupMemberInfo)
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
}
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(GroupCreatedTips)
|
||||
tips.DefaultTips = config.Config.Notification.GroupCreated.DefaultTips.Tips
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, false)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
//} apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
// ReqMessage string `protobuf:"bytes,2,opt,name=ReqMessage" json:"ReqMessage,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,3,opt,name=OpUserID" json:"OpUserID,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//申请进群后调用
|
||||
func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
return
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.JoinApplicationNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.OperationID
|
||||
|
||||
JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}}
|
||||
setGroupInfo(req.OperationID, req.GroupID, JoinGroupApplicationTips.Group, "")
|
||||
|
||||
apply, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID)
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(JoinGroupApplicationTips.Applicant, apply)
|
||||
JoinGroupApplicationTips.Reason = req.ReqMessage
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(JoinGroupApplicationTips)
|
||||
tips.DefaultTips = "JoinGroupApplicationTips"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
for _, v := range managerList {
|
||||
n.RecvID = v.UserID
|
||||
Notification(&n, true)
|
||||
}
|
||||
}
|
||||
|
||||
//message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
//}
|
||||
//处理进群请求后调用
|
||||
func ApplicationProcessedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.ApplicationProcessedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.OperationID
|
||||
n.RecvID = req.FromUserID
|
||||
|
||||
ApplicationProcessedTips := open_im_sdk.ApplicationProcessedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(req.OperationID, req.GroupID, ApplicationProcessedTips.Group, "")
|
||||
setOpUserInfo(req.OperationID, req.OpUserID, req.GroupID, ApplicationProcessedTips.OpUser)
|
||||
ApplicationProcessedTips.Reason = req.HandledMsg
|
||||
ApplicationProcessedTips.Result = req.HandleResult
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(ApplicationProcessedTips)
|
||||
tips.DefaultTips = "ApplicationProcessedNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被邀请进群后调用
|
||||
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.ContentType = constant.MemberInvitedNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
ApplicationProcessedTips := open_im_sdk.MemberInvitedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(operationID, groupID, ApplicationProcessedTips.Group, "")
|
||||
setOpUserInfo(operationID, opUserID, groupID, ApplicationProcessedTips.OpUser)
|
||||
for _, v := range invitedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
setGroupMemberInfo(operationID, groupID, v, &groupMemberInfo)
|
||||
ApplicationProcessedTips.InvitedUserList = append(ApplicationProcessedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(ApplicationProcessedTips)
|
||||
tips.DefaultTips = "MemberInvitedNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
n.RecvID = groupID
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberKickedNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.OperationID
|
||||
|
||||
MemberKickedTips := open_im_sdk.MemberKickedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(req.OperationID, req.GroupID, MemberKickedTips.Group, "")
|
||||
setOpUserInfo(req.OperationID, req.OpUserID, req.GroupID, MemberKickedTips.OpUser)
|
||||
for _, v := range kickedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
setGroupMemberInfo(req.OperationID, req.GroupID, v, &groupMemberInfo)
|
||||
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
|
||||
}
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(MemberKickedTips)
|
||||
tips.DefaultTips = "MemberKickedNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
n.RecvID = req.GroupID
|
||||
Notification(&n, true)
|
||||
|
||||
for _, v := range kickedUserIDList {
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.RecvID = v
|
||||
Notification(&n, true)
|
||||
}
|
||||
}
|
||||
|
||||
//message GroupInfoChangedTips{
|
||||
// int32 ChangedType = 1; //bitwise operators: 1:groupName; 10:Notification 100:Introduction; 1000:FaceUrl
|
||||
// GroupInfo Group = 2;
|
||||
// GroupMemberFullInfo OpUser = 3;
|
||||
//}
|
||||
|
||||
//群信息改变后掉用
|
||||
func GroupInfoChangedNotification(operationID, opUserID, groupID string, changedType int32) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.ContentType = constant.GroupInfoChangedNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
GroupInfoChangedTips := open_im_sdk.GroupInfoChangedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(operationID, groupID, GroupInfoChangedTips.Group, opUserID)
|
||||
setOpUserInfo(operationID, opUserID, groupID, GroupInfoChangedTips.OpUser)
|
||||
GroupInfoChangedTips.ChangedType = changedType
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(GroupInfoChangedTips)
|
||||
tips.DefaultTips = "GroupInfoChangedNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
n.RecvID = groupID
|
||||
Notification(&n, false)
|
||||
}
|
||||
|
||||
/*
|
||||
func GroupInfoChangedNotification(operationID string, changedType int32, group *immysql.Group, opUser *immysql.GroupMember) {
|
||||
var n NotificationMsg
|
||||
n.SendID = opUser.UserID
|
||||
n.RecvID = group.GroupID
|
||||
n.ContentType = constant.ChangeGroupInfoTip
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
var groupInfoChanged open_im_sdk.GroupInfoChangedTips
|
||||
groupInfoChanged.Group = &open_im_sdk.GroupInfo{}
|
||||
utils.CopyStructFields(groupInfoChanged.Group, group)
|
||||
groupInfoChanged.OpUser = &open_im_sdk.GroupMemberFullInfo{}
|
||||
utils.CopyStructFields(groupInfoChanged.OpUser, opUser)
|
||||
groupInfoChanged.ChangedType = changedType
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(groupInfoChanged)
|
||||
tips.DefaultTips = config.Config.Notification.GroupInfoChanged.DefaultTips.Tips
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, false)
|
||||
}
|
||||
*/
|
||||
|
||||
//message MemberLeaveTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo LeaverUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
|
||||
//群成员退群后调用
|
||||
func MemberLeaveNotification(req *pbGroup.QuitGroupReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberLeaveNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.OperationID
|
||||
|
||||
MemberLeaveTips := open_im_sdk.MemberLeaveTips{Group: &open_im_sdk.GroupInfo{}, LeaverUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(req.OperationID, req.GroupID, MemberLeaveTips.Group, "")
|
||||
setOpUserInfo(req.OperationID, req.OpUserID, req.GroupID, MemberLeaveTips.LeaverUser)
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(MemberLeaveTips)
|
||||
tips.DefaultTips = "MemberLeaveNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
n.RecvID = req.GroupID
|
||||
Notification(&n, true)
|
||||
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.RecvID = req.OpUserID
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message MemberEnterTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo EntrantUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
//群成员主动申请进群,管理员同意后调用,
|
||||
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberEnterNotification
|
||||
n.SessionType = constant.GroupChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.OperationID
|
||||
|
||||
MemberLeaveTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
setGroupInfo(req.OperationID, req.GroupID, MemberLeaveTips.Group, "")
|
||||
setOpUserInfo(req.OperationID, req.OpUserID, req.GroupID, MemberLeaveTips.EntrantUser)
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(MemberLeaveTips)
|
||||
tips.DefaultTips = "MemberEnterNotification"
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
n.RecvID = req.GroupID
|
||||
Notification(&n, true)
|
||||
|
||||
}
|
||||
|
||||
//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
|
||||
//}
|
||||
|
||||
func getFromToUserNickname(operationID, fromUserID, toUserID string) (string, string) {
|
||||
return "", ""
|
||||
from, err1 := imdb.GetUserByUserID(fromUserID)
|
||||
to, err2 := imdb.GetUserByUserID(toUserID)
|
||||
if err1 != nil || err2 != nil {
|
||||
log.NewError("FindUserByUID failed ", err1, err2, fromUserID, toUserID)
|
||||
}
|
||||
fromNickname, toNickname := "", ""
|
||||
if from != nil {
|
||||
fromNickname = from.Nickname
|
||||
}
|
||||
if to != nil {
|
||||
toNickname = to.Nickname
|
||||
}
|
||||
return fromNickname, toNickname
|
||||
}
|
||||
|
||||
func FriendApplicationAddedNotification(req *pbFriend.AddFriendReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
n.ContentType = constant.FriendApplicationAddedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.CommID.OperationID
|
||||
|
||||
var FriendApplicationAddedTips open_im_sdk.FriendApplicationAddedTips
|
||||
FriendApplicationAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(req.CommID.OperationID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(FriendApplicationAddedTips)
|
||||
tips.DefaultTips = fromUserNickname + " FriendApplicationAddedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
func FriendApplicationProcessedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
n.ContentType = constant.FriendApplicationProcessedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = req.CommID.OperationID
|
||||
|
||||
var FriendApplicationProcessedTips open_im_sdk.FriendApplicationProcessedTips
|
||||
FriendApplicationProcessedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationProcessedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(req.CommID.OperationID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(FriendApplicationProcessedTips)
|
||||
tips.DefaultTips = fromUserNickname + " FriendApplicationProcessedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = fromUserID
|
||||
n.RecvID = toUserID
|
||||
n.ContentType = constant.FriendAddedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
var FriendAddedTips open_im_sdk.FriendAddedTips
|
||||
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), opUserID)
|
||||
|
||||
} else {
|
||||
utils.CopyStructFields(FriendAddedTips.OpUser, user)
|
||||
}
|
||||
|
||||
friend, err := imdb.GetFriendRelationshipFromFriend(fromUserID, toUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), fromUserID, toUserID)
|
||||
} else {
|
||||
FriendAddedTips.Friend.Remark = friend.Remark
|
||||
}
|
||||
|
||||
from, err := imdb.GetUserByUserID(fromUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), fromUserID)
|
||||
|
||||
} else {
|
||||
utils.CopyStructFields(FriendAddedTips.Friend, from)
|
||||
}
|
||||
|
||||
to, err := imdb.GetUserByUserID(toUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), toUserID)
|
||||
|
||||
} else {
|
||||
utils.CopyStructFields(FriendAddedTips.Friend.FriendUser, to)
|
||||
}
|
||||
|
||||
fromUserNickname, toUserNickname := from.Nickname, to.Nickname
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(FriendAddedTips)
|
||||
tips.DefaultTips = fromUserNickname + " FriendAddedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message FriendDeletedTips{
|
||||
// FriendInfo Friend = 1;
|
||||
//}
|
||||
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
return
|
||||
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
|
||||
|
||||
var FriendDeletedTips open_im_sdk.FriendDeletedTips
|
||||
FriendDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(req.CommID.OperationID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(FriendDeletedTips)
|
||||
tips.DefaultTips = fromUserNickname + " FriendDeletedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message FriendInfoChangedTips{
|
||||
// FriendInfo Friend = 1;
|
||||
// PublicUserInfo OpUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
func FriendInfoChangedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = fromUserID
|
||||
n.RecvID = toUserID
|
||||
n.ContentType = constant.FriendInfoChangedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
var FriendInfoChangedTips open_im_sdk.FriendInfoChangedTips
|
||||
FriendInfoChangedTips.FromToUserID.FromUserID = fromUserID
|
||||
FriendInfoChangedTips.FromToUserID.ToUserID = toUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(operationID, fromUserID, toUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(FriendInfoChangedTips)
|
||||
tips.DefaultTips = fromUserNickname + " FriendDeletedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
return
|
||||
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
|
||||
|
||||
var BlackAddedTips open_im_sdk.BlackAddedTips
|
||||
BlackAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
BlackAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(req.CommID.OperationID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(BlackAddedTips)
|
||||
tips.DefaultTips = fromUserNickname + " BlackAddedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message BlackDeletedTips{
|
||||
// BlackInfo Black = 1;
|
||||
//}
|
||||
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
return
|
||||
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
|
||||
|
||||
var BlackDeletedTips open_im_sdk.BlackDeletedTips
|
||||
BlackDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
BlackDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
fromUserNickname, toUserNickname := getFromToUserNickname(req.CommID.OperationID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, _ = json.Marshal(BlackDeletedTips)
|
||||
tips.DefaultTips = fromUserNickname + " BlackDeletedNotification " + toUserNickname
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
||||
|
||||
//message SelfInfoUpdatedTips{
|
||||
// UserInfo SelfUserInfo = 1;
|
||||
// PublicUserInfo OpUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
func SelfInfoUpdatedNotification(operationID, userID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = userID
|
||||
n.RecvID = userID
|
||||
n.ContentType = constant.SelfInfoUpdatedNotification
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
|
||||
var SelfInfoUpdatedTips open_im_sdk.SelfInfoUpdatedTips
|
||||
SelfInfoUpdatedTips.UserID = userID
|
||||
|
||||
var tips open_im_sdk.TipsComm
|
||||
u, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindUserByUID failed ", err.Error(), userID)
|
||||
}
|
||||
|
||||
tips.Detail, _ = json.Marshal(SelfInfoUpdatedTips)
|
||||
tips.DefaultTips = u.Nickname + " SelfInfoUpdatedNotification "
|
||||
n.Content, _ = json.Marshal(tips)
|
||||
Notification(&n, true)
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package base_info
|
||||
|
||||
import sts "github.com/tencentyun/qcloud-cos-sts-sdk/go"
|
||||
|
||||
type TencentCloudStorageCredentialReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
type TencentCloudStorageCredentialRespData struct {
|
||||
*sts.CredentialResult
|
||||
Region string `json:"region"`
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
|
||||
type TencentCloudStorageCredentialResp struct {
|
||||
CommResp
|
||||
Data TencentCloudStorageCredentialRespData `json:"data"`
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue