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

pull/218/head
Gordon 3 years ago
commit d44d5711cb

@ -148,8 +148,6 @@ func main() {
officeGroup.POST("/get_work_moment_by_id", office.GetWorkMomentByID)
officeGroup.POST("/get_user_work_moments", office.GetUserWorkMoments)
officeGroup.POST("/get_user_friend_work_moments", office.GetUserFriendWorkMoments)
officeGroup.POST("/get_user_work_moments_comments_msg", office.GetUserWorkMomentsCommentsMsg)
officeGroup.POST("/clear_user_work_moments_comments_msg", office.ClearUserWorkMomentsCommentsMsg)
officeGroup.POST("/set_user_work_moments_level", office.SetUserWorkMomentsLevel)
}

@ -201,7 +201,10 @@ func GetWorkMomentByID(c *gin.Context) {
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp.Data.WorkMoment = respPb.WorkMoment
//resp.Data.WorkMoment = respPb.WorkMoment
if err := utils.CopyStructFields(&resp.Data.WorkMoment, respPb.WorkMoment); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
@ -242,7 +245,9 @@ func GetUserWorkMoments(c *gin.Context) {
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp.Data.WorkMoments = respPb.WorkMoments
if err := utils.CopyStructFields(&resp.Data.WorkMoments, respPb.WorkMoments); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
@ -285,52 +290,11 @@ func GetUserFriendWorkMoments(c *gin.Context) {
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp.Data.WorkMoments = respPb.WorkMoments
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func GetUserWorkMomentsCommentsMsg(c *gin.Context) {
var (
req apiStruct.GetUserWorkMomentsCommentsMsgReq
resp apiStruct.GetUserWorkMomentsCommentsMsgResp
reqPb pbOffice.GetUserWorkMomentsCommentsMsgReq
respPb *pbOffice.GetUserWorkMomentsCommentsMsgResp
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
reqPb.OperationID = req.OperationID
reqPb.Pagination = &pbCommon.RequestPagination{
PageNumber: req.PageNumber,
ShowNumber: req.ShowNumber,
}
reqPb.UserID = userID
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
client := pbOffice.NewOfficeServiceClient(etcdConn)
respPb, err := client.GetUserWorkMomentsCommentsMsg(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMomentsCommentsMsg rpc failed", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserWorkMomentsCommentsMsg rpc server failed" + err.Error()})
return
}
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
if err := utils.CopyStructFields(&resp.Data.WorkMoments, respPb.WorkMoments); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
resp.Data.CommentMsgs = respPb.CommentsMsgs
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
@ -372,39 +336,3 @@ func SetUserWorkMomentsLevel(c *gin.Context) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func ClearUserWorkMomentsCommentsMsg(c *gin.Context) {
var (
req apiStruct.ClearUserWorkMomentsCommentsMsgReq
resp apiStruct.ClearUserWorkMomentsCommentsMsgResp
reqPb pbOffice.ClearUserWorkMomentsCommentsMsgReq
respPb *pbOffice.ClearUserWorkMomentsCommentsMsgResp
)
if err := c.BindJSON(&req); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
reqPb.UserID = userID
reqPb.OperationID = req.OperationID
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
client := pbOffice.NewOfficeServiceClient(etcdConn)
respPb, err := client.ClearUserWorkMomentsCommentsMsg(context.Background(), &reqPb)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ClearUserWorkMomentsCommentsMsg rpc failed", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "ClearUserWorkMomentsCommentsMsg rpc server failed" + err.Error()})
return
}
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}

@ -1,47 +1,31 @@
package msg
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/chat"
pbCommon "Open_IM/pkg/proto/sdk_ws"
pbOffice "Open_IM/pkg/proto/office"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"strings"
"github.com/golang/protobuf/proto"
)
func CommentOneWorkMomentNotification(operationID, recvID string, comment db.CommentMsg, user db.User) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", recvID, user, comment)
var req pbChat.SendMsgReq
var msgData pbCommon.MsgData
msgData.SendID = user.UserID
msgData.RecvID = recvID
msgData.ContentType = constant.WorkMomentNewCommentNotification
msgData.SessionType = constant.SingleChatType
msgData.MsgFrom = constant.UserMsgType
bytes, err := json.Marshal(comment)
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(), "marshal failed", err.Error())
log.NewError(operationID, utils.GetSelfFuncName(), "proto marshal failed", err.Error())
}
msgData.Content = bytes
msgData.SenderFaceURL = user.FaceURL
msgData.SenderNickname = user.Nickname
msgData.CreateTime = utils.GetCurrentTimestampByMill()
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
req.MsgData = &msgData
req.OperationID = operationID
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
client := pbChat.NewChatClient(etcdConn)
respPb, err := client.SendMsg(context.Background(), &req)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
return
}
if respPb.ErrCode != 0 {
log.NewError(operationID, utils.GetSelfFuncName(), "send tag msg failed ", respPb)
WorkMomentNotification(operationID, sendID, recvID, bytes)
}
func WorkMomentNotification(operationID, sendID, recvID string, content []byte) {
n := &NotificationMsg{
SendID: sendID,
RecvID: recvID,
Content: content,
MsgFrom: constant.UserMsgType,
ContentType: constant.WorkMomentNotification,
SessionType: constant.UserMsgType,
OperationID: operationID,
}
Notification(n)
}

