mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 18:00:32 +08:00
work_moments
This commit is contained in:
parent
86e17d38d4
commit
d1ebcde725
@ -14,7 +14,7 @@ func main() {
|
|||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := cms_api.NewGinRouter()
|
router := cms_api.NewGinRouter()
|
||||||
router.Use(utils.CorsHandler())
|
router.Use(utils.CorsHandler())
|
||||||
ginPort := flag.Int("port", 8000, "get ginServerPort from cmd,default 10000 as port")
|
ginPort := flag.Int("port", 8000, "get ginServerPort from cmd,default 8000 as port")
|
||||||
fmt.Println("start cms api server, port: ", ginPort)
|
fmt.Println("start cms api server, port: ", ginPort)
|
||||||
router.Run(":" + strconv.Itoa(*ginPort))
|
router.Run(":" + strconv.Itoa(*ginPort))
|
||||||
}
|
}
|
||||||
|
@ -303,6 +303,7 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
|
|||||||
UserID: workMoment.UserID,
|
UserID: workMoment.UserID,
|
||||||
FaceURL: createUser.FaceURL,
|
FaceURL: createUser.FaceURL,
|
||||||
UserName: createUser.Nickname,
|
UserName: createUser.Nickname,
|
||||||
|
CreateTime: workMoment.CreateTime,
|
||||||
}
|
}
|
||||||
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser.UserID, workMomentNotificationMsg)
|
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser.UserID, workMomentNotificationMsg)
|
||||||
}
|
}
|
||||||
@ -375,13 +376,13 @@ func isUserCanSeeWorkMoment(userID string, workMoment db.WorkMoment) bool {
|
|||||||
func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOneWorkMomentReq) (resp *pbOffice.LikeOneWorkMomentResp, err error) {
|
func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOneWorkMomentReq) (resp *pbOffice.LikeOneWorkMomentResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp = &pbOffice.LikeOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
resp = &pbOffice.LikeOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||||
userName, err := imdb.GetUserNameByUserID(req.UserID)
|
user, err := imdb.GetUserByUserID(req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
workMoment, like, err := db.DB.LikeOneWorkMoment(req.UserID, userName, req.WorkMomentID)
|
workMoment, like, err := db.DB.LikeOneWorkMoment(req.UserID, user.Nickname, req.WorkMomentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
||||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
@ -391,9 +392,10 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn
|
|||||||
NotificationMsgType: constant.WorkMomentLikeNotification,
|
NotificationMsgType: constant.WorkMomentLikeNotification,
|
||||||
WorkMomentID: workMoment.WorkMomentID,
|
WorkMomentID: workMoment.WorkMomentID,
|
||||||
WorkMomentContent: workMoment.Content,
|
WorkMomentContent: workMoment.Content,
|
||||||
UserID: workMoment.UserID,
|
UserID: user.UserID,
|
||||||
FaceURL: workMoment.FaceURL,
|
FaceURL: user.FaceURL,
|
||||||
UserName: workMoment.UserName,
|
UserName: user.Nickname,
|
||||||
|
CreateTime: int32(time.Now().Unix()),
|
||||||
}
|
}
|
||||||
// send notification
|
// send notification
|
||||||
if like {
|
if like {
|
||||||
@ -442,16 +444,11 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
|
|||||||
UserID: workMoment.UserID,
|
UserID: workMoment.UserID,
|
||||||
FaceURL: workMoment.FaceURL,
|
FaceURL: workMoment.FaceURL,
|
||||||
UserName: workMoment.UserName,
|
UserName: workMoment.UserName,
|
||||||
Comment: &pbOffice.Comment{
|
|
||||||
UserID: comment.UserID,
|
|
||||||
UserName: comment.UserName,
|
|
||||||
FaceURL: commentUser.FaceURL,
|
|
||||||
ReplyUserID: comment.ReplyUserID,
|
ReplyUserID: comment.ReplyUserID,
|
||||||
ReplyUserName: comment.ReplyUserName,
|
ReplyUserName: comment.ReplyUserName,
|
||||||
ContentID: comment.ContentID,
|
ContentID: comment.ContentID,
|
||||||
Content: comment.Content,
|
Content: comment.Content,
|
||||||
CreateTime: comment.CreateTime,
|
CreateTime: comment.CreateTime,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg)
|
||||||
if req.ReplyUserID != "" {
|
if req.ReplyUserID != "" {
|
||||||
@ -488,10 +485,14 @@ func (s *officeServer) GetWorkMomentByID(_ context.Context, req *pbOffice.GetWor
|
|||||||
func (s *officeServer) GetUserWorkMoments(_ context.Context, req *pbOffice.GetUserWorkMomentsReq) (resp *pbOffice.GetUserWorkMomentsResp, err error) {
|
func (s *officeServer) GetUserWorkMoments(_ context.Context, req *pbOffice.GetUserWorkMomentsReq) (resp *pbOffice.GetUserWorkMomentsResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp = &pbOffice.GetUserWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
resp = &pbOffice.GetUserWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
||||||
//resp.WorkMoments = make([]*pbOffice.WorkMoment, 0)
|
var workMoments []db.WorkMoment
|
||||||
workMoments, err := db.DB.GetUserWorkMoments(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
if req.UserID == req.OpUserID {
|
||||||
|
workMoments, err = db.DB.GetUserSelfWorkMoments(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||||
|
} else {
|
||||||
|
workMoments, err = db.DB.GetUserWorkMoments(req.OpUserID, req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err)
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments failed", err.Error())
|
||||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,8 @@ type WorkMoment struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
LikeUserList []*WorkMomentUser `json:"likeUsers"`
|
LikeUserList []*WorkMomentUser `json:"likeUsers"`
|
||||||
Comments []*Comment `json:"comments"`
|
Comments []*Comment `json:"comments"`
|
||||||
FaceURL string `json:"faceUrl"`
|
FaceURL string `json:"faceURL"`
|
||||||
UserName string `json:"userName"`
|
UserName string `json:"userName"`
|
||||||
//Permission int32 `json:"permission"`
|
|
||||||
//PermissionUserIDList []string `json:"permissionUserIDList"`
|
|
||||||
//PermissionGroupIDList []string `json:"permissionGroupIDList"`
|
|
||||||
AtUserList []*WorkMomentUser `json:"atUsers"`
|
AtUserList []*WorkMomentUser `json:"atUsers"`
|
||||||
CreateTime int32 `json:"createTime"`
|
CreateTime int32 `json:"createTime"`
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,14 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gogo/protobuf/sortkeys"
|
"github.com/gogo/protobuf/sortkeys"
|
||||||
|
"go.etcd.io/etcd/clientv3"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
//"github.com/garyburd/redigo/redis"
|
//"github.com/garyburd/redigo/redis"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -659,7 +661,7 @@ func (d *DataBases) CommentOneWorkMoment(comment *Comment, workMomentID string)
|
|||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) GetUserWorkMoments(userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
|
func (d *DataBases) GetUserSelfWorkMoments(userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []WorkMoment
|
||||||
@ -672,14 +674,38 @@ func (d *DataBases) GetUserWorkMoments(userID string, showNumber, pageNumber int
|
|||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DataBases) GetUserWorkMoments(opUserID, userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
||||||
|
var workMomentList []WorkMoment
|
||||||
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
|
result, err := c.Find(ctx, bson.D{ // 等价条件: select * from
|
||||||
|
{"user_id", userID},
|
||||||
|
{"$or", bson.A{
|
||||||
|
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {opUserID, bson.D{{"$in", "permission_user_id_list"}}}},
|
||||||
|
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {opUserID, bson.D{{"$in", "permission_user_id_list"}}}},
|
||||||
|
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||||
|
}},
|
||||||
|
}, findOpts)
|
||||||
|
if err != nil {
|
||||||
|
return workMomentList, nil
|
||||||
|
}
|
||||||
|
err = result.All(ctx, &workMomentList)
|
||||||
|
return workMomentList, err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DataBases) GetUserFriendWorkMoments(friendIDList []*string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) {
|
func (d *DataBases) GetUserFriendWorkMoments(friendIDList []*string, showNumber, pageNumber int32, userID string) ([]WorkMoment, error) {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cWorkMoment)
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := c.Find(ctx,
|
result, err := c.Find(ctx, bson.D{ // 等价条件: select * from t where user_id in friend_id_list and () or () or ();
|
||||||
bson.M{"user_id": friendIDList, "$or": bson.M{"who_can_see_user_id_list": bson.M{"$elemMatch": bson.M{"$eq": userID}},
|
{"user_id", bson.D{{"$in", friendIDList}}},
|
||||||
"who_cant_see_user_id_list": bson.M{"$nin": userID}},
|
{"$or", bson.A{
|
||||||
|
bson.D{{"permission", constant.WorkMomentPermissionCantSee}, {userID, bson.D{{"$in", "permission_user_id_list"}}}},
|
||||||
|
bson.D{{"permission", constant.WorkMomentPermissionCanSee}, {userID, bson.D{{"$in", "permission_user_id_list"}}}},
|
||||||
|
bson.D{{"permission", constant.WorkMomentPublic}},
|
||||||
|
}},
|
||||||
}, findOpts)
|
}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -220,8 +220,9 @@ message ChangeWorkMomentPermissionResp {
|
|||||||
|
|
||||||
message GetUserWorkMomentsReq {
|
message GetUserWorkMomentsReq {
|
||||||
string userID = 1;
|
string userID = 1;
|
||||||
server_api_params.RequestPagination Pagination = 2;
|
string opUserID = 2;
|
||||||
string operationID = 3;
|
server_api_params.RequestPagination Pagination = 3;
|
||||||
|
string operationID = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserWorkMomentsResp {
|
message GetUserWorkMomentsResp {
|
||||||
@ -244,12 +245,16 @@ message GetUserFriendWorkMomentsResp {
|
|||||||
|
|
||||||
message WorkMomentNotificationMsg {
|
message WorkMomentNotificationMsg {
|
||||||
int32 notificationMsgType = 1;
|
int32 notificationMsgType = 1;
|
||||||
Comment comment = 2;
|
string replyUserName = 2;
|
||||||
string workMomentID = 3;
|
string replyUserID = 3;
|
||||||
string userID = 4;
|
string content = 4;
|
||||||
string userName = 5;
|
string contentID = 5;
|
||||||
string faceURL = 6;
|
string workMomentID = 6;
|
||||||
string workMomentContent = 7;
|
string userID = 7;
|
||||||
|
string userName = 8;
|
||||||
|
string faceURL = 9;
|
||||||
|
string workMomentContent = 10;
|
||||||
|
int32 createTime = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetUserWorkMomentsLevelReq {
|
message SetUserWorkMomentsLevelReq {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user