feat: triage streams with open, close (#121)
* refactor: use interfaces for function params * cleanup message retention code * support open / closed streams - Tabs for viewing separately - Context menu to close / open streams - Update stream particle status field * ui tweak * show stream state in stream-view * ui tweaks * cleanup message retention from orion api
This commit was merged in pull request #121.
This commit is contained in:
@@ -7,9 +7,6 @@ type Network struct {
|
||||
Name string
|
||||
AdminHumanId string
|
||||
MemberHumanIds []string
|
||||
OpenStreamCapacity int
|
||||
OpenStreamCount int
|
||||
MessageRetentionHours int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ type repository interface {
|
||||
getMemberHumanIds(ctx context.Context, networkID string) ([]string, error)
|
||||
getNetworksForHuman(ctx context.Context, humanId string) ([]*Network, error)
|
||||
isMember(ctx context.Context, networkID, humanId string) (bool, error)
|
||||
updateMessageRetentionHours(ctx context.Context, id string, hours int) error
|
||||
|
||||
// Invitations
|
||||
createInvitation(ctx context.Context, networkID, email string) error
|
||||
@@ -61,9 +60,9 @@ func (r *repositoryImpl) create(ctx context.Context, name, adminHumanId string)
|
||||
var n Network
|
||||
err = r.pool.QueryRow(ctx,
|
||||
`INSERT INTO networks (id, name, admin_human_id) VALUES ($1, $2, $3)
|
||||
RETURNING id, name, admin_human_id, open_stream_capacity, open_stream_count, message_retention_hours, created_at`,
|
||||
RETURNING id, name, admin_human_id, created_at`,
|
||||
id.String(), name, adminHumanId,
|
||||
).Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.OpenStreamCapacity, &n.OpenStreamCount, &n.MessageRetentionHours, &n.CreatedAt)
|
||||
).Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,9 +74,9 @@ func (r *repositoryImpl) create(ctx context.Context, name, adminHumanId string)
|
||||
func (r *repositoryImpl) getByID(ctx context.Context, id string) (*Network, error) {
|
||||
var n Network
|
||||
err := r.pool.QueryRow(ctx,
|
||||
`SELECT id, name, admin_human_id, open_stream_capacity, open_stream_count, message_retention_hours, created_at FROM networks WHERE id = $1`,
|
||||
`SELECT id, name, admin_human_id, created_at FROM networks WHERE id = $1`,
|
||||
id,
|
||||
).Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.OpenStreamCapacity, &n.OpenStreamCount, &n.MessageRetentionHours, &n.CreatedAt)
|
||||
).Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.CreatedAt)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, errNotFound
|
||||
@@ -158,7 +157,7 @@ func (r *repositoryImpl) getMemberHumanIds(ctx context.Context, networkID string
|
||||
|
||||
func (r *repositoryImpl) getNetworksForHuman(ctx context.Context, humanId string) ([]*Network, error) {
|
||||
rows, err := r.pool.Query(ctx,
|
||||
`SELECT n.id, n.name, n.admin_human_id, n.open_stream_capacity, n.open_stream_count, n.message_retention_hours, n.created_at
|
||||
`SELECT n.id, n.name, n.admin_human_id, n.created_at
|
||||
FROM networks n
|
||||
WHERE n.admin_human_id = $1
|
||||
OR EXISTS (SELECT 1 FROM network_members nm WHERE nm.network_id = n.id AND nm.human_id = $1)`,
|
||||
@@ -172,7 +171,7 @@ func (r *repositoryImpl) getNetworksForHuman(ctx context.Context, humanId string
|
||||
var networks []*Network
|
||||
for rows.Next() {
|
||||
var n Network
|
||||
if err := rows.Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.OpenStreamCapacity, &n.OpenStreamCount, &n.MessageRetentionHours, &n.CreatedAt); err != nil {
|
||||
if err := rows.Scan(&n.ID, &n.Name, &n.AdminHumanId, &n.CreatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
networks = append(networks, &n)
|
||||
@@ -269,17 +268,3 @@ func (r *repositoryImpl) deleteInvitation(ctx context.Context, networkID, email
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *repositoryImpl) updateMessageRetentionHours(ctx context.Context, id string, hours int) error {
|
||||
result, err := r.pool.Exec(ctx,
|
||||
`UPDATE networks SET message_retention_hours = $1 WHERE id = $2`,
|
||||
hours, id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.RowsAffected() == 0 {
|
||||
return errNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ type Service interface {
|
||||
RemoveMember(ctx context.Context, networkID, humanId string) error
|
||||
ListForHuman(ctx context.Context, humanId string) ([]*Network, error)
|
||||
IsMember(ctx context.Context, networkID, humanId string) (bool, error)
|
||||
// SetMessageRetentionHours sets how long messages remain visible (24–336 hours).
|
||||
SetMessageRetentionHours(ctx context.Context, id string, hours int) error
|
||||
|
||||
// Invitations (email-based, for users who haven't registered yet)
|
||||
InviteByEmail(ctx context.Context, networkID string, emails []string) error
|
||||
@@ -118,17 +116,6 @@ func (s *serviceImpl) IsMember(ctx context.Context, networkID, humanId string) (
|
||||
return s.repo.isMember(ctx, networkID, humanId)
|
||||
}
|
||||
|
||||
func (s *serviceImpl) SetMessageRetentionHours(ctx context.Context, id string, hours int) error {
|
||||
if hours < 24 || hours > 336 {
|
||||
return ErrInvalidRetentionHours
|
||||
}
|
||||
err := s.repo.updateMessageRetentionHours(ctx, id, hours)
|
||||
if errors.Is(err, errNotFound) {
|
||||
return ErrNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Invitation methods
|
||||
|
||||
func (s *serviceImpl) InviteByEmail(ctx context.Context, networkID string, emails []string) error {
|
||||
|
||||
Reference in New Issue
Block a user