]> git.giacomolli.uk - onechat/blobdiff - whatsapp_groups.go
Reflow comments over the reflow width
[onechat] / whatsapp_groups.go
index 56676e5264fb363e709b2785bd095c6c9d42c012..6e9bed3eae9c27c80af78543b5bf4cf15326d939 100644 (file)
@@ -2,13 +2,17 @@ package main
 
 import (
        "context"
-       "log"
+       "log/slog"
        "maps"
        "sync"
        "time"
 )
 
 const (
+       // whatsappGroupLookupTimeout is the longest time of a read of group
+       // names.
+       whatsappGroupLookupTimeout = 10 * time.Second
+
        // whatsappGroupsRefresh is the shortest time between two reads of the
        // groups from WhatsApp for a group with no name.
        whatsappGroupsRefresh = time.Minute
@@ -23,7 +27,7 @@ const (
 
 // newWhatsAppGroups returns the names of the groups with no names yet. logger
 // gets the failures of a read.
-func newWhatsAppGroups(logger *log.Logger) *WhatsAppGroups {
+func newWhatsAppGroups(logger *slog.Logger) *WhatsAppGroups {
        return &WhatsAppGroups{
                logger: logger,
                names:  make(map[string]string),
@@ -36,7 +40,7 @@ func newWhatsAppGroups(logger *log.Logger) *WhatsAppGroups {
 // read, and readAt the time of the last read that succeeded. The mutex
 // protects all fields after logger.
 type WhatsAppGroups struct {
-       logger *log.Logger
+       logger *slog.Logger
 
        mutex   sync.Mutex
        names   map[string]string
@@ -77,12 +81,12 @@ func (g *WhatsAppGroups) read(ctx context.Context, link WhatsAppLink) bool {
                return false
        }
 
-       ctx, cancel := context.WithTimeout(ctx, whatsappLookupTime)
+       ctx, cancel := context.WithTimeout(ctx, whatsappGroupLookupTimeout)
        defer cancel()
 
        groups, err := link.client.GetJoinedGroups(ctx)
        if err != nil {
-               g.logger.Printf("group list failed: %s", whatsappRedact(link.own, err.Error()))
+               g.logger.Warn("group list failed", "err", whatsappRedact(link.own, err.Error()))
        }
 
        g.mutex.Lock()