From bc218d176f44d998bcff81829edaefcbc9e9f188 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 4 May 2019 18:52:20 +0800 Subject: [PATCH] test --- td.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/td.go b/td.go index 4a7cb5f..2d5ff1f 100644 --- a/td.go +++ b/td.go @@ -68,10 +68,9 @@ func ListenCW(c *tdlib.Client) { } func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { - var lastMsgID64 int64 = int64(math.MaxInt64) var msgCount int32 = 0 var msgParsed int32 = 0 - var lastMsgTime time.Time = time.Now() + var lastParsedID64 int64 = int64(math.MaxInt64) var lastParsedTime time.Time = time.Now() var chat int64 var m ChatWarsMessage @@ -84,8 +83,8 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { fmt.Printf("Exporting historic messages for chat %d from user %d ...\n", chat, *senderUserID64) - for lastMsgID64 >= 0 { - msgs, err := c.GetChatHistory(chat, lastMsgID64, 0, 10, false) + for lastParsedID64 >= 0 { + msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 10, false) if err != nil { if err.Error() == "timeout" { logOnError(err, "Waiting...") @@ -127,23 +126,22 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) { if m.ID64 != 0 && (*senderUserID64 == 0 || m.SenderUserID64 == *senderUserID64) { MQCWMsgQueue <- m - - if m.ID64 < lastMsgID64 { - lastMsgID64 = m.ID64 - lastMsgTime = time.Unix(int64(m.Date), 0) - } msgCount = msgCount + 1 } default: log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum()) } + if m.ID64 < lastParsedID64 { + lastParsedID64 = msg.ID + lastParsedTime = time.Unix(int64(m.Date), 0) + } if msgParsed%1000 == 0 { fmt.Printf("Waiting : %d messages retrieved from %s ...\n", msgParsed, lastParsedTime.Format(time.RFC3339)) } } } else { - lastMsgID64 = -1 + lastParsedID64 = -1 } } log.Printf("Exported %d messages.\n", msgCount)