更新消息
This commit is contained in:
parent
a921aadcf8
commit
39ac8ae4ab
@ -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,
|
||||
}
|
||||
|
||||
@ -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])
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user