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

add: GetGroupListAsync().

This commit is contained in:
Mrs4s 2020-08-16 18:42:13 +08:00
parent be0e431f8f
commit cfe2585d84
3 changed files with 54 additions and 14 deletions

View File

@ -203,7 +203,7 @@ func (c *QQClient) buildFriendGroupListRequestPacket(friendStartIndex, friendLis
})
req := &jce.FriendListRequest{
Reqtype: 3,
IfReflush: func() byte { // fuck golang
IfReflush: func() byte {
if friendStartIndex <= 0 {
return 0
}
@ -996,6 +996,7 @@ func (c *QQClient) buildGroupFileDownloadReqPacket(groupCode int64, fileId strin
return seq, packet
}
// PttCenterSvr.ShortVideoDownReq
func (c *QQClient) buildPttShortVideoDownReqPacket(uuid, md5 []byte) (uint16, []byte) {
seq := c.nextSeq()
body := &pttcenter.ShortVideoReqBody{

View File

@ -542,10 +542,20 @@ func (c *QQClient) QueryFriendImage(target int64, hash []byte, size int32) (*mes
}, nil
}
func (c *QQClient) ReloadGroupList() error {
func (c *QQClient) ReloadGroupList(async ...bool) error {
f := false
if len(async) > 0 {
f = async[0]
}
c.groupListLock.Lock()
defer c.groupListLock.Unlock()
list, err := c.GetGroupList()
list, err := func() ([]*GroupInfo, error) {
if f {
return c.GetGroupListAsync()
} else {
return c.GetGroupList()
}
}()
if err != nil {
return err
}
@ -569,6 +579,25 @@ func (c *QQClient) GetGroupList() ([]*GroupInfo, error) {
return r, nil
}
func (c *QQClient) GetGroupListAsync() ([]*GroupInfo, error) {
rsp, err := c.sendAndWait(c.buildGroupListRequestPacket())
if err != nil {
return nil, err
}
r := rsp.([]*GroupInfo)
for _, group := range r {
g := group
go func() {
m, err := c.GetGroupMembers(g)
if err != nil {
return
}
g.Members = m
}()
}
return r, nil
}
func (c *QQClient) GetGroupMembers(group *GroupInfo) ([]*GroupMemberInfo, error) {
var nextUin int64
var list []*GroupMemberInfo
@ -795,15 +824,24 @@ func (c *QQClient) sendAndWait(seq uint16, pkt []byte) (interface{}, error) {
Error: err,
}
})
retry := 0
for true {
select {
case rsp := <-ch:
return rsp.Response, rsp.Error
case <-time.After(time.Second * 15):
retry++
if retry < 2 {
_ = c.send(pkt)
continue
}
c.handlers.Delete(seq)
println("Packet Timed out")
return nil, errors.New("time out")
}
}
return nil, nil
}
func (c *QQClient) netLoop() {
reader := binary.NewNetworkReader(c.Conn)
@ -840,7 +878,7 @@ func (c *QQClient) netLoop() {
}
}
retry = 0
//fmt.Println(pkt.CommandName)
//fmt.Println(pkt.CommandName, pkt.SequenceId)
go func() {
defer func() {
if pan := recover(); pan != nil {

View File

@ -254,10 +254,11 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
}
}
}
_, _ = c.sendAndWait(c.buildDeleteMessageRequestPacket(delItems))
_, delPkt := c.buildDeleteMessageRequestPacket(delItems)
_ = c.send(delPkt)
if rsp.SyncFlag != msg.SyncFlag_STOP {
seq, pkt := c.buildGetMessageRequestPacket(rsp.SyncFlag, time.Now().Unix())
_, _ = c.sendAndWait(seq, pkt)
_, nextPkt := c.buildGetMessageRequestPacket(rsp.SyncFlag, time.Now().Unix())
_ = c.send(nextPkt)
}
return nil, err
}