|
8 | 8 | "github.com/juggleim/commons/ctxs" |
9 | 9 | "github.com/juggleim/commons/errs" |
10 | 10 | "github.com/juggleim/commons/imsdk" |
| 11 | + "github.com/juggleim/commons/tools" |
11 | 12 | utils "github.com/juggleim/commons/tools" |
12 | 13 | apimodels "github.com/juggleim/jugglechat-server/apis/models" |
13 | 14 | "github.com/juggleim/jugglechat-server/storages" |
@@ -147,6 +148,23 @@ func QryGroupInfo(ctx context.Context, groupId string) (errs.IMErrorCode, *apimo |
147 | 148 | return errs.IMErrorCode_SUCCESS, ret |
148 | 149 | } |
149 | 150 |
|
| 151 | +func GetGroupInfo(ctx context.Context, groupId string) *apimodels.GrpInfo { |
| 152 | + if groupId == "" { |
| 153 | + return nil |
| 154 | + } |
| 155 | + appkey := ctxs.GetAppKeyFromCtx(ctx) |
| 156 | + ret := &apimodels.GrpInfo{ |
| 157 | + GroupId: groupId, |
| 158 | + } |
| 159 | + grpStorage := storages.NewGroupStorage() |
| 160 | + grpInfo, err := grpStorage.FindById(appkey, groupId) |
| 161 | + if err == nil && grpInfo != nil { |
| 162 | + ret.GroupName = grpInfo.GroupName |
| 163 | + ret.GroupPortrait = grpInfo.GroupPortrait |
| 164 | + } |
| 165 | + return ret |
| 166 | +} |
| 167 | + |
150 | 168 | func GetGroupSettings(ctx context.Context, groupId string) *apimodels.GroupManagement { |
151 | 169 | ret := &apimodels.GroupManagement{ |
152 | 170 | GroupEditMsgRight: utils.IntPtr(7), |
@@ -490,6 +508,55 @@ func GrpInviteMembers(ctx context.Context, req *apimodels.GroupInviteReq) (errs. |
490 | 508 | return errs.IMErrorCode_SUCCESS, results |
491 | 509 | } |
492 | 510 |
|
| 511 | +func GroupConfirm(ctx context.Context, req *apimodels.GroupConfirm) errs.IMErrorCode { |
| 512 | + appkey := ctxs.GetAppKeyFromCtx(ctx) |
| 513 | + //TODO check admin |
| 514 | + storage := storages.NewGrpApplicationStorage() |
| 515 | + id, err := tools.DecodeInt(req.ApplicationId) |
| 516 | + if err != nil || id <= 0 { |
| 517 | + return errs.IMErrorCode_APP_REQ_BODY_ILLEGAL |
| 518 | + } |
| 519 | + application, err := storage.FindById(appkey, id) |
| 520 | + if err != nil || application == nil { |
| 521 | + return errs.IMErrorCode_APP_REQ_BODY_ILLEGAL |
| 522 | + } |
| 523 | + if application.ApplyType == models.GrpApplicationType_Invite { |
| 524 | + if req.IsAgree { |
| 525 | + err := storage.UpdateStatus(id, models.GrpApplicationStatus_AgreeInvite) |
| 526 | + if err == nil { |
| 527 | + memberStorage := storages.NewGroupMemberStorage() |
| 528 | + memberStorage.BatchCreate([]models.GroupMember{ |
| 529 | + { |
| 530 | + GroupId: application.GroupId, |
| 531 | + MemberId: application.RecipientId, |
| 532 | + AppKey: appkey, |
| 533 | + }, |
| 534 | + }) |
| 535 | + //sync to imserver |
| 536 | + if sdk := imsdk.GetImSdk(appkey); sdk != nil { |
| 537 | + sdk.GroupAddMembers(juggleimsdk.GroupMembersReq{ |
| 538 | + GroupId: application.GroupId, |
| 539 | + MemberIds: []string{application.RecipientId}, |
| 540 | + }) |
| 541 | + } |
| 542 | + //send notify msg |
| 543 | + targetUsers := []*apimodels.UserObj{ |
| 544 | + GetUser(ctx, application.RecipientId), |
| 545 | + } |
| 546 | + notify := &apimodels.GroupNotify{ |
| 547 | + Operator: GetUser(ctx, application.InviterId), |
| 548 | + Members: targetUsers, |
| 549 | + Type: apimodels.GroupNotifyType_AddMember, |
| 550 | + } |
| 551 | + SendGrpNotify(ctx, application.GroupId, notify) |
| 552 | + } |
| 553 | + } else { |
| 554 | + storage.UpdateStatus(id, models.GrpApplicationStatus_DeclineInvite) |
| 555 | + } |
| 556 | + } |
| 557 | + return errs.IMErrorCode_SUCCESS |
| 558 | +} |
| 559 | + |
493 | 560 | func GrpJoinApply(ctx context.Context, req *apimodels.GroupInviteReq) errs.IMErrorCode { |
494 | 561 | appkey := ctxs.GetAppKeyFromCtx(ctx) |
495 | 562 | userId := ctxs.GetRequesterIdFromCtx(ctx) |
@@ -939,26 +1006,20 @@ func QryGrpApplications(ctx context.Context, startTime int64, count int32, order |
939 | 1006 | } |
940 | 1007 | applications, err := storage.QueryGrpApplications(appkey, groupId, startTime, int64(count), order > 0) |
941 | 1008 | if err == nil { |
| 1009 | + grpInfo := GetGroupInfo(ctx, groupId) |
942 | 1010 | for _, application := range applications { |
| 1011 | + idStr, _ := tools.EncodeInt(application.ID) |
| 1012 | + |
943 | 1013 | ret.Items = append(ret.Items, &apimodels.GrpApplicationItem{ |
944 | | - GrpInfo: &apimodels.GrpInfo{ |
945 | | - GroupId: application.GroupId, |
946 | | - }, |
947 | | - ApplyType: int32(application.ApplyType), |
948 | | - Sponsor: &apimodels.UserObj{ |
949 | | - UserId: application.SponsorId, |
950 | | - }, |
951 | | - Operator: &apimodels.UserObj{ |
952 | | - UserId: application.OperatorId, |
953 | | - }, |
954 | | - Recipient: &apimodels.UserObj{ |
955 | | - UserId: application.RecipientId, |
956 | | - }, |
957 | | - Inviter: &apimodels.UserObj{ |
958 | | - UserId: application.InviterId, |
959 | | - }, |
960 | | - ApplyTime: application.ApplyTime, |
961 | | - Status: int32(application.Status), |
| 1014 | + ApplicationId: idStr, |
| 1015 | + GrpInfo: grpInfo, |
| 1016 | + ApplyType: int32(application.ApplyType), |
| 1017 | + Sponsor: GetUser(ctx, application.SponsorId), |
| 1018 | + Operator: GetUser(ctx, application.OperatorId), |
| 1019 | + Recipient: GetUser(ctx, application.RecipientId), |
| 1020 | + Inviter: GetUser(ctx, application.InviterId), |
| 1021 | + ApplyTime: application.ApplyTime, |
| 1022 | + Status: int32(application.Status), |
962 | 1023 | }) |
963 | 1024 | } |
964 | 1025 | } |
|
0 commit comments