]> git.giacomolli.uk - onechat/blobdiff - whatsapp.go
Deliver routed WhatsApp batches to children
[onechat] / whatsapp.go
index 0c68a44ace8a0184b89789e473537d75ec876199..851cfd1c348053a8dba203afc24a20e7e4a55ec3 100644 (file)
@@ -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
        }
 }