mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-05 01:25:58 +08:00
errcode
This commit is contained in:
@@ -2,7 +2,7 @@ package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@@ -20,13 +20,13 @@ type SuperGroupMongoDriver struct {
|
||||
|
||||
func NewSuperGroupMongoDriver(mgoClient *mongo.Client) *SuperGroupMongoDriver {
|
||||
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
||||
return &SuperGroupMongoDriver{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(table.CSuperGroup), userToSuperGroupCollection: mgoDB.Collection(table.CUserToSuperGroup)}
|
||||
return &SuperGroupMongoDriver{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(unrelation.CSuperGroup), userToSuperGroupCollection: mgoDB.Collection(unrelation.CUserToSuperGroup)}
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
||||
superGroup := table.SuperGroupModel{
|
||||
GroupID: groupID,
|
||||
MemberIDList: initMemberIDList,
|
||||
func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDs []string) error {
|
||||
superGroup := unrelation.SuperGroupModel{
|
||||
GroupID: groupID,
|
||||
MemberIDs: initMemberIDs,
|
||||
}
|
||||
_, err := db.superGroupCollection.InsertOne(sCtx, superGroup)
|
||||
if err != nil {
|
||||
@@ -36,7 +36,7 @@ func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, gro
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
for _, userID := range initMemberIDList {
|
||||
for _, userID := range initMemberIDs {
|
||||
_, err = db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -46,16 +46,16 @@ func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, gro
|
||||
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroup(ctx context.Context, groupID string) (*table.SuperGroupModel, error) {
|
||||
superGroup := table.SuperGroupModel{}
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroup(ctx context.Context, groupID string) (*unrelation.SuperGroupModel, error) {
|
||||
superGroup := unrelation.SuperGroupModel{}
|
||||
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
||||
return &superGroup, err
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupID string, userIDList []string) error {
|
||||
func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$addToSet": bson.M{"member_id_list": bson.M{"$each": userIDList}}})
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$addToSet": bson.M{"member_id_list": bson.M{"$each": userIDs}}})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
@@ -64,7 +64,7 @@ func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupI
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
for _, userID := range userIDList {
|
||||
for _, userID := range userIDs {
|
||||
_, err = db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts)
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
@@ -75,15 +75,15 @@ func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupI
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDList []string) error {
|
||||
func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDList}}})
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDs}}})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
err = db.RemoveGroupFromUser(sCtx, groupID, userIDList)
|
||||
err = db.RemoveGroupFromUser(sCtx, groupID, userIDs)
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
@@ -92,8 +92,8 @@ func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context,
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, userID string) (*table.UserToSuperGroupModel, error) {
|
||||
var user table.UserToSuperGroupModel
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, userID string) (*unrelation.UserToSuperGroupModel, error) {
|
||||
var user unrelation.UserToSuperGroupModel
|
||||
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||
return &user, utils.Wrap(err, "")
|
||||
}
|
||||
@@ -101,13 +101,13 @@ func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, user
|
||||
func (db *SuperGroupMongoDriver) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
superGroup := &table.SuperGroupModel{}
|
||||
superGroup := &unrelation.SuperGroupModel{}
|
||||
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
if err = db.RemoveGroupFromUser(sCtx, groupID, superGroup.MemberIDList); err != nil {
|
||||
if err = db.RemoveGroupFromUser(sCtx, groupID, superGroup.MemberIDs); err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (db *SuperGroupMongoDriver) DeleteSuperGroup(ctx context.Context, groupID s
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) RemoveGroupFromUser(sCtx context.Context, groupID string, userIDList []string) error {
|
||||
_, err := db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": bson.M{"$in": userIDList}}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
func (db *SuperGroupMongoDriver) RemoveGroupFromUser(sCtx context.Context, groupID string, userIDs []string) error {
|
||||
_, err := db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": bson.M{"$in": userIDs}}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user