@ -270,20 +270,73 @@ func (s *officeServer) GetUserTagByID(_ context.Context, req *pbOffice.GetUserTa
func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.CreateOneWorkMomentReq) (resp *pbOffice.CreateOneWorkMomentResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.CreateOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
workMoment := db.WorkMoment{Comments: []*db.Comment{}, LikeUsers: []*db.LikeUser{}}
workMoment := db.WorkMoment{
Comments: []*db.Comment{},
LikeUserList: []*db.LikeUser{},
}
createUser, err := imdb.GetUserByUserID(req.WorkMoment.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
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,
})
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
err = db.DB.CreateOneWorkMoment(&workMoment)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateOneWorkMoment", err.Error())
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
// send notification to at users
for _, atUser := range req.WorkMoment.AtUserIDList {
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
NotificationMsgType: constant.WorkMomentAtUserNotification,
WorkMomentID: workMoment.WorkMomentID,
WorkMomentContent: workMoment.Content,
UserID: workMoment.UserID,
FaceURL: createUser.FaceURL,
UserName: createUser.Nickname,
}
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser, 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 {
var permissionUserIDList []string
for _, groupID := range groupIDList {
GroupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
if err != nil {
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", groupID, err.Error())
continue
}
permissionUserIDList = append(permissionUserIDList, GroupMemberIDList...)
}
permissionUserIDList = append(permissionUserIDList, userIDList...)
permissionUserIDList = utils.RemoveRepeatedStringInList(permissionUserIDList)
return permissionUserIDList
}
func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.DeleteOneWorkMomentReq) (resp *pbOffice.DeleteOneWorkMomentResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.DeleteOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
@ -295,7 +348,7 @@ func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.Dele
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment", workMoment)
if workMoment.UserID != req.UserID {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoment.UserID != req.WorkMomentID ", workMoment, req.WorkMomentID)
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoment.UserID != req.WorkMomentID, delete failed", workMoment, req.WorkMomentID)
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}
return resp, nil
}
@ -311,15 +364,17 @@ func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.Dele
func isUserCanSeeWorkMoment(userID string, workMoment db.WorkMoment) bool {
if userID != workMoment.UserID {
if utils.IsContain(userID, workMoment.WhoCantSeeUserIDList) {
return false
}
if utils.IsContain(userID, workMoment.WhoCanSeeUserIDList) {
switch workMoment.Permission {
case constant.WorkMomentPublic:
return true
}
if workMoment.IsPrivate {
case constant.WorkMomentPrivate:
return false
case constant.WorkMomentPermissionCanSee:
return utils.IsContain(userID, workMoment.PermissionUserIDList)
case constant.WorkMomentPermissionCantSee:
return !utils.IsContain(userID, workMoment.PermissionUserIDList)
}
return false
}
return true
}
@ -333,11 +388,20 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
if err = db.DB.LikeOneWorkMoment(req.UserID, userName, req.WorkMomentID); err != nil {
workMoment, err := db.DB.LikeOneWorkMoment(req.UserID, userName, req.WorkMomentID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
NotificationMsgType: constant.WorkMomentLikeNotification,
WorkMomentID: workMoment.WorkMomentID,
WorkMomentContent: workMoment.Content,
UserID: workMoment.UserID,
}
// send notification
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
@ -360,7 +424,7 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
return resp, nil
}
}
comment := db.Comment{
comment := &db.Comment{
UserID: req.UserID,
UserName: commentUser.Nickname,
ReplyUserID: req.ReplyUserID,
@ -374,18 +438,25 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
commentMsg := db.CommentMsg{
Comment: comment,
UserID: workMoment.UserID,
WorkMomentID: workMoment.WorkMomentID,
WorkMomentContent: workMoment.Content,
}
if err = db.DB.CreateUserWorkMomentsCommentsMsg(commentMsg); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
NotificationMsgType: constant.WorkMomentCommentNotification,
WorkMomentID: workMoment.WorkMomentID,
WorkMomentContent: workMoment.Content,
UserID: workMoment.UserID,
Comment: &pbOffice.Comment{
UserID: comment.UserID,
UserName: comment.UserName,
FaceURL: commentUser.FaceURL,
ReplyUserID: comment.ReplyUserID,
ReplyUserName: comment.ReplyUserName,
ContentID: comment.ContentID,
Content: comment.Content,
CreateTime: comment.CreateTime,
},
}
msg.CommentOneWorkMomentNotification(req.OperationID, workMoment.UserID, commentMsg, *commentUser)
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
if req.ReplyUserID != "" {
msg.CommentOneWorkMomentNotification(req.OperationID, req.ReplyUserID, commentMsg, *commentUser)
msg.WorkMomentSendNotification(req.OperationID, req.UserID, req.ReplyUserID, workMomentNotificationMsg)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
@ -405,6 +476,9 @@ func (s *officeServer) GetWorkMomentByID(_ context.Context, req *pbOffice.GetWor
}
canSee := isUserCanSeeWorkMoment(req.OpUserID, *workMoment)
log.Debug(req.OperationID, utils.GetSelfFuncName(), canSee, req.OpUserID, *workMoment)
if !canSee {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoments not access to user", canSee, workMoment, req.OpUserID)
}
if err := utils.CopyStructFields(resp.WorkMoment, workMoment); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
}
@ -455,34 +529,6 @@ func (s *officeServer) GetUserFriendWorkMoments(_ context.Context, req *pbOffice
return resp, nil
}
func (s *officeServer) GetUserWorkMomentsCommentsMsg(_ context.Context, req *pbOffice.GetUserWorkMomentsCommentsMsgReq) (resp *pbOffice.GetUserWorkMomentsCommentsMsgResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.GetUserWorkMomentsCommentsMsgResp{CommonResp: &pbOffice.CommonResp{}}
resp.CommentsMsgs = make([]*pbOffice.CommentsMsg, 0)
workMomentsCommentMsgs, err := db.DB.GetUserWorkMomentsCommentsMsg(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMomentsCommentsMsg", err.Error())
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMomentsCommentMsgs: ", workMomentsCommentMsgs)
for _, commentMsg := range workMomentsCommentMsgs {
comment := pbOffice.Comment{}
if err := utils.CopyStructFields(&comment, commentMsg); err != nil {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
resp.CommentsMsgs = append(resp.CommentsMsgs, &pbOffice.CommentsMsg{
Comment: &comment,
WorkMomentID: commentMsg.WorkMomentID,
Content: commentMsg.WorkMomentContent,
UserID: req.UserID,
})
}
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
func (s *officeServer) SetUserWorkMomentsLevel(_ context.Context, req *pbOffice.SetUserWorkMomentsLevelReq) (resp *pbOffice.SetUserWorkMomentsLevelResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.SetUserWorkMomentsLevelResp{CommonResp: &pbOffice.CommonResp{}}
@ -495,14 +541,9 @@ func (s *officeServer) SetUserWorkMomentsLevel(_ context.Context, req *pbOffice.
return resp, nil
}
func (s *officeServer) ClearUserWorkMomentsCommentsMsg(_ context.Context, req *pbOffice.ClearUserWorkMomentsCommentsMsgReq) (resp *pbOffice.ClearUserWorkMomentsCommentsMsgResp, err error) {
func (s *officeServer) ChangeWorkMomentPermission(_ context.Context, req *pbOffice.ChangeWorkMomentPermissionReq) (resp *pbOffice.ChangeWorkMomentPermissionResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.ClearUserWorkMomentsCommentsMsgResp{CommonResp: &pbOffice.CommonResp{}}
if err := db.DB.ClearUserWorkMomentsCommentsMsg(req.UserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ClearUserWorkMomentsCommentsMsg", err.Error())
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil
}
resp = &pbOffice.ChangeWorkMomentPermissionResp{CommonResp: &pbOffice.CommonResp{}}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}

@ -44,10 +44,38 @@ type GetWorkMomentByIDReq struct {
office.GetWorkMomentByIDReq
}
type WorkMoment struct {
WorkMomentID string `json:"workMomentID"`
UserID string `json:"userID"`
Content string `json:"content"`
LikeUsers []*LikeUser `json:"likeUsers"`
Comments []*Comment `json:"comments"`
Permission int32 `json:"permission"`
PermissionUserIDList []string `json:"permissionUserIDList"`
PermissionGroupIDList []string `json:"permissionGroupIDList"`
AtUserIDList []string `json:"atUserIDList"`
CreateTime int32 `json:"createTime,omitempty"`
}
type LikeUser struct {
UserID string `json:"userID"`
UserName string `json:"userName"`
}
type Comment struct {
UserID string `json:"userID"`
UserName string `json:"userName"`
ReplyUserID string `json:"replyUserID"`
ReplyUserName string `json:"replyUserName"`
ContentID string `json:"contentID"`
Content string `json:"content"`
CreateTime int32 `json:"createTime"`
}
type GetWorkMomentByIDResp struct {
CommResp
Data struct {
WorkMoment *office.WorkMoment `json:"workMoment"`
WorkMoment *WorkMoment `json:"workMoment"`
} `json:"data"`
}
@ -58,9 +86,9 @@ type GetUserWorkMomentsReq struct {
type GetUserWorkMomentsResp struct {
CommResp
Data struct {
WorkMoments []*office.WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
WorkMoments []*WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
@ -71,22 +99,9 @@ type GetUserFriendWorkMomentsReq struct {
type GetUserFriendWorkMomentsResp struct {
CommResp
Data struct {
WorkMoments []*office.WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
type GetUserWorkMomentsCommentsMsgReq struct {
WorkMomentsUserCommonReq
}
type GetUserWorkMomentsCommentsMsgResp struct {
CommResp
Data struct {
CommentMsgs []*office.CommentsMsg `json:"comments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
WorkMoments []*WorkMoment `json:"workMoments"`
CurrentPage int32 `json:"currentPage"`
ShowNumber int32 `json:"showNumber"`
} `json:"data"`
}
@ -97,11 +112,3 @@ type SetUserWorkMomentsLevelReq struct {
type SetUserWorkMomentsLevelResp struct {
CommResp
}
type ClearUserWorkMomentsCommentsMsgReq struct {
office.ClearUserWorkMomentsCommentsMsgReq
}
type ClearUserWorkMomentsCommentsMsgResp struct {
CommResp
}

@ -91,8 +91,8 @@ const (
OrganizationChangedNotification = 1801
WorkMomentNotificationStart = 1900
WorkMomentNewCommentNotification = 1901
WorkMomentNotificationBegin = 1900
WorkMomentNotification = 1901
NotificationEnd = 2000
@ -183,6 +183,17 @@ const (
OtherType = 1
VideoType = 2
ImageType = 3
// workMoment permission
WorkMomentPublic = 0
WorkMomentPrivate = 1
WorkMomentPermissionCanSee = 2
WorkMomentPermissionCantSee = 3
// workMoment sdk notification type
WorkMomentCommentNotification = 0
WorkMomentLikeNotification = 1
WorkMomentAtUserNotification = 2
)
var ContentType2PushContent = map[int64]string{

@ -568,15 +568,22 @@ func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32)
type WorkMoment struct {
WorkMomentID string `bson:"work_moment_id"`
UserID string `bson:"user_id"`
UserName string `bson:"user_name"`
FaceURL string `bson:"face_url"`
Content string `bson:"content"`
LikeUsers []*LikeUser `bson:"like_users"`
LikeUserList []*LikeUser `bson:"like_user_list"`
AtUserList []*AtUser `bson:"at_user_list"`
Comments []*Comment `bson:"comments"`
WhoCanSeeUserIDList []string `bson:"who_can_see_user_id_list"`
WhoCantSeeUserIDList []string `bson:"who_cant_see_user_id_list"`
IsPrivate bool `bson:"is_private"`
PermissionUserIDList []string `bson:"permission_user_id_list"`
Permission int32 `bson:"is_private"`
CreateTime int32 `bson:"create_time"`
}
type AtUser struct {
UserID string `bson:"user_id"`
UserName string `bson:"user_name"`
}
type LikeUser struct {
UserID string `bson:"user_id"`
UserName string `bson:"user_name"`
@ -617,67 +624,33 @@ func (d *DataBases) GetWorkMomentByID(workMomentID string) (*WorkMoment, error)
return workMoment, err
}
func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string) error {
func (d *DataBases) LikeOneWorkMoment(likeUserID, userName, workMomentID string) (*WorkMoment, error) {
workMoment, err := d.GetWorkMomentByID(workMomentID)
if err != nil {
return err
return nil, err
}
var isAlreadyLike bool
for i, user := range workMoment.LikeUsers {
for i, user := range workMoment.LikeUserList {
if likeUserID == user.UserID {
isAlreadyLike = true
workMoment.LikeUsers = append(workMoment.LikeUsers[0:i], workMoment.LikeUsers[i+1:]...)
workMoment.LikeUserList = append(workMoment.LikeUserList[0:i], workMoment.LikeUserList[i+1:]...)
}
}
if !isAlreadyLike {
workMoment.LikeUsers = append(workMoment.LikeUsers, &LikeUser{UserID: likeUserID, UserName: userName})
workMoment.LikeUserList = append(workMoment.LikeUserList, &LikeUser{UserID: likeUserID, UserName: userName})
}
log.Info("", utils.GetSelfFuncName(), workMoment)
log.NewDebug("", utils.GetSelfFuncName(), workMoment)
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
_, err = c.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_users": workMoment.LikeUsers}})
return err
_, err = c.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_users": workMoment.LikeUserList}})
return workMoment, err
}
func (d *DataBases) SetUserWorkMomentsLevel(userID string, level int32) error {
return nil
}
func (d *DataBases) CreateUserWorkMomentsCommentsMsg(msg CommentMsg) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cCommentMsg)
_, err := c.InsertOne(ctx, msg)
return err
}
func (d *DataBases) ClearUserWorkMomentsCommentsMsg(userID string) error {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cCommentMsg)
_, err := c.DeleteOne(ctx, bson.M{"user_id": userID})
return err
}
type CommentMsg struct {
WorkMomentID string `bson:"work_moment" json:"work_moment"`
WorkMomentContent string `bson:"work_moment_content" json:"work_moment_content"`
UserID string `bson:"user_id" json:"user_id"`
Comment
}
func (d *DataBases) GetUserWorkMomentsCommentsMsg(userID string, showNumber, pageNumber int32) ([]CommentMsg, error) {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cCommentMsg)
var commentMsgList []CommentMsg
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
result, err := c.Find(ctx, bson.M{"user_id": userID}, findOpts)
if err != nil {
return commentMsgList, err
}
err = result.All(ctx, &commentMsgList)
return commentMsgList, err
}
func (d *DataBases) CommentOneWorkMoment(comment Comment, workMomentID string) (WorkMoment, error) {
func (d *DataBases) CommentOneWorkMoment(comment *Comment, workMomentID string) (WorkMoment, error) {
comment.ContentID = generateWorkMomentCommentID(workMomentID)
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)

File diff suppressed because it is too large Load Diff

@ -113,26 +113,35 @@ message LikeUser {
string userName = 2;
}
message NotificationUser {
string userID = 1;
string userName = 2;
}
message Comment {
string userID = 1;
string userName = 2;
string replyUserID = 3;
string replyUserName = 4;
string contentID = 5;
string content = 6;
int32 createTime = 7;
string faceURL = 3;
string replyUserID = 4;
string replyUserName = 5;
string contentID = 6;
string content = 7;
int32 createTime = 8;
}
message WorkMoment {
string workMomentID = 1;
string userID = 2;
string content = 3;
repeated LikeUser likeUsers = 4;
repeated Comment comments = 5;
repeated string whoCanSeeUserIDList = 6;
repeated string whoCantSeeUserIDList = 7;
bool isPrivate = 8;
int32 CreateTime = 10;
string userName = 3;
string faceURL = 4;
string content = 5;
repeated LikeUser likeUsers = 6;
repeated Comment comments = 7;
int32 permission = 8;
repeated string permissionUserIDList = 9;
repeated string permissionGroupIDList = 10;
repeated string atUserIDList = 11;
int32 createTime = 12;
}
message CreateOneWorkMomentReq {
@ -187,6 +196,18 @@ message GetWorkMomentByIDResp {
WorkMoment workMoment = 2;
}
message ChangeWorkMomentPermissionReq {
string workMomentID = 1;
string opUserID = 2;
int32 permission = 3;
repeated string permissionUserIDList = 4;
string operationID = 5;
}
message ChangeWorkMomentPermissionResp {
CommonResp commonResp = 1;
}
message GetUserWorkMomentsReq {
string userID = 1;
server_api_params.RequestPagination Pagination = 2;
@ -211,32 +232,14 @@ message GetUserFriendWorkMomentsResp {
server_api_params.ResponsePagination Pagination = 3;
}
message CommentsMsg {
Comment comment = 1;
string workMomentID = 2;
string userID = 3;
string content = 4;
}
message GetUserWorkMomentsCommentsMsgReq {
string userID = 1;
string operationID = 2;
server_api_params.RequestPagination Pagination = 3;
}
message GetUserWorkMomentsCommentsMsgResp {
CommonResp commonResp = 1;
repeated CommentsMsg commentsMsgs = 2;
server_api_params.ResponsePagination Pagination = 3;
}
message ClearUserWorkMomentsCommentsMsgReq {
string userID = 1;
string operationID = 2;
}
message ClearUserWorkMomentsCommentsMsgResp {
CommonResp commonResp = 1;
message WorkMomentNotificationMsg {
int32 notificationMsgType = 1;
Comment comment = 2;
string workMomentID = 3;
string userID = 4;
string userName = 5;
string faceURL = 6;
string workMomentContent = 7;
}
message SetUserWorkMomentsLevelReq {
@ -263,12 +266,11 @@ service OfficeService {
rpc LikeOneWorkMoment(LikeOneWorkMomentReq) returns(LikeOneWorkMomentResp);
rpc CommentOneWorkMoment(CommentOneWorkMomentReq) returns(CommentOneWorkMomentResp);
rpc GetWorkMomentByID(GetWorkMomentByIDReq) returns(GetWorkMomentByIDResp);
rpc ChangeWorkMomentPermission(ChangeWorkMomentPermissionReq) returns(ChangeWorkMomentPermissionResp);
/// user self
rpc GetUserWorkMoments(GetUserWorkMomentsReq) returns(GetUserWorkMomentsResp);
/// users friend
rpc GetUserFriendWorkMoments(GetUserFriendWorkMomentsReq) returns(GetUserFriendWorkMomentsResp);
rpc GetUserWorkMomentsCommentsMsg(GetUserWorkMomentsCommentsMsgReq) returns(GetUserWorkMomentsCommentsMsgResp);
rpc ClearUserWorkMomentsCommentsMsg(ClearUserWorkMomentsCommentsMsgReq) returns(ClearUserWorkMomentsCommentsMsgResp);
rpc SetUserWorkMomentsLevel(SetUserWorkMomentsLevelReq) returns(SetUserWorkMomentsLevelResp);
}

Loading…
Cancel
Save