2021-01-28 15:56:50 +01:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2021-09-01 23:10:18 +02:00
|
|
|
"errors"
|
|
|
|
|
2022-07-14 00:58:22 +02:00
|
|
|
"github.com/demodesk/neko/pkg/types"
|
|
|
|
"github.com/demodesk/neko/pkg/types/event"
|
|
|
|
"github.com/demodesk/neko/pkg/types/message"
|
2021-01-28 15:56:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
|
|
|
|
receiver, ok := h.sessions.Get(payload.Receiver)
|
|
|
|
if !ok {
|
2021-09-01 23:10:18 +02:00
|
|
|
return errors.New("receiver session ID not found")
|
2021-01-28 15:56:50 +01:00
|
|
|
}
|
|
|
|
|
2021-09-01 21:58:39 +02:00
|
|
|
receiver.Send(
|
|
|
|
event.SEND_UNICAST,
|
|
|
|
message.SendUnicast{
|
|
|
|
Sender: session.ID(),
|
|
|
|
Receiver: receiver.ID(),
|
|
|
|
Subject: payload.Subject,
|
|
|
|
Body: payload.Body,
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
2021-01-28 15:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *message.SendBroadcast) error {
|
2021-09-01 21:58:39 +02:00
|
|
|
h.sessions.Broadcast(
|
|
|
|
event.SEND_BROADCAST,
|
|
|
|
message.SendBroadcast{
|
|
|
|
Sender: session.ID(),
|
|
|
|
Subject: payload.Subject,
|
|
|
|
Body: payload.Body,
|
2022-07-28 12:20:20 +02:00
|
|
|
}, session.ID())
|
2021-03-16 10:53:03 +01:00
|
|
|
|
2021-01-28 15:56:50 +01:00
|
|
|
return nil
|
|
|
|
}
|