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
1 changed files with 25 additions and 0 deletions

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)