This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
online_push_message.go
98 lines (89 loc) · 2.77 KB
/
online_push_message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package client
import (
"context"
"encoding/hex"
"strconv"
"google.golang.org/protobuf/proto"
"github.com/elap5e/go-mobileqq-api/encoding/mark"
"github.com/elap5e/go-mobileqq-api/log"
"github.com/elap5e/go-mobileqq-api/mobileqq/client/db"
"github.com/elap5e/go-mobileqq-api/mobileqq/codec"
"github.com/elap5e/go-mobileqq-api/pb"
"github.com/elap5e/go-mobileqq-api/util"
)
type OnlinePushMessageResponse struct {
Uin int64 `jce:",0" json:"uin,omitempty"`
Items []MessageDelete `jce:",1" json:"items,omitempty"`
ServerIP Uint32IPType `jce:",2" json:"server_ip,omitempty"`
}
func (c *Client) handleOnlinePushMessage(
ctx context.Context,
s2c *codec.ServerToClientMessage,
) (*codec.ClientToServerMessage, error) {
push := pb.OnlinePush_Message{}
if err := proto.Unmarshal(s2c.Buffer, &push); err != nil {
log.Debug().Msg(">>> [dump]\n" + hex.Dump(s2c.Buffer))
return nil, err
}
util.DumpServerToClientMessage(s2c, &push)
uin, _ := strconv.ParseUint(s2c.Username, 10, 64)
msg := push.GetMessage()
mr := &db.MessageRecord{
Time: msg.GetMessageHead().GetMessageTime(),
Seq: msg.GetMessageHead().GetMessageSeq(),
Uid: int64(msg.GetMessageBody().GetRichText().GetAttribute().GetRandom()) | 1<<56,
PeerID: msg.GetMessageHead().GetC2CTempMessageHead().GetGroupCode(),
UserID: msg.GetMessageHead().GetToUin(),
FromID: msg.GetMessageHead().GetFromUin(),
Text: "",
Type: msg.GetMessageHead().GetMessageType(),
}
if msg.GetMessageHead().GetC2CCmd() == 0 {
mr.PeerID = msg.GetMessageHead().GetGroupInfo().GetGroupCode()
mr.UserID = 0
if mr.Type == 82 {
c.setMessageSeq(mr.PeerID, mr.UserID, int64(uin), mr.Seq)
}
}
text, _ := mark.NewEncoder(mr.PeerID, mr.UserID, mr.FromID).
Encode(msg.GetMessageBody().GetRichText().GetElements())
mr.Text = string(text)
if c.db != nil {
err := c.dbInsertMessageRecord(uin, mr)
if err != nil {
log.Error().Err(err).Msg(">>> [db ] dbInsertMessageRecord")
}
} else {
c.PrintMessageRecord(mr)
}
if uin != uint64(mr.FromID) {
elems, err := mark.NewDecoder(mr.PeerID, mr.UserID, mr.FromID).
Decode([]byte(mr.Text))
if err != nil {
return nil, err
}
msg := pb.MessageCommon_Message{
MessageBody: &pb.IMMessageBody_MessageBody{
RichText: &pb.IMMessageBody_RichText{
Elements: elems,
},
},
}
if _, err := c.MessageSendMessage(
ctx, s2c.Username, NewMessageSendMessageRequest(
c.GetRoutingHead(mr.PeerID, mr.UserID),
msg.GetContentHead(),
msg.GetMessageBody(),
0,
c.syncCookie[int64(uin)],
),
); err != nil {
return nil, err
}
}
return NewOnlinePushMessageResponse(ctx, s2c.Username, []MessageDelete{{
FromUin: mr.FromID,
MessageTime: mr.Time,
MessageSeq: mr.Seq,
}}, Uint32IPType(push.GetServerIp()), int32(s2c.Seq))
}