mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
40 lines
918 B
Go
40 lines
918 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gitlab.com/demodesk/neko/server/internal/types"
|
|
"gitlab.com/demodesk/neko/server/internal/types/event"
|
|
"gitlab.com/demodesk/neko/server/internal/types/message"
|
|
)
|
|
|
|
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
|
|
receiver, ok := h.sessions.Get(payload.Receiver)
|
|
if !ok {
|
|
return errors.New("receiver session ID not found")
|
|
}
|
|
|
|
receiver.Send(
|
|
event.SEND_UNICAST,
|
|
message.SendUnicast{
|
|
Sender: session.ID(),
|
|
Receiver: receiver.ID(),
|
|
Subject: payload.Subject,
|
|
Body: payload.Body,
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *message.SendBroadcast) error {
|
|
h.sessions.Broadcast(
|
|
event.SEND_BROADCAST,
|
|
message.SendBroadcast{
|
|
Sender: session.ID(),
|
|
Subject: payload.Subject,
|
|
Body: payload.Body,
|
|
}, []string{session.ID()})
|
|
|
|
return nil
|
|
}
|