Check last message ID before attempting backfill
This commit is contained in:
22
portal.go
22
portal.go
@@ -1968,11 +1968,24 @@ func (portal *Portal) UpdateInfo(source *User, meta *discordgo.Channel) *discord
|
|||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) ForwardBackfill(source *User) error {
|
func (portal *Portal) ForwardBackfill(source *User, meta *discordgo.Channel) error {
|
||||||
portal.log.Debugln("Checking for missing messages to fill")
|
portal.log.Debugln("Checking for missing messages to fill")
|
||||||
lastMessage := portal.bridge.DB.Message.GetLast(portal.Key)
|
lastMessage := portal.bridge.DB.Message.GetLast(portal.Key)
|
||||||
if lastMessage == nil {
|
if lastMessage == nil {
|
||||||
portal.log.Debugln("No last message in portal, can't forward backfill")
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metaLastMessageID, err := strconv.ParseInt(meta.LastMessageID, 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorfln("Last message ID %s isn't integer", meta.LastMessageID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dbLastMessageID, err := strconv.ParseInt(lastMessage.DiscordID, 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorfln("Last message ID %s isn't integer", lastMessage.DiscordID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if metaLastMessageID <= dbLastMessageID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1995,14 +2008,11 @@ func (portal *Portal) ForwardBackfill(source *User) error {
|
|||||||
|
|
||||||
if len(messages) < 100 {
|
if len(messages) < 100 {
|
||||||
// Assume that was all the missing messages
|
// Assume that was all the missing messages
|
||||||
break
|
return nil
|
||||||
}
|
}
|
||||||
lastMessage = portal.bridge.DB.Message.GetLast(portal.Key)
|
lastMessage = portal.bridge.DB.Message.GetLast(portal.Key)
|
||||||
if lastMessage == nil {
|
if lastMessage == nil {
|
||||||
portal.log.Debugln("No last message in portal, can't forward backfill")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
user.go
4
user.go
@@ -728,7 +728,7 @@ func (user *User) handlePrivateChannel(portal *Portal, meta *discordgo.Channel,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
portal.UpdateInfo(user, meta)
|
portal.UpdateInfo(user, meta)
|
||||||
portal.ForwardBackfill(user)
|
portal.ForwardBackfill(user, meta)
|
||||||
}
|
}
|
||||||
user.MarkInPortal(database.UserPortal{
|
user.MarkInPortal(database.UserPortal{
|
||||||
DiscordID: portal.Key.ChannelID,
|
DiscordID: portal.Key.ChannelID,
|
||||||
@@ -843,7 +843,7 @@ func (user *User) handleGuild(meta *discordgo.Guild, timestamp time.Time, isInSp
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
portal.UpdateInfo(user, ch)
|
portal.UpdateInfo(user, ch)
|
||||||
portal.ForwardBackfill(user)
|
portal.ForwardBackfill(user, ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user