更新消息

This commit is contained in:
zhx 2026-06-29 15:46:08 +08:00
parent a921aadcf8
commit 39ac8ae4ab
2 changed files with 47 additions and 2 deletions

View File

@ -316,7 +316,9 @@ type confirmIMPayload struct {
type confirmIMAction struct {
Action string `json:"action"`
Label string `json:"label"`
Text string `json:"text"`
Style string `json:"style,omitempty"`
}
func confirmIMPayloadJSON(confirmID string, event messagedomain.RoleInvitationConfirmEvent, messageText string, createdAtMS int64) (string, error) {
@ -330,8 +332,9 @@ func confirmIMPayloadJSON(confirmID string, event messagedomain.RoleInvitationCo
ReceiverUserID: strconv.FormatInt(event.TargetUserID, 10),
Msg: messageText,
Actions: []confirmIMAction{
{Action: messagedomain.ActionConfirmActionReject, Text: "Reject"},
{Action: messagedomain.ActionConfirmActionAccept, Text: "Accept"},
// label 是当前 App 渲染按钮的字段text 保留给早期自定义消息解析,避免协议兼容回退。
{Action: messagedomain.ActionConfirmActionReject, Label: "Reject", Text: "Reject", Style: "secondary"},
{Action: messagedomain.ActionConfirmActionAccept, Label: "Accept", Text: "Accept", Style: "primary"},
},
CreatedAtMS: createdAtMS,
}

View File

@ -0,0 +1,42 @@
package message
import (
"encoding/json"
"testing"
messagedomain "hyapp/services/activity-service/internal/domain/message"
)
func TestConfirmIMPayloadActionsExposeAppButtonLabels(t *testing.T) {
payloadJSON, err := confirmIMPayloadJSON("cfm_1", messagedomain.RoleInvitationConfirmEvent{
InvitationID: 901,
InvitationType: "host",
InviterUserID: 1001,
TargetUserID: 2002,
}, "Alice has invited you to join ABC guild", 1760000000000)
if err != nil {
t.Fatalf("confirmIMPayloadJSON failed: %v", err)
}
var payload struct {
Type string `json:"type"`
Actions []struct {
Action string `json:"action"`
Label string `json:"label"`
Text string `json:"text"`
Style string `json:"style"`
} `json:"actions"`
}
if err := json.Unmarshal([]byte(payloadJSON), &payload); err != nil {
t.Fatalf("payload must be valid JSON: %v", err)
}
if payload.Type != "im_confirm" || len(payload.Actions) != 2 {
t.Fatalf("confirm payload shape mismatch: %+v", payload)
}
// Flutter 现在线上按 label 渲染按钮text 只作为旧解析兼容字段;两个字段必须一起存在。
if payload.Actions[0].Action != "reject" || payload.Actions[0].Label != "Reject" || payload.Actions[0].Text != "Reject" || payload.Actions[0].Style != "secondary" {
t.Fatalf("reject action mismatch: %+v", payload.Actions[0])
}
if payload.Actions[1].Action != "accept" || payload.Actions[1].Label != "Accept" || payload.Actions[1].Text != "Accept" || payload.Actions[1].Style != "primary" {
t.Fatalf("accept action mismatch: %+v", payload.Actions[1])
}
}