mirror of
https://github.com/pushbits/server.git
synced 2025-08-01 15:49:09 +02:00
proof of concept
This commit is contained in:
parent
6c69be7d34
commit
5be204dc19
4 changed files with 65 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
|
@ -10,6 +11,16 @@ import (
|
|||
"github.com/pushbits/server/internal/model"
|
||||
)
|
||||
|
||||
type ExampleEvent struct {
|
||||
Body string `json:"body"`
|
||||
Msgtype string `json:"msgtype"`
|
||||
RelatesTo RelatesTo `json:"m.relates_to,omitempty"`
|
||||
}
|
||||
|
||||
type RelatesTo struct {
|
||||
InReplyTo map[string]string `json:"m.in_reply_to"`
|
||||
}
|
||||
|
||||
// SendNotification sends a notification to the specified user.
|
||||
func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notification) error {
|
||||
log.Printf("Sending notification to room %s.", a.MatrixID)
|
||||
|
@ -27,6 +38,38 @@ func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notificatio
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Dispatcher) SendDeleteNotification(a *model.Application, n *model.DeleteNotification) error {
|
||||
log.Printf("Sending delete notification to room %s", a.MatrixID)
|
||||
event := ExampleEvent{
|
||||
Body: "Testmessage",
|
||||
Msgtype: "m.text",
|
||||
}
|
||||
|
||||
irt := make(map[string]string)
|
||||
|
||||
irt["event_id"] = "$uf5OLKPaefHTZhc2lxSIY7If7pLFcNHcMZLbMfS-7qw"
|
||||
|
||||
rt := RelatesTo{
|
||||
InReplyTo: irt,
|
||||
}
|
||||
|
||||
event.RelatesTo = rt
|
||||
|
||||
_, err := d.client.SendMessageEvent(a.MatrixID, "m.room.message", event)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
messages, _ := d.client.Messages(a.MatrixID, "", "", 'b', 10)
|
||||
|
||||
js, _ := json.Marshal(messages)
|
||||
|
||||
log.Println(string(js))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HTML-formats the title
|
||||
func (d *Dispatcher) getFormattedTitle(n *model.Notification) string {
|
||||
trimmedTitle := strings.TrimSpace(n.Title)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue