feat: add 5 experiment

This commit is contained in:
TAskMAster339
2026-10-10 21:32:33 +03:00
parent 6892af8842
commit 715f6c4175
1397 changed files with 271651 additions and 56 deletions
-27
View File
@@ -5,8 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"strconv"
"strings"
"unicode/utf8"
"messenger/src/backend/repositories"
)
@@ -24,31 +22,6 @@ func NewMessageService(messages *repositories.MessageStore) *MessageService {
return &MessageService{messages: messages}
}
func (s *MessageService) Create(ctx context.Context, userID string, chat repositories.Chat, text string) (repositories.Message, error) {
if !ChatHasMember(chat, userID) {
return repositories.Message{}, ErrChatNotFound
}
if strings.TrimSpace(text) == "" {
return repositories.Message{}, InvalidInput{"text must not be blank"}
}
if utf8.RuneCountInString(text) > 4000 {
return repositories.Message{}, InvalidInput{"text is too long"}
}
return s.messages.Create(ctx, chat.ID, userID, text)
}
func MessageLess(left, right repositories.Message) bool {
if left.CreatedAt.Equal(right.CreatedAt) {
return left.ID < right.ID
}
return left.CreatedAt.Before(right.CreatedAt)
}
func MessageAfterCursor(message repositories.Message, cursor repositories.MessageCursor) bool {
return message.CreatedAt.After(cursor.CreatedAt) ||
(message.CreatedAt.Equal(cursor.CreatedAt) && message.ID > cursor.MessageID)
}
func EncodeMessageCursor(cursor repositories.MessageCursor) (string, error) {
data, err := json.Marshal(cursor)
if err != nil {