Refactor code

pull/141/head
wenxu12345 3 years ago
parent 6f411e96ed
commit 4d172ec4f5

@ -141,7 +141,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
resp.ErrMsg = constant.ErrDB.ErrMsg
return resp, nil
}
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, req.OwnerUserID, groupId, okUserIDList)
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
utils.CopyStructFields(resp.GroupInfo, group)
resp.GroupInfo.MemberCount, err = imdb.GetGroupMemberNumByGroupID(groupId)
if err != nil {

@ -1,6 +1,7 @@
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"
@ -72,19 +73,12 @@ func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.Gro
//}
//创建群后调用
func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string, initMemberList []string) {
var n NotificationMsg
n.SendID = opUserID
n.RecvID = groupID
n.ContentType = constant.GroupCreatedNotification
n.SessionType = constant.GroupChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberList []string) {
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
Creator: &open_im_sdk.GroupMemberFullInfo{}}
if err := setOpUserInfo(GroupCreatedTips.Creator.UserID, groupID, GroupCreatedTips.Creator); err != nil {
log.NewError(operationID, "setOpUserInfo failed ", err.Error(), GroupCreatedTips.Creator.UserID, groupID, GroupCreatedTips.Creator)
return
}
err := setGroupInfo(groupID, GroupCreatedTips.Group)
if err != nil {
@ -99,6 +93,13 @@ func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(GroupCreatedTips)
tips.DefaultTips = config.Config.Notification.GroupCreated.DefaultTips.Tips
var n NotificationMsg
n.SendID = opUserID
n.RecvID = groupID
n.ContentType = constant.GroupCreatedNotification
n.SessionType = constant.GroupChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
n.Content, _ = json.Marshal(tips)
log.NewInfo(operationID, "Notification ", n)
Notification(&n)
@ -114,13 +115,6 @@ func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
//申请进群后调用
func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
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{}}
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
if err != nil {
@ -139,6 +133,12 @@ func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(JoinGroupApplicationTips)
tips.DefaultTips = "JoinGroupApplicationTips"
var n NotificationMsg
n.SendID = req.OpUserID
n.ContentType = constant.JoinApplicationNotification
n.SessionType = constant.SingleChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.OperationID
n.Content, _ = json.Marshal(tips)
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
if err != nil {
@ -160,24 +160,29 @@ func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
//}
//处理进群请求后调用
func ApplicationProcessedNotification(req *pbGroup.GroupApplicationResponseReq) {
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.GroupID, ApplicationProcessedTips.Group)
setOpUserInfo(req.OpUserID, req.GroupID, ApplicationProcessedTips.OpUser)
if err := setGroupInfo(req.GroupID, ApplicationProcessedTips.Group); err != nil {
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, ApplicationProcessedTips.Group)
return
}
if err := setOpUserInfo(req.OpUserID, req.GroupID, ApplicationProcessedTips.OpUser); err != nil {
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, ApplicationProcessedTips.OpUser)
return
}
ApplicationProcessedTips.Reason = req.HandledMsg
ApplicationProcessedTips.Result = req.HandleResult
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(ApplicationProcessedTips)
tips.DefaultTips = "ApplicationProcessedNotification"
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
n.Content, _ = json.Marshal(tips)
Notification(&n)
}
@ -189,24 +194,32 @@ func ApplicationProcessedNotification(req *pbGroup.GroupApplicationResponseReq)
//}
//被邀请进群后调用
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
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(groupID, ApplicationProcessedTips.Group)
setOpUserInfo(opUserID, groupID, ApplicationProcessedTips.OpUser)
if err := setGroupInfo(groupID, ApplicationProcessedTips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, ApplicationProcessedTips.Group)
return
}
if err := setOpUserInfo(opUserID, groupID, ApplicationProcessedTips.OpUser); err != nil {
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID, ApplicationProcessedTips.OpUser)
return
}
for _, v := range invitedUserIDList {
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
setGroupMemberInfo(groupID, v, &groupMemberInfo)
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
log.Error(operationID, "setGroupMemberInfo faield ", err.Error(), groupID)
continue
}
ApplicationProcessedTips.InvitedUserList = append(ApplicationProcessedTips.InvitedUserList, &groupMemberInfo)
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(ApplicationProcessedTips)
tips.DefaultTips = "MemberInvitedNotification"
var n NotificationMsg
n.SendID = opUserID
n.ContentType = constant.MemberInvitedNotification
n.SessionType = constant.GroupChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = operationID
n.Content, _ = json.Marshal(tips)
n.RecvID = groupID
Notification(&n)
@ -220,33 +233,42 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
//}
//被踢后调用
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
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.GroupID, MemberKickedTips.Group)
setOpUserInfo(req.OpUserID, req.GroupID, MemberKickedTips.OpUser)
if err := setGroupInfo(req.GroupID, MemberKickedTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberKickedTips.Group)
return
}
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberKickedTips.OpUser); err != nil {
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberKickedTips.OpUser)
return
}
for _, v := range kickedUserIDList {
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
setGroupMemberInfo(req.GroupID, v, &groupMemberInfo)
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)
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(MemberKickedTips)
tips.DefaultTips = "MemberKickedNotification"
var n NotificationMsg
n.SendID = req.OpUserID
n.ContentType = constant.MemberKickedNotification
n.SessionType = constant.GroupChatType
n.MsgFrom = constant.SysMsgType
n.OperationID = req.OperationID
n.Content, _ = json.Marshal(tips)
n.RecvID = req.GroupID
Notification(&n)
for _, v := range kickedUserIDList {
n.SessionType = constant.SingleChatType
n.RecvID = v
Notification(&n)
m := n
m.SessionType = constant.SingleChatType
m.RecvID = v
Notification(&m)
}
}
@ -258,49 +280,29 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
//群信息改变后掉用
func GroupInfoChangedNotification(operationID, opUserID, groupID string, changedType int32) {
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(groupID, GroupInfoChangedTips.Group)
setOpUserInfo(opUserID, groupID, GroupInfoChangedTips.OpUser)
if err := setGroupInfo(groupID, GroupInfoChangedTips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, GroupInfoChangedTips.Group)
return
}
if err := setOpUserInfo(opUserID, groupID, GroupInfoChangedTips.OpUser); err != nil {
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID, GroupInfoChangedTips.OpUser)
return
}
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)
}
/*
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.SendID = opUserID
n.ContentType = constant.GroupInfoChangedNotification
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)
n.RecvID = groupID
Notification(&n)
}
*/
//message MemberLeaveTips{
// GroupInfo Group = 1;
@ -310,27 +312,33 @@ func GroupInfoChangedNotification(operationID string, changedType int32, group *
//群成员退群后调用
func MemberLeaveNotification(req *pbGroup.QuitGroupReq) {
MemberLeaveTips := open_im_sdk.MemberLeaveTips{Group: &open_im_sdk.GroupInfo{}, LeaverUser: &open_im_sdk.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, MemberLeaveTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberLeaveTips.Group)
return
}
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberLeaveTips.LeaverUser); err != nil {
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberLeaveTips.LeaverUser)
return
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(MemberLeaveTips)
tips.DefaultTips = "MemberLeaveNotification"
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.GroupID, MemberLeaveTips.Group)
setOpUserInfo(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)
m := n
n.SessionType = constant.SingleChatType
n.RecvID = req.OpUserID
Notification(&n)
Notification(&m)
}
//message MemberEnterTips{
@ -340,22 +348,25 @@ func MemberLeaveNotification(req *pbGroup.QuitGroupReq) {
//}
//群成员主动申请进群,管理员同意后调用,
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
MemberLeaveTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, MemberLeaveTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberLeaveTips.Group)
return
}
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberLeaveTips.EntrantUser); err != nil {
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberLeaveTips.EntrantUser)
return
}
var tips open_im_sdk.TipsComm
tips.Detail, _ = json.Marshal(MemberLeaveTips)
tips.DefaultTips = "MemberEnterNotification"
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.GroupID, MemberLeaveTips.Group)
setOpUserInfo(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)
}

