fix: join group directly when invitation needs no approval
This commit is contained in:
+26
-7
@@ -5456,13 +5456,6 @@ func serveIMGroupInvitations(wrt http.ResponseWriter, req *http.Request, topic s
|
||||
results = append(results, item)
|
||||
continue
|
||||
}
|
||||
invitationID := "ginv_" + store.Store.GetUidString()
|
||||
idempotencyKey := strings.TrimSpace(req.Header.Get("Idempotency-Key"))
|
||||
if idempotencyKey != "" {
|
||||
idempotencyKey += ":" + uid.UserId()
|
||||
} else {
|
||||
idempotencyKey = invitationID
|
||||
}
|
||||
targetRequiresApproval := settings != nil && settings.JoinApproval
|
||||
if !targetRequiresApproval && store.Profiles != nil {
|
||||
privacy, privacyErr := store.Profiles.GetPrivacy(principal.TenantID, uid)
|
||||
@@ -5480,9 +5473,35 @@ func serveIMGroupInvitations(wrt http.ResponseWriter, req *http.Request, topic s
|
||||
targetRequiresApproval = privacy != nil && privacy.GroupInviteVerification
|
||||
}
|
||||
joinRequestID := ""
|
||||
invitationID := ""
|
||||
if targetRequiresApproval {
|
||||
invitationID = "ginv_" + store.Store.GetUidString()
|
||||
joinRequestID = "gjr_" + store.Store.GetUidString()
|
||||
}
|
||||
if !targetRequiresApproval {
|
||||
joined, err := store.GroupBusiness.InviteMember(principal.TenantID, topic, principal.Uid, uid,
|
||||
strings.TrimSpace(body.Message), strings.TrimSpace(req.Header.Get("Idempotency-Key")),
|
||||
groupMemberPrivate("", false, false, 1, now), now)
|
||||
if err != nil {
|
||||
item["status"] = "failed"
|
||||
item["reason"] = relationErrorReason(err)
|
||||
results = append(results, item)
|
||||
continue
|
||||
}
|
||||
if joined {
|
||||
item["status"] = types.GroupInvitationStatusJoined
|
||||
} else {
|
||||
item["status"] = "already_member"
|
||||
}
|
||||
results = append(results, item)
|
||||
continue
|
||||
}
|
||||
idempotencyKey := strings.TrimSpace(req.Header.Get("Idempotency-Key"))
|
||||
if idempotencyKey != "" {
|
||||
idempotencyKey += ":" + uid.UserId()
|
||||
} else {
|
||||
idempotencyKey = invitationID
|
||||
}
|
||||
inv, err := store.GroupBusiness.CreateInvitation(principal.TenantID, &types.GroupInvitation{
|
||||
InvitationID: invitationID,
|
||||
Topic: topic,
|
||||
|
||||
Reference in New Issue
Block a user