]> git.giacomolli.uk - onechat/blobdiff - whatsapp_groups.go
Order model and chat declarations
[onechat] / whatsapp_groups.go
index 4d6c7e588be6501bb4c7e06745ba2fb6a427e892..5eedd5dc29e804472fcc4e6ca803c84c62454a4b 100644 (file)
@@ -9,9 +9,9 @@ import (
 )
 
 const (
 )
 
 const (
-       // whatsappGroupsLookupTime is the longest time of a read of group
+       // whatsappGroupLookupTimeout is the longest time of a read of group
        // names.
        // names.
-       whatsappGroupsLookupTime = 10 * time.Second
+       whatsappGroupLookupTimeout = 10 * time.Second
 
        // whatsappGroupsRefresh is the shortest time between two reads of the
        // groups from WhatsApp for a group with no name.
 
        // whatsappGroupsRefresh is the shortest time between two reads of the
        // groups from WhatsApp for a group with no name.
@@ -25,15 +25,6 @@ const (
        whatsappGroupsAge = time.Hour
 )
 
        whatsappGroupsAge = time.Hour
 )
 
-// newWhatsAppGroups returns the names of the groups with no names yet. logger
-// gets the failures of a read.
-func newWhatsAppGroups(logger *slog.Logger) *WhatsAppGroups {
-       return &WhatsAppGroups{
-               logger: logger,
-               names:  make(map[string]string),
-       }
-}
-
 // WhatsAppGroups holds the names of the groups of the account, by the ID of the
 // group. They come from the events of the groups and from reads of the groups
 // from WhatsApp, and they stay in memory only. triedAt is the time of the last
 // WhatsAppGroups holds the names of the groups of the account, by the ID of the
 // group. They come from the events of the groups and from reads of the groups
 // from WhatsApp, and they stay in memory only. triedAt is the time of the last
@@ -48,6 +39,15 @@ type WhatsAppGroups struct {
        readAt  time.Time
 }
 
        readAt  time.Time
 }
 
+// newWhatsAppGroups returns the names of the groups with no names yet. logger
+// gets the failures of a read.
+func newWhatsAppGroups(logger *slog.Logger) *WhatsAppGroups {
+       return &WhatsAppGroups{
+               logger: logger,
+               names:  make(map[string]string),
+       }
+}
+
 // name returns the name of the group id, or whatsappUnknownGroup. A group that
 // is not in the names reads the groups from WhatsApp with the client of link
 // again, at most once in whatsappGroupsRefresh.
 // name returns the name of the group id, or whatsappUnknownGroup. A group that
 // is not in the names reads the groups from WhatsApp with the client of link
 // again, at most once in whatsappGroupsRefresh.
@@ -81,7 +81,7 @@ func (g *WhatsAppGroups) read(ctx context.Context, link WhatsAppLink) bool {
                return false
        }
 
                return false
        }
 
-       ctx, cancel := context.WithTimeout(ctx, whatsappGroupsLookupTime)
+       ctx, cancel := context.WithTimeout(ctx, whatsappGroupLookupTimeout)
        defer cancel()
 
        groups, err := link.client.GetJoinedGroups(ctx)
        defer cancel()
 
        groups, err := link.client.GetJoinedGroups(ctx)