feat(message): store messages in Postgres
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
var ErrInvalidCursor = errors.New("invalid cursor")
|
||||
|
||||
type Cursor struct {
|
||||
ChatID uuid.UUID `json:"chat_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
@@ -21,7 +22,7 @@ func encodeCursor(cursor Cursor) string {
|
||||
return base64.RawURLEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
func decodeCursor(raw string) (Cursor, error) {
|
||||
func decodeCursor(raw string, chatID uuid.UUID) (Cursor, error) {
|
||||
data, err := base64.RawURLEncoding.DecodeString(raw)
|
||||
if err != nil {
|
||||
return Cursor{}, ErrInvalidCursor
|
||||
@@ -32,7 +33,7 @@ func decodeCursor(raw string) (Cursor, error) {
|
||||
return Cursor{}, ErrInvalidCursor
|
||||
}
|
||||
|
||||
if cursor.ID == uuid.Nil || cursor.CreatedAt.IsZero() {
|
||||
if cursor.ID == uuid.Nil || cursor.CreatedAt.IsZero() || cursor.ChatID != chatID {
|
||||
return Cursor{}, ErrInvalidCursor
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user