@ -54,7 +54,7 @@ type GetJoinedGroupListReq struct {
}
type GetJoinedGroupListResp struct {
CommResp
GroupInfoList []*open_im_sdk.GroupInfo
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
Data []map[string]interface{} `json:"data"`
}
@ -66,9 +66,9 @@ type GetGroupMemberListReq struct {
}
type GetGroupMemberListResp struct {
CommResp
NextSeq int32 `json:"nextSeq"`
MemberList []*open_im_sdk.GroupMemberFullInfo
Data []map[string]interface{} `json:"data"`
NextSeq int32 `json:"nextSeq"`
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
Data []map[string]interface{} `json:"data"`
}
type GetGroupAllMemberReq struct {
@ -90,7 +90,7 @@ type CreateGroupReq struct {
}
type CreateGroupResp struct {
CommResp
GroupInfo open_im_sdk.GroupInfo
GroupInfo open_im_sdk.GroupInfo `jason:-`
Data map[string]interface{} `json:"data"`
}
@ -100,8 +100,8 @@ type GetGroupApplicationListReq struct {
}
type GetGroupApplicationListResp struct {
CommResp
GroupRequestList []*open_im_sdk.GroupRequest
Data []map[string]interface{} `json:"data"`
GroupRequestList []*open_im_sdk.GroupRequest `json:"-"`
Data []map[string]interface{} `json:"data"`
}
type GetGroupInfoReq struct {
@ -110,7 +110,7 @@ type GetGroupInfoReq struct {
}
type GetGroupInfoResp struct {
CommResp
GroupInfoList []*open_im_sdk.GroupInfo
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
Data []map[string]interface{} `json:"data"`
}

@ -88,33 +88,25 @@ func initRotateLogs(rotationTime time.Duration, maxRemainNum uint, level string,
}
}
//Deprecated
func Info(token, OperationID, format string, args ...interface{}) {
func Info(OperationID string, args ...interface{}) {
logger.WithFields(logrus.Fields{
"PID": logger.Pid,
"OperationID": OperationID,
}).Infof(format, args...)
"PID": logger.Pid,
}).Infoln(args)
}
//Deprecated
func Error(token, OperationID, format string, args ...interface{}) {
func Error(OperationID string, args ...interface{}) {
logger.WithFields(logrus.Fields{
"PID": logger.Pid,
"OperationID": OperationID,
}).Errorf(format, args...)
"PID": logger.Pid,
}).Errorln(args)
}
//Deprecated
func Debug(token, OperationID, format string, args ...interface{}) {
func Debug(OperationID string, args ...interface{}) {
logger.WithFields(logrus.Fields{
"PID": logger.Pid,
"OperationID": OperationID,
}).Debugf(format, args...)
"PID": logger.Pid,
}).Debugln(args)
}
//Deprecated

Loading…
Cancel
Save