This commit is contained in:
Cereska
2026-03-02 08:47:52 -05:00
parent a1b599d030
commit 661011485c
7 changed files with 184 additions and 42 deletions

View File

@@ -1,34 +1 @@
package repositories
import (
"chat/internal/models"
"fmt"
"time"
)
func SendChatMessage(msg string, user *models.User, channel *models.Channel) error {
// Handle empty message
if len(msg) < 1 {
return fmt.Errorf("message cannot be empty")
}
// Handle long message
if len(msg) > 500 {
return fmt.Errorf("message too long")
}
// Check if user is banned
banned := user.IsBanned
if banned {
return fmt.Errorf("user: %s, is banned", user.ID)
}
// Send message to channel
channel.Send(models.Message{
Content: msg,
Sender: user,
Timestamp: time.Now(),
})
return nil
}