diff --git a/client/entities.go b/client/entities.go index a32328ee..29232b06 100644 --- a/client/entities.go +++ b/client/entities.go @@ -75,8 +75,9 @@ type ( MaxMemberCount uint16 Members []*GroupMemberInfo - client *QQClient - lock sync.RWMutex + client *QQClient + lastMsgSeq int64 + lock sync.RWMutex } GroupMemberInfo struct { diff --git a/client/group_info.go b/client/group_info.go index 9c6e01c4..7a6b929d 100644 --- a/client/group_info.go +++ b/client/group_info.go @@ -44,6 +44,7 @@ func (c *QQClient) buildGroupInfoRequestPacket(groupCode int64) (uint16, []byte) GroupMemo: EmptyBytes, GroupFingerMemo: EmptyBytes, GroupLastMsgTime: proto.Uint32(0), + GroupCurMsgSeq: proto.Uint32(0), GroupQuestion: EmptyBytes, GroupAnswer: EmptyBytes, GroupGrade: proto.Uint32(0), @@ -146,6 +147,7 @@ func decodeGroupInfoResponse(c *QQClient, _ uint16, payload []byte) (interface{} MemberCount: uint16(*info.GroupInfo.GroupMemberNum), MaxMemberCount: uint16(*info.GroupInfo.GroupMemberMaxNum), Members: []*GroupMemberInfo{}, + lastMsgSeq: int64(info.GroupInfo.GetGroupCurMsgSeq()), client: c, }, nil } diff --git a/client/group_msg.go b/client/group_msg.go index f7e6cb9d..7b580d87 100644 --- a/client/group_msg.go +++ b/client/group_msg.go @@ -69,6 +69,7 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se eid := utils.RandomString(6) mr := int32(rand.Uint32()) ch := make(chan int32) + defer close(ch) c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) { if e.Rand == mr { ch <- e.Seq @@ -107,7 +108,16 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se } select { case mid = <-ch: - case <-time.After(time.Second * 5): + case <-time.After(time.Second * 3): + if g, err := c.GetGroupInfo(groupCode); err == nil { + if history, err := c.GetGroupMessages(groupCode, g.lastMsgSeq-10, g.lastMsgSeq+1); err == nil { + for _, m := range history { + if m.InternalId == mr { + return m + } + } + } + } return ret } ret.Id = mid