34 lines
604 B
Go
34 lines
604 B
Go
// backend\user_events.go
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func (s *Server) publishUserProfileEvent(eventType string, user User) {
|
|
data, err := json.Marshal(map[string]any{
|
|
"user": user,
|
|
})
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
now := time.Now()
|
|
|
|
notificationsBroker.publishToAll(Notification{
|
|
ID: fmt.Sprintf("%s-%s-%d", eventType, user.ID, now.UnixNano()),
|
|
UserID: user.ID,
|
|
Type: eventType,
|
|
Title: "",
|
|
Message: "",
|
|
EntityType: "user",
|
|
EntityID: user.ID,
|
|
Data: json.RawMessage(data),
|
|
Silent: true,
|
|
CreatedAt: now,
|
|
})
|
|
}
|