From 7e82d698b8b031bd7f3560c6d848f60b8b435688 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 1 Oct 2024 17:23:43 +0300 Subject: [PATCH] msgconv/mediaretry: add appropriate suffix to error notice --- pkg/connector/connector.go | 8 ++++++++ pkg/msgconv/msgconv.go | 1 + pkg/msgconv/wa-media.go | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index 84de9a54..8909eb3b 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -48,6 +48,14 @@ func (wa *WhatsAppConnector) Init(bridge *bridgev2.Bridge) { wa.MsgConv = msgconv.New(bridge) wa.MsgConv.AnimatedStickerConfig = wa.Config.AnimatedSticker wa.MsgConv.FetchURLPreviews = wa.Config.URLPreviews + wa.MsgConv.OldMediaSuffix = "Requesting old media is not enabled on this bridge." + if wa.Config.HistorySync.MediaRequests.AutoRequestMedia { + if wa.Config.HistorySync.MediaRequests.RequestMethod == MediaRequestMethodImmediate { + wa.MsgConv.OldMediaSuffix = "Media will be requested from your phone automatically soon." + } else if wa.Config.HistorySync.MediaRequests.RequestMethod == MediaRequestMethodLocalTime { + wa.MsgConv.OldMediaSuffix = "Media will be requested from your phone automatically overnight." + } + } wa.DB = wadb.New(bridge.ID, bridge.DB.Database, bridge.Log.With().Str("db_section", "whatsapp").Logger()) wa.Bridge.Commands.(*commands.Processor).AddHandlers( cmdAccept, diff --git a/pkg/msgconv/msgconv.go b/pkg/msgconv/msgconv.go index f145ce7d..edcbc862 100644 --- a/pkg/msgconv/msgconv.go +++ b/pkg/msgconv/msgconv.go @@ -36,6 +36,7 @@ type MessageConverter struct { HTMLParser *format.HTMLParser AnimatedStickerConfig AnimatedStickerConfig FetchURLPreviews bool + OldMediaSuffix string } func New(br *bridgev2.Bridge) *MessageConverter { diff --git a/pkg/msgconv/wa-media.go b/pkg/msgconv/wa-media.go index 8161c6a5..f3aeadef 100644 --- a/pkg/msgconv/wa-media.go +++ b/pkg/msgconv/wa-media.go @@ -426,7 +426,7 @@ func (mc *MessageConverter) makeMediaFailure(ctx context.Context, mediaInfo *Pre Error: waid.MsgErrMediaNotFound, MediaMeta: serializedMedia, } - errorMsg = fmt.Sprintf("Old %s. Viewing old media is not currently supported.", mediaInfo.TypeDescription) + errorMsg = fmt.Sprintf("Old %s. %s", mediaInfo.TypeDescription, mc.OldMediaSuffix) } zerolog.Ctx(ctx).WithLevel(logLevel).Err(err). Str("media_type", mediaInfo.TypeDescription).