mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-11-10 16:19:18 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a15089b18d |
||
|
|
945474343f |
||
|
|
5c8c1fc835 |
3 changed files with 15 additions and 14 deletions
|
|
@ -293,11 +293,17 @@ func (wa *WhatsAppClient) handleWAHistorySync(
|
||||||
for i, rawMsg := range rawMessages {
|
for i, rawMsg := range rawMessages {
|
||||||
// Don't store messages that will just be skipped.
|
// Don't store messages that will just be skipped.
|
||||||
msgEvt, err := wa.Client.ParseWebMessage(jid, rawMsg.GetMessage())
|
msgEvt, err := wa.Client.ParseWebMessage(jid, rawMsg.GetMessage())
|
||||||
if err != nil {
|
if err != nil && getMessageType(rawMsg.GetMessage().GetMessage()) == "ignore" {
|
||||||
|
ignoredTypes++
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
log.Warn().Err(err).
|
log.Warn().Err(err).
|
||||||
Int("msg_index", i).
|
Int("msg_index", i).
|
||||||
Str("msg_id", rawMsg.GetMessage().GetKey().GetID()).
|
Str("msg_id", rawMsg.GetMessage().GetKey().GetID()).
|
||||||
Uint64("msg_time_seconds", rawMsg.GetMessage().GetMessageTimestamp()).
|
Uint64("msg_time_seconds", rawMsg.GetMessage().GetMessageTimestamp()).
|
||||||
|
Stringer("stub_type", rawMsg.GetMessage().GetMessageStubType()).
|
||||||
|
Str("message_type", getMessageType(rawMsg.GetMessage().GetMessage())).
|
||||||
|
Bool("from_me", rawMsg.GetMessage().GetKey().GetFromMe()).
|
||||||
Msg("Dropping historical message due to parse error")
|
Msg("Dropping historical message due to parse error")
|
||||||
log.Trace().
|
log.Trace().
|
||||||
Any("web_message_info", rawMsg.GetMessage()).
|
Any("web_message_info", rawMsg.GetMessage()).
|
||||||
|
|
@ -399,8 +405,6 @@ func (wa *WhatsAppClient) handleWAHistorySync(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const historySyncQueuedTimeout = 10 * time.Minute
|
|
||||||
|
|
||||||
func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
log := wa.UserLogin.Log.With().
|
log := wa.UserLogin.Log.With().
|
||||||
Str("action", "create portals from history sync").
|
Str("action", "create portals from history sync").
|
||||||
|
|
@ -444,9 +448,6 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
// We don't currently support new PSAs, so don't bother backfilling them either
|
// We don't currently support new PSAs, so don't bother backfilling them either
|
||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
} else if queuedAt, ok := wa.historySyncQueued.Get(conv.ChatJID); ok && time.Since(queuedAt) < historySyncQueuedTimeout {
|
|
||||||
wg.Done()
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
// TODO can the chat info fetch be avoided entirely?
|
// TODO can the chat info fetch be avoided entirely?
|
||||||
select {
|
select {
|
||||||
|
|
@ -487,7 +488,6 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wa.historySyncQueued.Set(conv.ChatJID, time.Now())
|
|
||||||
res := wa.UserLogin.QueueRemoteEvent(&simplevent.ChatResync{
|
res := wa.UserLogin.QueueRemoteEvent(&simplevent.ChatResync{
|
||||||
EventMeta: simplevent.EventMeta{
|
EventMeta: simplevent.EventMeta{
|
||||||
Type: bridgev2.RemoteEventChatResync,
|
Type: bridgev2.RemoteEventChatResync,
|
||||||
|
|
@ -503,7 +503,6 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Msg("Failed to mark conversation as bridged")
|
zerolog.Ctx(ctx).Err(err).Msg("Failed to mark conversation as bridged")
|
||||||
}
|
}
|
||||||
wa.historySyncQueued.Delete(conv.ChatJID)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -511,7 +510,6 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
LatestMessageTS: conv.LastMessageTimestamp,
|
LatestMessageTS: conv.LastMessageTimestamp,
|
||||||
})
|
})
|
||||||
if !res.Success {
|
if !res.Success {
|
||||||
wa.historySyncQueued.Delete(conv.ChatJID)
|
|
||||||
log.Debug().Msg("Cancelling history sync portal creation loop")
|
log.Debug().Msg("Cancelling history sync portal creation loop")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -519,9 +517,6 @@ func (wa *WhatsAppClient) createPortalsFromHistorySync(ctx context.Context) {
|
||||||
log.Info().Int("conversation_count", len(conversations)).Msg("Finished creating portals from history sync")
|
log.Info().Int("conversation_count", len(conversations)).Msg("Finished creating portals from history sync")
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if wa.historySyncQueued.Len() > 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
wa.UserLogin.Metadata.(*waid.UserLoginMetadata).HistorySyncPortalsNeedCreating = false
|
wa.UserLogin.Metadata.(*waid.UserLoginMetadata).HistorySyncPortalsNeedCreating = false
|
||||||
err = wa.UserLogin.Save(ctx)
|
err = wa.UserLogin.Save(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ func (wa *WhatsAppConnector) LoadUserLogin(ctx context.Context, login *bridgev2.
|
||||||
MC: noopMCInstance,
|
MC: noopMCInstance,
|
||||||
|
|
||||||
historySyncWakeup: make(chan struct{}, 1),
|
historySyncWakeup: make(chan struct{}, 1),
|
||||||
historySyncQueued: exsync.NewMap[types.JID, time.Time](),
|
|
||||||
resyncQueue: make(map[types.JID]resyncQueueItem),
|
resyncQueue: make(map[types.JID]resyncQueueItem),
|
||||||
directMediaRetries: make(map[networkid.MessageID]*directMediaRetry),
|
directMediaRetries: make(map[networkid.MessageID]*directMediaRetry),
|
||||||
mediaRetryLock: semaphore.NewWeighted(wa.Config.HistorySync.MediaRequests.MaxAsyncHandle),
|
mediaRetryLock: semaphore.NewWeighted(wa.Config.HistorySync.MediaRequests.MaxAsyncHandle),
|
||||||
|
|
@ -115,7 +114,6 @@ type WhatsAppClient struct {
|
||||||
MC mClient
|
MC mClient
|
||||||
|
|
||||||
historySyncWakeup chan struct{}
|
historySyncWakeup chan struct{}
|
||||||
historySyncQueued *exsync.Map[types.JID, time.Time]
|
|
||||||
stopLoops atomic.Pointer[context.CancelFunc]
|
stopLoops atomic.Pointer[context.CancelFunc]
|
||||||
resyncQueue map[types.JID]resyncQueueItem
|
resyncQueue map[types.JID]resyncQueueItem
|
||||||
resyncQueueLock sync.Mutex
|
resyncQueueLock sync.Mutex
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,14 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
|
||||||
if assocType := messageAssoc.GetAssociationType(); assocType == waE2E.MessageAssociation_HD_IMAGE_DUAL_UPLOAD || assocType == waE2E.MessageAssociation_HD_VIDEO_DUAL_UPLOAD {
|
if assocType := messageAssoc.GetAssociationType(); assocType == waE2E.MessageAssociation_HD_IMAGE_DUAL_UPLOAD || assocType == waE2E.MessageAssociation_HD_VIDEO_DUAL_UPLOAD {
|
||||||
parentKey := messageAssoc.GetParentMessageKey()
|
parentKey := messageAssoc.GetParentMessageKey()
|
||||||
protocolMsg, shouldHideEdit := makeHDMediaReplacementEdit(evt.Message, parentKey)
|
protocolMsg, shouldHideEdit := makeHDMediaReplacementEdit(evt.Message, parentKey)
|
||||||
|
if protocolMsg.GetEditedMessage() == nil {
|
||||||
|
wa.UserLogin.Log.Debug().
|
||||||
|
Str("message_id", evt.Info.ID).
|
||||||
|
Str("parent_id", parentKey.GetID()).
|
||||||
|
Stringer("assoc_type", assocType).
|
||||||
|
Msg("Ignoring HD replacement message without replacement content")
|
||||||
|
return
|
||||||
|
}
|
||||||
dontRenderEdited = shouldHideEdit
|
dontRenderEdited = shouldHideEdit
|
||||||
wa.UserLogin.Log.Debug().
|
wa.UserLogin.Log.Debug().
|
||||||
Str("message_id", evt.Info.ID).
|
Str("message_id", evt.Info.ID).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue