feat: support group invite privacy verification
This commit is contained in:
@@ -1851,6 +1851,7 @@ func createIMUserProductTables(tx *sql.Tx) error {
|
||||
profile_visibility VARCHAR(32) NOT NULL DEFAULT 'friends',
|
||||
last_seen_visibility VARCHAR(32) NOT NULL DEFAULT 'friends',
|
||||
read_receipts TINYINT NOT NULL DEFAULT 1,
|
||||
group_invite_verification TINYINT NOT NULL DEFAULT 0,
|
||||
version INT NOT NULL DEFAULT 1,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
|
||||
@@ -6201,6 +6201,10 @@ func (a *adapter) TenantUserPrivacyUpdate(id t.TenantID, uid t.Uid, patch t.User
|
||||
sets = append(sets, "read_receipts=?")
|
||||
args = append(args, *patch.ReadReceipts)
|
||||
}
|
||||
if patch.GroupInviteVerification != nil {
|
||||
sets = append(sets, "group_invite_verification=?")
|
||||
args = append(args, *patch.GroupInviteVerification)
|
||||
}
|
||||
args = append(args, decodeUID(uid), patch.Version)
|
||||
res, err := a.db.ExecContext(ctx, `UPDATE im_user_privacy_settings SET `+strings.Join(sets, ",")+` WHERE user_id=? AND version=?`, args...)
|
||||
if err != nil {
|
||||
@@ -6825,28 +6829,30 @@ func (a *adapter) userProfileByUID(ctx context.Context, uid t.Uid) (*t.UserProfi
|
||||
|
||||
func (a *adapter) userPrivacyByUID(ctx context.Context, uid t.Uid) (*t.UserPrivacySettings, error) {
|
||||
row := struct {
|
||||
UserID int64 `db:"user_id"`
|
||||
AddMeMethods []byte `db:"add_me_methods"`
|
||||
ProfileVisibility string `db:"profile_visibility"`
|
||||
LastSeenVisibility string `db:"last_seen_visibility"`
|
||||
ReadReceipts bool `db:"read_receipts"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
UserID int64 `db:"user_id"`
|
||||
AddMeMethods []byte `db:"add_me_methods"`
|
||||
ProfileVisibility string `db:"profile_visibility"`
|
||||
LastSeenVisibility string `db:"last_seen_visibility"`
|
||||
ReadReceipts bool `db:"read_receipts"`
|
||||
GroupInviteVerification bool `db:"group_invite_verification"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}{}
|
||||
if err := sqlx.GetContext(ctx, a.db, &row, `SELECT user_id,add_me_methods,profile_visibility,last_seen_visibility,
|
||||
read_receipts,version,created_at,updated_at FROM im_user_privacy_settings WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
read_receipts,group_invite_verification,version,created_at,updated_at FROM im_user_privacy_settings WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
settings := &t.UserPrivacySettings{
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AddMeMethods: map[string]bool{"account": true, "phone": true, "qr": true, "group": true},
|
||||
ProfileVisibility: row.ProfileVisibility,
|
||||
LastSeenVisibility: row.LastSeenVisibility,
|
||||
ReadReceipts: row.ReadReceipts,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AddMeMethods: map[string]bool{"account": true, "phone": true, "qr": true, "group": true},
|
||||
ProfileVisibility: row.ProfileVisibility,
|
||||
LastSeenVisibility: row.LastSeenVisibility,
|
||||
ReadReceipts: row.ReadReceipts,
|
||||
GroupInviteVerification: row.GroupInviteVerification,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}
|
||||
_ = json.Unmarshal(row.AddMeMethods, &settings.AddMeMethods)
|
||||
return settings, nil
|
||||
|
||||
@@ -499,6 +499,12 @@ func (a *adapter) TenantGroupInvitationAccept(id t.TenantID, invitationID string
|
||||
if inv.Status == t.GroupInvitationStatusJoined || inv.Result == "joined" {
|
||||
return &inv, nil
|
||||
}
|
||||
if strings.TrimSpace(inv.JoinRequestID) != "" {
|
||||
if err = tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &inv, nil
|
||||
}
|
||||
var deletedAt sql.NullTime
|
||||
err = tx.QueryRowxContext(ctx, "SELECT deletedat FROM im_subscriptions WHERE topic=? AND userid=?",
|
||||
inv.Topic, decodeUID(uid)).Scan(&deletedAt)
|
||||
|
||||
Reference in New Issue
Block a user