fix: group moderation and profile sync
This commit is contained in:
@@ -1555,27 +1555,33 @@ func (a *adapter) TenantGroupOwnerTransfer(id t.TenantID, topic string, previous
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (a *adapter) TenantGroupCanPost(id t.TenantID, topic string, uid t.Uid, admin bool, now time.Time) (bool, error) {
|
||||
func (a *adapter) TenantGroupCanPost(id t.TenantID, topic string, uid t.Uid, _ bool, now time.Time) (bool, error) {
|
||||
if tenantAdp, err := a.routeGroupTenant(id); err != nil {
|
||||
return false, err
|
||||
} else if tenantAdp != a {
|
||||
return tenantAdp.TenantGroupCanPost(id, topic, uid, admin, now)
|
||||
}
|
||||
if admin {
|
||||
return true, nil
|
||||
return tenantAdp.TenantGroupCanPost(id, topic, uid, false, now)
|
||||
}
|
||||
ctx, cancel := a.getContext()
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
}
|
||||
var role string
|
||||
var muteAll, memberMuted bool
|
||||
err := a.db.QueryRowContext(ctx, `SELECT
|
||||
err := a.db.QueryRowContext(ctx, tenantShardSQL(id, `SELECT
|
||||
COALESCE((SELECT role FROM im_group_members WHERE tenant_id=? AND topic=? AND user_id=? AND member_status=? LIMIT 1),''),
|
||||
COALESCE((SELECT mute_all FROM im_group_settings WHERE tenant_id=? AND topic=? AND group_status=? LIMIT 1),0),
|
||||
EXISTS(SELECT 1 FROM im_group_mutes WHERE tenant_id=? AND topic=? AND user_id=? AND status=? AND (expires_at IS NULL OR expires_at>?))`,
|
||||
id, topic, t.GroupStatusActive, id, topic, decodeUID(uid), t.GroupMuteStatusActive, now).Scan(&muteAll, &memberMuted)
|
||||
EXISTS(SELECT 1 FROM im_group_mutes WHERE tenant_id=? AND topic=? AND user_id=? AND status=? AND (expires_at IS NULL OR expires_at>?))`),
|
||||
id, topic, decodeUID(uid), t.GroupMemberStatusActive,
|
||||
id, topic, t.GroupStatusActive, id, topic, decodeUID(uid), t.GroupMuteStatusActive, now).Scan(&role, &muteAll, &memberMuted)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if role == t.GroupMemberRoleOwner || role == t.GroupMemberRoleAdmin {
|
||||
return true, nil
|
||||
}
|
||||
if role != t.GroupMemberRoleMember {
|
||||
return false, nil
|
||||
}
|
||||
return !muteAll && !memberMuted, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user