forked from gotify/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessagehandler.go
More file actions
44 lines (39 loc) · 1.18 KB
/
Copy pathmessagehandler.go
File metadata and controls
44 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package plugin
import (
"errors"
"time"
"github.com/gotify/server/v2/model"
"github.com/gotify/server/v2/plugin/compat"
)
type redirectToChannel struct {
ApplicationID uint
UserID uint
Messages chan MessageWithUserID
}
// MessageWithUserID encapsulates a message with a given user ID.
type MessageWithUserID struct {
Message model.MessageExternal
UserID uint
}
// SendMessage sends a message to the underlying message channel.
func (c redirectToChannel) SendMessage(msg compat.Message) error {
if c.ApplicationID == 0 {
// Final safety net: the internal application should always be set up by
// Manager.initializeSingleUserPlugin. If it somehow isn't, refuse the
// message instead of storing it with application_id = 0, where it would
// be orphaned (not shown in the UI and not deletable).
return errors.New("plugin messenger has no associated internal application")
}
c.Messages <- MessageWithUserID{
Message: model.MessageExternal{
ApplicationID: c.ApplicationID,
Message: msg.Message,
Title: msg.Title,
Priority: &msg.Priority,
Date: time.Now(),
Extras: msg.Extras,
},
UserID: c.UserID,
}
return nil
}