From f66a73f5f709b84864c2841bebf0102d9d157329 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 11 May 2019 16:32:01 +0800 Subject: [PATCH] test --- td.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/td.go b/td.go index 2576b55..7515178 100644 --- a/td.go +++ b/td.go @@ -73,6 +73,7 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { var msgCount int32 = 0 var msgParsed int32 = 0 var lastParsedID64 int64 = int64(math.MaxInt64) + var loopCount int32 = 1 var lastParsedTime time.Time = time.Now() var chat int64 var m ChatWarsMessage @@ -95,13 +96,15 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { fmt.Printf("Exporting historic messages for chat %d (%s) ...\n", chat, chatDetails.Title) } - for lastParsedID64 >= 0 { + for lastParsedID64 >= 0 && loopCount > 0 { msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 33, false) + loopCount = 0 if err != nil { if err.Error() == "timeout" { logOnError(err, "Waiting...") - fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64) + fmt.Printf("Timeout : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64) time.Sleep(5 * time.Second) + loopCount = 1 } else { logOnError(err, "Cannot get history") lastParsedID64 = -1 @@ -149,6 +152,7 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { if m.ID64 < lastParsedID64 { lastParsedID64 = msg.ID lastParsedTime = m.Date + loopCount = loopCount + 1 } if msgParsed%1000 == 0 { fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64)