Merge remote-tracking branch 'origin/tuoyun' into tuoyun

This commit is contained in:
Gordon
2022-04-21 12:53:39 +08:00
7 changed files with 320 additions and 243 deletions
+17 -7
View File
@@ -4,28 +4,38 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
pbOffice "Open_IM/pkg/proto/office"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
log.NewInfo(operationID, utils.GetSelfFuncName(), recvID)
bytes, err := proto.Marshal(notificationMsg)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "proto marshal failed", err.Error())
}
WorkMomentNotification(operationID, sendID, recvID, bytes)
WorkMomentNotification(operationID, sendID, recvID, notificationMsg)
}
func WorkMomentNotification(operationID, sendID, recvID string, content []byte) {
func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) {
marshaler := jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: false,
}
var tips open_im_sdk.TipsComm
var err error
tips.JsonDetail, _ = marshaler.MarshalToString(m)
n := &NotificationMsg{
SendID: sendID,
RecvID: recvID,
Content: content,
MsgFrom: constant.UserMsgType,
ContentType: constant.WorkMomentNotification,
SessionType: constant.UserMsgType,
OperationID: operationID,
}
n.Content, err = proto.Marshal(m)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "proto marshal falied", err.Error())
return
}
Notification(n)
}
+13 -20
View File
@@ -280,23 +280,12 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
workMoment.UserName = createUser.Nickname
workMoment.FaceURL = createUser.FaceURL
if err := utils.CopyStructFields(&workMoment, req.WorkMoment); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupIDList, req.WorkMoment.PermissionUserIDList)
for _, userID := range req.WorkMoment.AtUserIDList {
userName, err := imdb.GetUserNameByUserID(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", userID, err.Error())
continue
}
workMoment.AtUserList = append(workMoment.AtUserList, &db.AtUser{
UserID: userID,
UserName: userName,
})
}
workMoment.UserName = createUser.Nickname
workMoment.FaceURL = createUser.FaceURL
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
err = db.DB.CreateOneWorkMoment(&workMoment)
if err != nil {
@@ -306,7 +295,7 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
}
// send notification to at users
for _, atUser := range req.WorkMoment.AtUserIDList {
for _, atUser := range req.WorkMoment.AtUserList {
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
NotificationMsgType: constant.WorkMomentAtUserNotification,
WorkMomentID: workMoment.WorkMomentID,
@@ -315,23 +304,27 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
FaceURL: createUser.FaceURL,
UserName: createUser.Nickname,
}
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser, workMomentNotificationMsg)
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser.UserID, workMomentNotificationMsg)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
// count and distinct permission users
func (s *officeServer) getPermissionUserIDList(operationID string, groupIDList, userIDList []string) []string {
func (s *officeServer) getPermissionUserIDList(operationID string, groupList []*pbOffice.PermissionGroup, userList []*pbOffice.WorkMomentUser) []string {
var permissionUserIDList []string
for _, groupID := range groupIDList {
GroupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
for _, group := range groupList {
GroupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(group.GroupID)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", groupID, err.Error())
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", group, err.Error())
continue
}
permissionUserIDList = append(permissionUserIDList, GroupMemberIDList...)
}
var userIDList []string
for _, user := range userList {
userIDList = append(userIDList, user.UserID)
}
permissionUserIDList = append(permissionUserIDList, userIDList...)
permissionUserIDList = utils.RemoveRepeatedStringInList(permissionUserIDList)
return permissionUserIDList