Эх сурвалжийг харах

Add some logs and increase timestamp difference for short-circuiting deduplication

Tulir Asokan 4 жил өмнө
parent
commit
4b80c15a0a
2 өөрчлөгдсөн 9 нэмэгдсэн , 2 устгасан
  1. 7 2
      portal.go
  2. 2 0
      user.go

+ 7 - 2
portal.go

@@ -62,6 +62,7 @@ const StatusBroadcastName = "WhatsApp Status Broadcast"
 const BroadcastTopic = "WhatsApp broadcast list"
 const BroadcastTopic = "WhatsApp broadcast list"
 const UnnamedBroadcastName = "Unnamed broadcast list"
 const UnnamedBroadcastName = "Unnamed broadcast list"
 const PrivateChatTopic = "WhatsApp private chat"
 const PrivateChatTopic = "WhatsApp private chat"
+
 var ErrStatusBroadcastDisabled = errors.New("status bridging is disabled")
 var ErrStatusBroadcastDisabled = errors.New("status bridging is disabled")
 
 
 func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal {
 func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal {
@@ -380,8 +381,12 @@ func (portal *Portal) startHandling(source *User, info whatsapp.MessageInfo, msg
 			atomic.CompareAndSwapUint64(&portal.lastMessageTs, 0, uint64(lastMessage.Timestamp))
 			atomic.CompareAndSwapUint64(&portal.lastMessageTs, 0, uint64(lastMessage.Timestamp))
 		}
 		}
 	}
 	}
-	if portal.lastMessageTs > info.Timestamp+1 {
-		portal.log.Debugfln("Not handling %s (%s): message is older (%d) than last bridge message (%d)", info.Id, msgType, info.Timestamp, portal.lastMessageTs)
+
+	// If there are messages slightly older than the last message, it's possible the order is just wrong,
+	// so don't short-circuit and check the database for duplicates.
+	const timestampIgnoreFuzziness = 5 * 60
+	if portal.lastMessageTs > info.Timestamp+timestampIgnoreFuzziness {
+		portal.log.Debugfln("Not handling %s (%s): message is >5 minutes older (%d) than last bridge message (%d)", info.Id, msgType, info.Timestamp, portal.lastMessageTs)
 	} else if portal.isRecentlyHandled(info.Id) {
 	} else if portal.isRecentlyHandled(info.Id) {
 		portal.log.Debugfln("Not handling %s (%s): message was recently handled", info.Id, msgType)
 		portal.log.Debugfln("Not handling %s (%s): message was recently handled", info.Id, msgType)
 	} else if portal.isDuplicate(info.Id) {
 	} else if portal.isDuplicate(info.Id) {

+ 2 - 0
user.go

@@ -677,7 +677,9 @@ func (user *User) HandleChatList(chats []whatsapp.Chat) {
 	}
 	}
 	select {
 	select {
 	case user.chatListReceived <- struct{}{}:
 	case user.chatListReceived <- struct{}{}:
+		user.log.Debugln("Sent chat list receive confirmation from HandleChatList")
 	default:
 	default:
+		user.log.Debugln("Failed to send chat list receive confirmation from HandleChatList, channel probably full")
 	}
 	}
 	go user.syncPortals(chatMap, false)
 	go user.syncPortals(chatMap, false)
 }
 }