9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-12-22 03:26:59 +00:00

Set Matrix online status and mark encountered messages as read

This commit is contained in:
Lomanic 2020-10-24 22:34:18 +02:00
parent 91999707d0
commit d3d1b1676c

25
main.go
View File

@ -233,9 +233,34 @@ func statusHandler(w http.ResponseWriter, r *http.Request) {
}
}
func syncMatrix() {
syncer := matrix.Syncer.(*gomatrix.DefaultSyncer)
syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) {
if ev.Sender != matrix.UserID {
matrix.MarkRead(ev.RoomID, ev.ID)
}
})
go func() { // set online status every 15 seconds
for {
if err := matrix.SetStatus("online", "up and running"); err != nil {
panic(fmt.Sprintf("error setting matrix status: %s", err))
}
time.Sleep(15 * time.Second)
}
}()
for {
if err := matrix.Sync(); err != nil {
fmt.Println("Sync() returned ", err)
}
}
}
func main() {
go updateUptime()
go checkClosure()
go syncMatrix()
http.HandleFunc("/", rootHandler)
http.HandleFunc("/api", apiHandler)
http.HandleFunc("/img", imgHandler)