mirror of
https://github.com/Lomanic/presence-button-web
synced 2024-11-21 21:17:29 +00:00
Set Matrix online status and mark encountered messages as read
This commit is contained in:
parent
91999707d0
commit
d3d1b1676c
25
main.go
25
main.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user