X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/6844f8c992ec4e276a3a0d93b544de0127eebbd2..0e57dcfc96cd95268d5dd00af7ce0594721d3ded:/whatsapp.go diff --git a/whatsapp.go b/whatsapp.go index 0c68a44..851cfd1 100644 --- a/whatsapp.go +++ b/whatsapp.go @@ -190,6 +190,7 @@ type WhatsApp struct { state *WhatsAppState groups *WhatsAppGroups inbox *WhatsAppInbox + routes *Routes sessionMutex sync.Mutex mutex sync.Mutex @@ -358,23 +359,31 @@ func (w *WhatsApp) Command(args string, answer func(text string)) { } // Status returns the state of the link: not linked, linked and connected, or -// linked and disconnected, with the times of the connection. It never holds the -// phone number. +// linked and disconnected, with the times of the connection and the routes. +// Route source IDs can hold the phone numbers of other chats. func (w *WhatsApp) Status() string { w.mutex.Lock() defer w.mutex.Unlock() + routes := "" + if w.routes != nil { + listed := w.routes.List() + if listed != "No routes." { + routes = "\nWhatsApp routes:\n" + listed + } + } + switch { case !w.linked: - return "WhatsApp is not linked. Run /whatsapp pair PHONE to link it." + return "WhatsApp is not linked. Run /whatsapp pair PHONE to link it." + routes case w.connected: - return "WhatsApp is linked and connected since " + w.connectedAt.Format(whatsappTimeLayout) + "." + return "WhatsApp is linked and connected since " + w.connectedAt.Format(whatsappTimeLayout) + "." + routes case w.disconnectedAt.IsZero(): - return "WhatsApp is linked and not connected yet." + return "WhatsApp is linked and not connected yet." + routes case w.connectedAt.IsZero(): - return "WhatsApp is linked and disconnected since " + w.disconnectedAt.Format(whatsappTimeLayout) + "." + return "WhatsApp is linked and disconnected since " + w.disconnectedAt.Format(whatsappTimeLayout) + "." + routes default: - return "WhatsApp is linked and disconnected since " + w.disconnectedAt.Format(whatsappTimeLayout) + ". The last connection started at " + w.connectedAt.Format(whatsappTimeLayout) + "." + return "WhatsApp is linked and disconnected since " + w.disconnectedAt.Format(whatsappTimeLayout) + ". The last connection started at " + w.connectedAt.Format(whatsappTimeLayout) + "." + routes } }