From 39ac8ae4abd12ce837ea5d88ee0d09ced0ef6ad1 Mon Sep 17 00:00:00 2001 From: zhx Date: Mon, 29 Jun 2026 15:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/message/action_confirm.go | 7 +++- .../service/message/action_confirm_test.go | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 services/activity-service/internal/service/message/action_confirm_test.go diff --git a/services/activity-service/internal/service/message/action_confirm.go b/services/activity-service/internal/service/message/action_confirm.go index d5a4e1e4..6bd2229e 100644 --- a/services/activity-service/internal/service/message/action_confirm.go +++ b/services/activity-service/internal/service/message/action_confirm.go @@ -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, } diff --git a/services/activity-service/internal/service/message/action_confirm_test.go b/services/activity-service/internal/service/message/action_confirm_test.go new file mode 100644 index 00000000..d0485fe8 --- /dev/null +++ b/services/activity-service/internal/service/message/action_confirm_test.go @@ -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]) + } +}