Skip to content

Commit

Permalink
fix: 统一数据类型,增加私聊clientSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Sep 9, 2024
1 parent 3ee0ef4 commit 7ebbf04
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
38 changes: 20 additions & 18 deletions client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/RomiChan/protobuf/proto"
)

func (c *QQClient) SendRawMessage(route *message.RoutingHead, body *message.MessageBody, random uint32) (*action.SendMessageResponse, error) {
func (c *QQClient) SendRawMessage(route *message.RoutingHead, body *message.MessageBody, random uint32) (*action.SendMessageResponse, uint32, error) {
clientSeq := c.getSequence()
msg := &message.Message{
RoutingHead: route,
ContentHead: &message.ContentHead{
Expand All @@ -18,7 +19,7 @@ func (c *QQClient) SendRawMessage(route *message.RoutingHead, body *message.Mess
DivSeq: proto.Some(uint32(0)),
},
Body: body,
ClientSequence: proto.Some(c.getSequence()),
ClientSequence: proto.Some(clientSeq),
Random: proto.Some(random),
}
// grp_id not null
Expand All @@ -28,18 +29,18 @@ func (c *QQClient) SendRawMessage(route *message.RoutingHead, body *message.Mess

data, err := proto.Marshal(msg)
if err != nil {
return nil, err
return nil, 0, err
}
packet, err := c.sendUniPacketAndWait("MessageSvc.PbSendMsg", data)
if err != nil {
return nil, err
return nil, 0, err
}
resp := &action.SendMessageResponse{}
err = proto.Unmarshal(packet, resp)
if err != nil {
return nil, err
return nil, 0, err
}
return resp, err
return resp, clientSeq, err
}

// SendGroupMessage 发送群聊消息,默认会对消息进行预处理
Expand All @@ -52,15 +53,15 @@ func (c *QQClient) SendGroupMessage(groupUin uint32, elements []message2.IMessag
Grp: &message.Grp{GroupCode: proto.Some(groupUin)},
}
mr := crypto.RandU32()
ret, err := c.SendRawMessage(route, body, mr)
ret, _, err := c.SendRawMessage(route, body, mr)
if err != nil || ret.GroupSequence.IsNone() {
return nil, err
}
group := c.GetCachedGroupInfo(groupUin)
minfo := c.GetCachedMemberInfo(c.Uin, groupUin)
resp := &message2.GroupMessage{
Id: int32(ret.GroupSequence.Unwrap()),
InternalId: int32(mr),
Id: ret.GroupSequence.Unwrap(),
InternalId: mr,
GroupUin: groupUin,
GroupName: group.GroupName,
Sender: &message2.Sender{
Expand All @@ -71,7 +72,7 @@ func (c *QQClient) SendGroupMessage(groupUin uint32, elements []message2.IMessag
AnonymousInfo: nil,
IsFriend: true,
},
Time: uint64(ret.Timestamp1),
Time: ret.Timestamp1,
Elements: elements,
OriginalObject: nil,
}
Expand All @@ -90,16 +91,17 @@ func (c *QQClient) SendPrivateMessage(uin uint32, elements []message2.IMessageEl
},
}
mr := crypto.RandU32()
ret, err := c.SendRawMessage(route, body, mr)
ret, clientSeq, err := c.SendRawMessage(route, body, mr)
if err != nil || ret.PrivateSequence == 0 {
return nil, err
}
resp := &message2.PrivateMessage{
Id: int32(ret.PrivateSequence),
InternalId: int32(mr),
Self: int64(c.Uin),
Target: int64(uin),
Time: int32(ret.Timestamp1),
Id: ret.PrivateSequence,
InternalId: mr,
CleintSeq: clientSeq,
Self: c.Uin,
Target: uin,
Time: ret.Timestamp1,
Sender: &message2.Sender{
Uin: c.Uin,
Uid: c.GetUid(c.Uin),
Expand All @@ -121,13 +123,13 @@ func (c *QQClient) SendTempMessage(groupUin uint32, uin uint32, elements []messa
},
}
mr := crypto.RandU32()
ret, err := c.SendRawMessage(route, body, mr)
ret, _, err := c.SendRawMessage(route, body, mr)
if err != nil || ret.PrivateSequence == 0 {
return nil, err
}
group := c.GetCachedGroupInfo(groupUin)
resp := &message2.TempMessage{
Id: int32(ret.PrivateSequence),
Id: ret.PrivateSequence,
GroupUin: groupUin,
GroupName: group.GroupName,
Self: c.Uin,
Expand Down
2 changes: 1 addition & 1 deletion client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (c *QQClient) UploadPrivateFile(targetUin uint32, localFilePath string) err
}
body := message2.PackElementsToBody([]message2.IMessageElement{uploadedFileElement})
mr := crypto.RandU32()
ret, err := c.SendRawMessage(route, body, mr)
ret, _, err := c.SendRawMessage(route, body, mr)
if err != nil || ret.PrivateSequence == 0 {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions client/packets/pb/message/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/packets/pb/message/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ message ContentHead {
uint32 Type = 1;
optional uint32 SubType = 2;
optional uint32 DivSeq = 3;
optional uint64 MsgId = 4;
optional uint32 MsgId = 4;
optional uint32 Sequence = 5;
optional uint64 TimeStamp = 6;
optional uint32 TimeStamp = 6;
optional uint64 Field7 = 7;
optional uint32 Field8 = 8;
optional uint32 Field9 = 9;
Expand Down
33 changes: 17 additions & 16 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ const (

type (
PrivateMessage struct {
Id int32
InternalId int32
Self int64
Target int64
Time int32
Id uint32
InternalId uint32
CleintSeq uint32
Self uint32
Target uint32
Time uint32
Sender *Sender
Elements []IMessageElement
}

TempMessage struct {
Id int32
Id uint32
GroupUin uint32
GroupName string
Self uint32
Expand All @@ -58,12 +59,12 @@ type (
}

GroupMessage struct {
Id int32
InternalId int32
Id uint32
InternalId uint32
GroupUin uint32
GroupName string
Sender *Sender
Time uint64
Time uint32
Elements []IMessageElement
OriginalObject *message.PushMsgBody
}
Expand Down Expand Up @@ -99,16 +100,16 @@ func (s *Sender) IsAnonymous() bool {

func ParsePrivateMessage(msg *message.PushMsg) *PrivateMessage {
prvMsg := &PrivateMessage{
Id: int32(msg.Message.ContentHead.Sequence.Unwrap()),
InternalId: int32(msg.Message.ContentHead.MsgId.Unwrap()),
Self: int64(msg.Message.ResponseHead.ToUin),
Target: int64(msg.Message.ResponseHead.FromUin),
Id: (msg.Message.ContentHead.Sequence.Unwrap()),
InternalId: (msg.Message.ContentHead.MsgId.Unwrap()),
Self: (msg.Message.ResponseHead.ToUin),
Target: (msg.Message.ResponseHead.FromUin),
Sender: &Sender{
Uin: msg.Message.ResponseHead.FromUin,
Uid: msg.Message.ResponseHead.FromUid.Unwrap(),
IsFriend: true,
},
Time: int32(msg.Message.ContentHead.TimeStamp.Unwrap()),
Time: msg.Message.ContentHead.TimeStamp.Unwrap(),
Elements: parseMessageElements(msg.Message.Body.RichText.Elems),
}
if msg.Message != nil && msg.Message.Body != nil {
Expand All @@ -120,8 +121,8 @@ func ParsePrivateMessage(msg *message.PushMsg) *PrivateMessage {

func ParseGroupMessage(msg *message.PushMsg) *GroupMessage {
grpMsg := &GroupMessage{
Id: int32(msg.Message.ContentHead.Sequence.Unwrap()),
InternalId: int32(msg.Message.ContentHead.MsgId.Unwrap()),
Id: msg.Message.ContentHead.Sequence.Unwrap(),
InternalId: msg.Message.ContentHead.MsgId.Unwrap(),
GroupUin: msg.Message.ResponseHead.Grp.GroupUin,
GroupName: msg.Message.ResponseHead.Grp.GroupName,
Sender: &Sender{
Expand Down

0 comments on commit 7ebbf04

Please sign in to comment.