Remove some commented code and add note about future code to remove

This commit is contained in:
Tulir Asokan 2021-10-27 19:48:14 +03:00
parent 2cd6713cc4
commit 92c9ec6203
2 changed files with 5 additions and 89 deletions

View file

@ -987,6 +987,8 @@ func (portal *Portal) backfill(source *User, messages []*waProto.HistorySyncMsg)
historyBatch.StateEventsAtStart = make([]*event.Event, 1)
newBatch.StateEventsAtStart = make([]*event.Event, 1)
// TODO remove the dummy state events after https://github.com/matrix-org/synapse/pull/11188
emptyStr := ""
dummyStateEvent := event.Event{
Type: BackfillDummyStateEvent,
@ -997,8 +999,8 @@ func (portal *Portal) backfill(source *User, messages []*waProto.HistorySyncMsg)
}
historyBatch.StateEventsAtStart[0] = &dummyStateEvent
newBatch.StateEventsAtStart[0] = &dummyStateEvent
addedMembers := make(map[id.UserID]*event.MemberEventContent)
addedMembers := make(map[id.UserID]*event.MemberEventContent)
addMember := func(puppet *Puppet) {
if _, alreadyAdded := addedMembers[puppet.MXID]; alreadyAdded {
return
@ -1096,7 +1098,7 @@ func (portal *Portal) backfill(source *User, messages []*waProto.HistorySyncMsg)
}
}
if len(historyBatch.Events) > 0 {
if len(historyBatch.Events) > 0 && len(historyBatch.PrevEventID) > 0 {
portal.log.Infofln("Sending %d historical messages...", len(historyBatch.Events))
historyResp, err := portal.MainIntent().BatchSend(portal.MXID, &historyBatch)
if err != nil {
@ -1112,7 +1114,7 @@ func (portal *Portal) backfill(source *User, messages []*waProto.HistorySyncMsg)
}
}
if len(newBatch.Events) > 0 {
if len(newBatch.Events) > 0 && len(newBatch.PrevEventID) > 0 {
portal.log.Debugln("Sending a dummy event to avoid forward extremity errors with forward backfill")
_, err := portal.MainIntent().SendMessageEvent(portal.MXID, ForwardBackfillDummyEvent, struct{}{})
if err != nil {

86
user.go
View file

@ -569,62 +569,6 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, portal *Port
}
}
//func (user *User) syncPortal(chat Chat) {
// // Don't sync unless chat meta sync is enabled or portal doesn't exist
// if user.bridge.Config.Bridge.ChatMetaSync || len(chat.Portal.MXID) == 0 {
// failedToCreate := chat.Portal.Sync(user, chat.Contact)
// if failedToCreate {
// return
// }
// }
// err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
// if err != nil {
// chat.Portal.log.Errorln("Error backfilling history:", err)
// }
//}
//
//func (user *User) syncPortals(chatMap map[string]whatsapp.Chat, createAll bool) {
// // TODO use contexts instead of checking if user.Conn is the same?
// connAtStart := user.Conn
//
// chats := user.collectChatList(chatMap)
//
// limit := user.bridge.Config.Bridge.InitialChatSync
// if limit < 0 {
// limit = len(chats)
// }
// if user.Conn != connAtStart {
// user.log.Debugln("Connection seems to have changed before sync, cancelling")
// return
// }
// now := time.Now().Unix()
// user.log.Infoln("Syncing portals")
// doublePuppet := user.bridge.GetPuppetByCustomMXID(user.MXID)
// for i, chat := range chats {
// if chat.LastMessageTime+user.bridge.Config.Bridge.SyncChatMaxAge < now {
// break
// }
// create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
// if len(chat.Portal.MXID) > 0 || create || createAll {
// user.log.Debugfln("Syncing chat %+v", chat.Chat.Source)
// justCreated := len(chat.Portal.MXID) == 0
// user.syncPortal(chat)
// user.syncChatDoublePuppetDetails(doublePuppet, chat, justCreated)
// }
// }
// if user.Conn != connAtStart {
// user.log.Debugln("Connection seems to have changed during sync, cancelling")
// return
// }
// user.UpdateDirectChats(nil)
//
// user.log.Infoln("Finished syncing portals")
// select {
// case user.syncPortalsDone <- struct{}{}:
// default:
// }
//}
func (user *User) getDirectChats() map[id.UserID][]id.RoomID {
res := make(map[id.UserID][]id.RoomID)
privateChats := user.bridge.DB.Portal.FindPrivateChats(user.JID.ToNonAD())
@ -702,36 +646,6 @@ func (user *User) syncPuppet(jid types.JID) {
user.bridge.GetPuppetByJID(jid).SyncContact(user, false)
}
//func (user *User) HandlePresence(info whatsapp.PresenceEvent) {
// puppet := user.bridge.GetPuppetByJID(info.SenderJID)
// switch info.Status {
// case whatsapp.PresenceUnavailable:
// _ = puppet.DefaultIntent().SetPresence("offline")
// case whatsapp.PresenceAvailable:
// if len(puppet.typingIn) > 0 && puppet.typingAt+15 > time.Now().Unix() {
// portal := user.bridge.GetPortalByMXID(puppet.typingIn)
// _, _ = puppet.IntentFor(portal).UserTyping(puppet.typingIn, false, 0)
// puppet.typingIn = ""
// puppet.typingAt = 0
// } else {
// _ = puppet.DefaultIntent().SetPresence("online")
// }
// case whatsapp.PresenceComposing:
// portal := user.GetPortalByJID(info.JID)
// if len(puppet.typingIn) > 0 && puppet.typingAt+15 > time.Now().Unix() {
// if puppet.typingIn == portal.MXID {
// return
// }
// _, _ = puppet.IntentFor(portal).UserTyping(puppet.typingIn, false, 0)
// }
// if len(portal.MXID) > 0 {
// puppet.typingIn = portal.MXID
// puppet.typingAt = time.Now().Unix()
// _, _ = puppet.IntentFor(portal).UserTyping(portal.MXID, true, 15*1000)
// }
// }
//}
const WATypingTimeout = 15 * time.Second
func (user *User) handleChatPresence(presence *events.ChatPresence) {