diff --git a/roomdb/interface.go b/roomdb/interface.go index 37e2130..e19ce73 100644 --- a/roomdb/interface.go +++ b/roomdb/interface.go @@ -161,6 +161,9 @@ type InvitesService interface { // Count returns the total number of invites. Count(context.Context) (uint, error) + // CountActive returns the total number of active invites. + CountActive(context.Context) (uint, error) + // Revoke removes a active invite and invalidates it for future use. Revoke(ctx context.Context, id int64) error } diff --git a/roomdb/sqlite/invites.go b/roomdb/sqlite/invites.go index 70b8d27..9623645 100644 --- a/roomdb/sqlite/invites.go +++ b/roomdb/sqlite/invites.go @@ -258,6 +258,16 @@ func (i Invites) Count(ctx context.Context) (uint, error) { return uint(count), nil } +func (i Invites) CountActive(ctx context.Context) (uint, error) { + count, err := models.Invites( + qm.Where("active = true"), + ).Count(ctx, i.db) + if err != nil { + return 0, err + } + return uint(count), nil +} + // Revoke removes a active invite and invalidates it for future use. func (i Invites) Revoke(ctx context.Context, id int64) error { return transact(i.db, func(tx *sql.Tx) error { diff --git a/web/handlers/admin/dashboard.go b/web/handlers/admin/dashboard.go index bea165e..4ea3fe1 100644 --- a/web/handlers/admin/dashboard.go +++ b/web/handlers/admin/dashboard.go @@ -77,9 +77,9 @@ func (h dashboardHandler) overview(w http.ResponseWriter, req *http.Request) (in return nil, fmt.Errorf("failed to count members: %w", err) } - inviteCount, err := h.dbs.Invites.Count(ctx) + inviteCount, err := h.dbs.Invites.CountActive(ctx) if err != nil { - return nil, fmt.Errorf("failed to count invites: %w", err) + return nil, fmt.Errorf("failed to count active invites: %w", err) } deniedCount, err := h.dbs.DeniedKeys.Count(ctx)