diff --git a/td.go b/td.go index e086b82..1cb8714 100644 --- a/td.go +++ b/td.go @@ -72,6 +72,7 @@ func ListenCW(c *tdlib.Client) { func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { var msgCount int32 = 0 var msgParsed int32 = 0 + var loopOverflow int32 = 0 var lastParsedID64 int64 = int64(math.MaxInt64) var lastParsedTime time.Time = time.Now() var chat int64 @@ -160,8 +161,13 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { lastParsedID64 = -1 } if prevLastParsedID64 == lastParsedID64 { - // we should be at the end ! - lastParsedID64 = -1 + loopOverflow++ + if loopOverflow == 5 { + // we should be at the end ! + lastParsedID64 = -1 + } else { + time.Sleep(5 * time.Second) + } } } log.Printf("Exported %d messages.\n", msgCount)