workMoments

This commit is contained in:
wangchuxiao
2022-04-20 16:25:33 +08:00
parent 3e5d9a394f
commit 071dd46a4c
8 changed files with 651 additions and 727 deletions
+35 -28
View File
@@ -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
}
+13 -2
View File
@@ -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{
+20 -47
View File
@@ -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
+42 -40
View File
@@ -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);
}