1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

fix issue of repeatedly trigger for LeaveGroupEvent.

This commit is contained in:
Mrs4s 2020-07-14 03:12:20 +08:00
parent c6b4c61122
commit cc2ce301a3
2 changed files with 9 additions and 3 deletions

View File

@ -262,6 +262,8 @@ func (c *QQClient) UploadGroupImage(groupUin int64, img []byte) (*message.GroupI
} }
func (c *QQClient) ReloadGroupList() error { func (c *QQClient) ReloadGroupList() error {
c.groupListLock.Lock()
defer c.groupListLock.Unlock()
list, err := c.GetGroupList() list, err := c.GetGroupList()
if err != nil { if err != nil {
return err return err
@ -271,8 +273,6 @@ func (c *QQClient) ReloadGroupList() error {
} }
func (c *QQClient) GetGroupList() ([]*GroupInfo, error) { func (c *QQClient) GetGroupList() ([]*GroupInfo, error) {
c.groupListLock.Lock()
defer c.groupListLock.Unlock()
rsp, err := c.sendAndWait(c.buildGroupListRequestPacket()) rsp, err := c.sendAndWait(c.buildGroupListRequestPacket())
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -12,7 +12,8 @@ import (
) )
var ( var (
groupJoinLock = new(sync.Mutex) groupJoinLock = new(sync.Mutex)
groupLeaveLock = new(sync.Mutex)
) )
func decodeLoginResponse(c *QQClient, seq uint16, payload []byte) (interface{}, error) { func decodeLoginResponse(c *QQClient, seq uint16, payload []byte) (interface{}, error) {
@ -395,12 +396,15 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
if err := proto.Unmarshal(probuf, &d4); err != nil { if err := proto.Unmarshal(probuf, &d4); err != nil {
return nil, err return nil, err
} }
groupLeaveLock.Lock()
if g := c.FindGroup(d4.Uin); g != nil { if g := c.FindGroup(d4.Uin); g != nil {
if err := c.ReloadGroupList(); err != nil { if err := c.ReloadGroupList(); err != nil {
groupLeaveLock.Unlock()
return nil, err return nil, err
} }
c.dispatchLeaveGroupEvent(&GroupLeaveEvent{Group: g}) c.dispatchLeaveGroupEvent(&GroupLeaveEvent{Group: g})
} }
groupLeaveLock.Unlock()
} }
} }
} }
@ -423,6 +427,8 @@ func decodeOnlinePushTransPacket(c *QQClient, seq uint16, payload []byte) (inter
operator := int64(uint32(data.ReadInt32())) operator := int64(uint32(data.ReadInt32()))
switch typ { switch typ {
case 0x03: case 0x03:
groupLeaveLock.Lock()
defer groupLeaveLock.Unlock()
if g := c.FindGroup(info.FromUin); g != nil { if g := c.FindGroup(info.FromUin); g != nil {
if err = c.ReloadGroupList(); err != nil { if err = c.ReloadGroupList(); err != nil {
return nil, err return nil, err