39 lines
1.8 KiB
Go
39 lines
1.8 KiB
Go
package chat
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ChatRepository stores chats and their membership. Membership is answered
|
|
// by queries; the projection with members is assembled by the store in one
|
|
// query, never by loading a member list into the entity. Members are always
|
|
// returned ordered by id.
|
|
type ChatRepository interface {
|
|
// Create stores the chat row and its members atomically.
|
|
Create(ctx context.Context, chat Chat, memberIDs []uuid.UUID) error
|
|
// GetForMember returns the chat with members, or ErrNotFound when the
|
|
// chat does not exist or the user is not a member.
|
|
GetForMember(ctx context.Context, chatID, userID uuid.UUID) (ChatWithMembers, error)
|
|
IsMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error)
|
|
// ListByMember returns up to limit chats of the user ordered by
|
|
// (created_at, id), strictly after the chat identified by after when set.
|
|
ListByMember(ctx context.Context, userID uuid.UUID, after *uuid.UUID, limit int) ([]ChatWithMembers, error)
|
|
}
|
|
|
|
type MessageRepository interface {
|
|
// AppendOnce stores message under the sender's key in its chat, unless
|
|
// the key was used there within ttl; it returns the message the key is
|
|
// bound to: the given one or the earlier one.
|
|
AppendOnce(ctx context.Context, message Message, key string, ttl time.Duration) (Message, error)
|
|
// DeleteExpiredKeys removes up to limit keys older than ttl and reports
|
|
// how many it removed.
|
|
DeleteExpiredKeys(ctx context.Context, ttl time.Duration, limit int) (int64, error)
|
|
// ListByChat returns up to limit messages ordered by (created_at, id),
|
|
// strictly after the message identified by after when set. An unknown
|
|
// chat yields an empty history.
|
|
ListByChat(ctx context.Context, chatID uuid.UUID, after *uuid.UUID, limit int) ([]Message, error)
|
|
}
|