feat: first init
This commit is contained in:
28
internal/services/messaging.go
Normal file
28
internal/services/messaging.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"chat/internal/cache"
|
||||
"chat/internal/models"
|
||||
repo "chat/internal/repositories"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MessagingService struct {
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
// Send a chat message
|
||||
func (s *MessagingService) Send(msg string, user *models.User, channel *models.Channel) error {
|
||||
key := fmt.Sprintf("%s:messages:%s:%s", channel.ID, user.ID, time.Now())
|
||||
|
||||
if err := repo.SendChatMessage(msg, user, channel); err == nil {
|
||||
// Store in cache
|
||||
go func() {
|
||||
s.cache.Set(key, msg, time.Minute*10)
|
||||
}()
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user