mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 19:45:58 +08:00
invite user to groups api add
This commit is contained in:
@@ -47,7 +47,15 @@ type InviteUserToGroupResp struct {
|
||||
CommResp
|
||||
UserIDResultList []*UserIDResult `json:"data"`
|
||||
}
|
||||
|
||||
type InviteUserToGroupsReq struct {
|
||||
GroupIDList string `json:"groupIDList" binding:"required"`
|
||||
InvitedUserID string `json:"invitedUserID" binding:"required"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type InviteUserToGroupsResp struct {
|
||||
CommResp
|
||||
}
|
||||
type GetJoinedGroupListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
|
||||
@@ -112,6 +112,10 @@ func init() {
|
||||
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + cTag + " tag_id")
|
||||
}
|
||||
if err := createMongoIndex(mongoClient, cUserToSuperGroup, true, "user_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + cUserToSuperGroup + " user_id")
|
||||
}
|
||||
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
||||
@@ -1233,6 +1233,36 @@ func (d *DataBases) AddUserToSuperGroup(groupID string, userIDList []string) err
|
||||
_ = session.CommitTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
func (d *DataBases) AddUserToSuperGroups(groupIDList []string, 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(cSuperGroup)
|
||||
session, err := d.mongoClient.StartSession()
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "start session failed")
|
||||
}
|
||||
defer session.EndSession(ctx)
|
||||
sCtx := mongo.NewSessionContext(ctx, session)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "start transaction failed")
|
||||
}
|
||||
_, err = c.UpdateMany(sCtx, bson.M{"group_id": bson.M{"$in": groupIDList}}, bson.M{"$addToSet": bson.M{"member_id_list": userID}})
|
||||
if err != nil {
|
||||
_ = session.AbortTransaction(ctx)
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
}
|
||||
c = d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cUserToSuperGroup)
|
||||
upsert := true
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
_, err = c.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": bson.M{"$each": groupIDList}}}, opts)
|
||||
if err != nil {
|
||||
_ = session.AbortTransaction(ctx)
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
}
|
||||
_ = session.CommitTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) RemoverUserFromSuperGroup(groupID string, userIDList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
|
||||
+367
-213
File diff suppressed because it is too large
Load Diff
@@ -200,6 +200,17 @@ message InviteUserToGroupResp {
|
||||
repeated Id2Result Id2ResultList = 3; // 0 ok, -1 error
|
||||
}
|
||||
|
||||
message InviteUserToGroupsReq {
|
||||
string OperationID = 1;
|
||||
repeated string groupIDList = 2;
|
||||
string Reason = 3;
|
||||
string invitedUserID = 4;
|
||||
string OpUserID = 5; //group member or app manager
|
||||
}
|
||||
message InviteUserToGroupsResp {
|
||||
int32 ErrCode = 1;
|
||||
string ErrMsg = 2;
|
||||
}
|
||||
|
||||
message GetGroupAllMemberReq {
|
||||
string GroupID = 1;
|
||||
@@ -413,6 +424,7 @@ service group{
|
||||
rpc kickGroupMember(KickGroupMemberReq) returns (KickGroupMemberResp);
|
||||
rpc getJoinedGroupList(GetJoinedGroupListReq) returns (GetJoinedGroupListResp);
|
||||
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
|
||||
rpc inviteUserToGroups(InviteUserToGroupsReq) returns (InviteUserToGroupsResp);
|
||||
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
|
||||
|
||||
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
|
||||
|
||||
Reference in New Issue
Block a user