1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

fix session sync timeout.

This commit is contained in:
Mrs4s 2021-03-08 09:11:15 +08:00
parent 154ce35198
commit 8c89d62657
2 changed files with 10 additions and 8 deletions

View File

@ -153,7 +153,9 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, info *in
*/
}
}
if delItems != nil {
_, _ = c.sendAndWait(c.buildDeleteMessageRequestPacket(delItems))
}
if rsp.GetSyncFlag() != msg.SyncFlag_STOP {
c.Debug("continue sync with flag: %v", rsp.SyncFlag.String())
seq, pkt := c.buildGetMessageRequestPacket(rsp.GetSyncFlag(), time.Now().Unix())

View File

@ -73,19 +73,13 @@ func (c *QQClient) RefreshStatus() error {
}
func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) {
_, pkt := c.buildSyncMsgRequestPacket()
if err := c.send(pkt); err != nil {
return nil, err
}
ret := &SessionSyncResponse{}
notifyChan := make(chan bool)
var groupNum int32 = -1
p := 0
stop := c.waitPacket("RegPrxySvc.PbSyncMsg", func(i interface{}, err error) {
if err != nil {
return
}
p++
e := i.(*sessionSyncEvent)
if len(e.GroupSessions) > 0 {
ret.GroupSessions = append(ret.GroupSessions, e.GroupSessions...)
@ -93,14 +87,20 @@ func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) {
if e.GroupNum != -1 {
groupNum = e.GroupNum
}
c.Debug("sync session %v/%v", len(ret.GroupSessions), groupNum)
if groupNum != -1 && len(ret.GroupSessions) >= int(groupNum) {
notifyChan <- true
}
})
_, pkt := c.buildSyncMsgRequestPacket()
if err := c.send(pkt); err != nil {
stop()
return nil, err
}
select {
case <-notifyChan:
stop()
case <-time.After(time.Second * 20):
case <-time.After(time.Second * 3):
stop()
}
return ret, nil