X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/790279faf0fda789d93a75f6f5996e65d5de4a18..80e348724041a694002fc38f57e8868b9b9a2be9:/whatsapp_groups.go diff --git a/whatsapp_groups.go b/whatsapp_groups.go index ec5c892..5eedd5d 100644 --- a/whatsapp_groups.go +++ b/whatsapp_groups.go @@ -9,6 +9,10 @@ import ( ) 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 @@ -21,15 +25,6 @@ const ( 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 @@ -44,6 +39,15 @@ type WhatsAppGroups struct { 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. @@ -77,7 +81,7 @@ 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)