Mark media messages as sent when a 404 is returned while downloading

master
Hugo Thunnissen 4 years ago
parent e14614da9e
commit c63932686a

@ -62,6 +62,8 @@ func MakeImageMessageAction(w *WhappContext, m whatsapp.ImageMessage) MessageAct
if err != nil { if err != nil {
w.BridgeCtx.SendLog(err.Error()) w.BridgeCtx.SendLog(err.Error())
w.markSentIf404Download(&m.Info.Id, err)
return err return err
} }
@ -103,6 +105,8 @@ func MakeDocumentMessageAction(w *WhappContext, m whatsapp.DocumentMessage) Mess
if err != nil { if err != nil {
w.BridgeCtx.SendLog(err.Error()) w.BridgeCtx.SendLog(err.Error())
w.markSentIf404Download(&m.Info.Id, err)
return err return err
} }
@ -144,6 +148,8 @@ func MakeAudioMessageAction(w *WhappContext, m whatsapp.AudioMessage) MessageAct
if err != nil { if err != nil {
w.BridgeCtx.SendLog(err.Error()) w.BridgeCtx.SendLog(err.Error())
w.markSentIf404Download(&m.Info.Id, err)
return err return err
} }
@ -185,6 +191,8 @@ func MakeVideoMessageAction(w *WhappContext, m whatsapp.VideoMessage) MessageAct
if err != nil { if err != nil {
w.BridgeCtx.SendLog(err.Error()) w.BridgeCtx.SendLog(err.Error())
w.markSentIf404Download(&m.Info.Id, err)
return err return err
} }

@ -91,3 +91,15 @@ func (w *WhappContext) ShouldMessageBeSent(info whatsapp.MessageInfo) bool {
func (w *WhappContext) DCCtx() *deltachat.Context { func (w *WhappContext) DCCtx() *deltachat.Context {
return w.BridgeCtx.DCContext return w.BridgeCtx.DCContext
} }
// Helper to easily mark failed media downloads as sent anyways.
func (w *WhappContext) markSentIf404Download(ID *string, err error) {
if err == whatsapp.ErrMediaDownloadFailedWith404 {
err := w.MessageTracker.MarkSent(ID)
if err != nil {
log.Println(err)
w.BridgeCtx.SendLog(err.Error())
}
}
}

@ -9,6 +9,7 @@ import (
core "github.com/hugot/whapp-deltachat/whappdc-core" core "github.com/hugot/whapp-deltachat/whappdc-core"
) )
// WhappHandler implements go-whaptsapp.Handler
type WhappHandler struct { type WhappHandler struct {
WhappCtx *WhappContext WhappCtx *WhappContext
MessageWorker *MessageWorker MessageWorker *MessageWorker

Loading…
Cancel
Save