@@ -77,17 +77,11 @@ type (
77
77
}
78
78
79
79
Sender struct {
80
- Uin uint32
81
- UID string
82
- Nickname string
83
- CardName string
84
- AnonymousInfo * AnonymousInfo
85
- IsFriend bool
86
- }
87
-
88
- AnonymousInfo struct {
89
- AnonymousID string
90
- AnonymousNick string
80
+ Uin uint32
81
+ UID string
82
+ Nickname string
83
+ CardName string
84
+ IsFriend bool
91
85
}
92
86
93
87
IMessageElement interface {
@@ -97,10 +91,6 @@ type (
97
91
ElementType int
98
92
)
99
93
100
- func (s * Sender ) IsAnonymous () bool {
101
- return s .Uin == 80000000
102
- }
103
-
104
94
func ParsePrivateMessage (msg * message.PushMsgBody ) * PrivateMessage {
105
95
prvMsg := & PrivateMessage {
106
96
ID : msg .ContentHead .Sequence .Unwrap (),
@@ -161,26 +151,24 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
161
151
continue
162
152
}
163
153
if elem .SrcMsg != nil && len (elem .SrcMsg .OrigSeqs ) != 0 {
164
- r := & ReplyElement {
154
+ res = append ( res , & ReplyElement {
165
155
ReplySeq : elem .SrcMsg .OrigSeqs [0 ],
166
156
Time : uint32 (elem .SrcMsg .Time .Unwrap ()),
167
157
SenderUin : uint32 (elem .SrcMsg .SenderUin ),
168
158
GroupUin : uint32 (elem .SrcMsg .ToUin .Unwrap ()),
169
159
Elements : ParseMessageElements (elem .SrcMsg .Elems ),
170
- }
171
- res = append (res , r )
160
+ })
172
161
}
173
162
174
163
if elem .Text != nil {
175
- switch {
176
- case len (elem .Text .Attr6Buf ) > 0 :
164
+ if len (elem .Text .Attr6Buf ) > 0 {
177
165
att6 := binary .NewReader (elem .Text .Attr6Buf )
178
166
att6 .SkipBytes (7 )
179
167
target := att6 .ReadU32 ()
180
168
at := NewAt (target , elem .Text .Str .Unwrap ())
181
169
at .SubType = AtTypeGroupMember
182
170
res = append (res , at )
183
- default :
171
+ } else {
184
172
res = append (res , NewText (func () string {
185
173
if strings .Contains (elem .Text .Str .Unwrap (), "\r " ) && ! strings .Contains (elem .Text .Str .Unwrap (), "\r \n " ) {
186
174
return strings .ReplaceAll (elem .Text .Str .Unwrap (), "\r " , "\r \n " )
@@ -191,24 +179,25 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
191
179
}
192
180
193
181
if elem .Face != nil {
194
- switch {
195
- case len (elem .Face .Old ) > 0 :
182
+ if len (elem .Face .Old ) > 0 {
196
183
faceID := elem .Face .Index
197
184
if faceID .IsSome () {
198
185
res = append (res , & FaceElement {FaceID : uint32 (faceID .Unwrap ())})
199
186
}
200
- case elem .CommonElem != nil && elem .CommonElem .ServiceType == 37 && elem .CommonElem .PbElem != nil :
201
- qFace := message.QFaceExtra {}
202
- if err := proto .Unmarshal (elem .CommonElem .PbElem , & qFace ); err == nil {
203
- if qFace .Qsid .IsSome () {
204
- res = append (res , & FaceElement {FaceID : uint32 (qFace .Qsid .Unwrap ()), isLargeFace : true })
187
+ } else if elem .CommonElem != nil && elem .CommonElem .PbElem != nil {
188
+ if elem .CommonElem .ServiceType == 37 {
189
+ qFace := message.QFaceExtra {}
190
+ if err := proto .Unmarshal (elem .CommonElem .PbElem , & qFace ); err == nil {
191
+ if qFace .Qsid .IsSome () {
192
+ res = append (res , & FaceElement {FaceID : uint32 (qFace .Qsid .Unwrap ()), isLargeFace : true })
193
+ }
194
+ }
195
+ } else if elem .CommonElem .ServiceType == 33 {
196
+ qFace := message.QSmallFaceExtra {}
197
+ err := proto .Unmarshal (elem .CommonElem .PbElem , & qFace )
198
+ if err == nil {
199
+ res = append (res , & FaceElement {FaceID : qFace .FaceId , isLargeFace : false })
205
200
}
206
- }
207
- case elem .CommonElem != nil && elem .CommonElem .ServiceType == 33 && elem .CommonElem .PbElem != nil :
208
- qFace := message.QSmallFaceExtra {}
209
- err := proto .Unmarshal (elem .CommonElem .PbElem , & qFace )
210
- if err == nil {
211
- res = append (res , & FaceElement {FaceID : qFace .FaceId , isLargeFace : false })
212
201
}
213
202
}
214
203
}
@@ -328,7 +317,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
328
317
})
329
318
case 11 , 21 : // video
330
319
var thumb = new (VideoThumb )
331
- if ! ( len (extra .MsgInfoBody ) < 2 ) {
320
+ if len (extra .MsgInfoBody ) > 1 {
332
321
info := extra .MsgInfoBody [1 ].Index
333
322
thumb .Size = info .Info .FileSize
334
323
thumb .Width = info .Info .Width
@@ -408,7 +397,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
408
397
} else {
409
398
res = append (res , & XMLElement {
410
399
ServiceID : 35 ,
411
- Content : utils .B2S (binary . ZlibUncompress ( elem . RichMsg . Template1 [ 1 :]) ),
400
+ Content : utils .B2S (xmlData ),
412
401
})
413
402
}
414
403
}
@@ -450,8 +439,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement
450
439
if body != nil {
451
440
if body .RichText != nil && body .RichText .Ptt != nil {
452
441
ptt := body .RichText .Ptt
453
- switch {
454
- case isGroup && ptt .FileId != 0 :
442
+ if isGroup && ptt .FileId != 0 {
455
443
res = append (res , & VoiceElement {
456
444
Name : ptt .FileName ,
457
445
UUID : ptt .FileUuid ,
@@ -460,7 +448,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement
460
448
FileUuid : ptt .GroupFileKey ,
461
449
},
462
450
})
463
- case ! isGroup :
451
+ } else if ! isGroup {
464
452
res = append (res , & VoiceElement {
465
453
Name : ptt .FileName ,
466
454
UUID : ptt .FileUuid ,
@@ -654,11 +642,9 @@ func PackElementsToBody(msgElems []IMessageElement) (msgBody *message.MessageBod
654
642
RichText : & message.RichText {Elems : PackElements (msgElems )},
655
643
}
656
644
for _ , elem := range msgElems {
657
- bd , ok := elem .(MsgContentBuilder )
658
- if ! ok {
659
- continue
645
+ if bd , ok := elem .(MsgContentBuilder ); ok {
646
+ msgBody .MsgContent = bd .BuildContent ()
660
647
}
661
- msgBody .MsgContent = bd .BuildContent ()
662
648
}
663
649
return
664
650
}
@@ -669,11 +655,9 @@ func PackElements(msgElems []IMessageElement) []*message.Elem {
669
655
}
670
656
elems := make ([]* message.Elem , 0 , len (msgElems ))
671
657
for _ , elem := range msgElems {
672
- bd , ok := elem .(ElementBuilder )
673
- if ! ok {
674
- continue
658
+ if bd , ok := elem .(ElementBuilder ); ok {
659
+ elems = append (elems , bd .BuildElement ()... )
675
660
}
676
- elems = append (elems , bd .BuildElement ()... )
677
661
}
678
662
return elems
679
663
}
0 commit comments