Skip to content

Commit

Permalink
fix: 优化合并转发预览显示 (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
2mf8 authored Oct 6, 2024
1 parent e011a24 commit 061e8dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func (c *QQClient) preProcessGroupMessage(groupUin uint32, elements []message2.I
case *message2.ForwardMessage:
if elem.ResID != "" && len(elem.Nodes) == 0 {
forward, _ := c.FetchForwardMsg(elem.ResID)
elem.IsGroup = true
elem.Nodes = forward.Nodes
}
if elem.ResID == "" && len(elem.Nodes) != 0 {
Expand Down Expand Up @@ -291,6 +292,7 @@ func (c *QQClient) preProcessPrivateMessage(targetUin uint32, elements []message
case *message2.ForwardMessage:
if elem.ResID != "" && len(elem.Nodes) == 0 {
forward, _ := c.FetchForwardMsg(elem.ResID)
elem.SelfId = c.Uin
elem.Nodes = forward.Nodes
}
if elem.ResID == "" && len(elem.Nodes) != 0 {
Expand Down
30 changes: 29 additions & 1 deletion message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ func (e *ForwardMessage) BuildElement() []*message.Elem {
news = []News{{Text: "转发消息"}}
}

var metaSource string = ""
if len(e.Nodes) > 0 {
isSenderNameExist := make(map[string]bool, 0)
isContainSelf := false
isCount := 0
for _, v := range e.Nodes {
if v.SenderId == e.SelfId && e.SelfId > 0 {
isContainSelf = true
}
if _, ok := isSenderNameExist[v.SenderName]; !ok {
isCount++
isSenderNameExist[v.SenderName] = true
if metaSource == "" {
metaSource = v.SenderName
} else {
metaSource += fmt.Sprintf("和%s", v.SenderName)
}
}
}
if !isContainSelf || (isCount > 2 && isCount < 1) {
metaSource = "群聊的聊天记录"
} else {
metaSource += "的聊天记录"
}
} else {
metaSource = "聊天记录"
}

content := MultiMsgLightApp{
App: "com.tencent.multimsg",
Config: Config{
Expand All @@ -179,7 +207,7 @@ func (e *ForwardMessage) BuildElement() []*message.Elem {
Detail: Detail{
News: news,
Resid: e.ResID,
Source: "聊天记录",
Source: metaSource,
Summary: fmt.Sprintf("查看%d条转发消息", len(e.Nodes)),
UniSeq: fileId,
},
Expand Down
6 changes: 4 additions & 2 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ type (
}

ForwardMessage struct {
ResID string
Nodes []*ForwardNode
IsGroup bool
SelfId uint32
ResID string
Nodes []*ForwardNode
}

AtType int
Expand Down

0 comments on commit 061e8dc

Please sign in to comment.