X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=r3-netstatus%2Fmain.go;h=6f53ac3bd64b80a2c750cc39905473d5a5d7d49e;hb=5c31e88216090d9cd9de24f904b105878728ddbf;hp=c6229ab3608afd404337049d34c70cdf7507b2cb;hpb=988a91bab029af7738561b948f7f27023d5102b1;p=svn42.git diff --git a/r3-netstatus/main.go b/r3-netstatus/main.go index c6229ab..6f53ac3 100644 --- a/r3-netstatus/main.go +++ b/r3-netstatus/main.go @@ -52,12 +52,12 @@ func composeMessage(present, locked, shut bool, who string, ts int64) string { } func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface{}) { - events := ps.Sub("presence","door","buttons") + events := ps.Sub("presence","door","buttons","updateinterval") defer func() { if x := recover(); x != nil { fmt.Printf("handleIncomingXMPPStanzas: run time panic: %v", x) - ps.Unsub(events, "presence","door","buttons") + ps.Unsub(events, "presence","door","buttons","updateinterval") close(xmpp_presence_events_chan_) } }() @@ -66,6 +66,8 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface var last_buttonpress int64 = 0 var who string button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)" + present_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"} + notpresent_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"} button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"} xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe, "Nobody is here"} @@ -76,14 +78,10 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface present = event.Present xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: true} if present { - if time.Now().Unix() - last_buttonpress < button_press_timeout_ { - xmpp_presence_events_chan_ <- button_status - } else { - xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"} - } + xmpp_presence_events_chan_ <- present_status } else { - xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"} - } + xmpp_presence_events_chan_ <- notpresent_status + } case DoorCommandEvent: if len(event.Who) > 0 && len(event.Using) > 0 { who = fmt.Sprintf("%s (%s)",event.Who, event.Using) @@ -99,6 +97,11 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo} xmpp_presence_events_chan_ <- button_status last_buttonpress = event.Ts + case TimeTick: + if present && last_buttonpress > 0 && time.Now().Unix() - last_buttonpress > button_press_timeout_ { + xmpp_presence_events_chan_ <- present_status + last_buttonpress = 0 + } } } } @@ -131,7 +134,7 @@ func main() { case e := <-newlinequeue: ParseSocketInputLine(e, ps) //, brn) case <-ticker.C: - ps.Pub(TimeTick{time.Now().Unix()}, "publishjson") + ps.Pub(TimeTick{time.Now().Unix()}, "updateinterval") } } }