Skip to content

Commit a95472b

Browse files
committed
SetAttachmentsを使わない場合にAttachmentsを消去するように変更
1 parent 9a0432c commit a95472b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

message.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type (
1313
Message Message `json:"message"`
1414
Mode string `json:"mode"`
1515
Raw interface{} `json:"raw"`
16+
17+
shouldKeepAttachments bool
1618
}
1719
pack struct {
1820
User User `json:"user"`
@@ -55,6 +57,7 @@ func NewLXMessage(msg M) (*LXMessage, error) {
5557
Message: pack.Message,
5658
Mode: "",
5759
Raw: pack.Raw,
60+
shouldKeepAttachments: false,
5861
}, nil
5962
}
6063

@@ -63,6 +66,12 @@ func (this *LXMessage) SetText(text string) *LXMessage {
6366
return this
6467
}
6568

69+
func (this *LXMessage) SetAttachments(attachments []Attachment) *LXMessage {
70+
this.Message.Attachments = attachments
71+
this.shouldKeepAttachments = true
72+
return this
73+
}
74+
6675
func (this *LXMessage) Send() *LXMessage {
6776
this.Mode = "send"
6877
return this
@@ -79,7 +88,11 @@ func (this *LXMessage) ToMap() (M, error) {
7988
return nil, err
8089
}
8190

82-
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
91+
if this.shouldKeepAttachments {
92+
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
93+
} else {
94+
r["message"].(M)["attachments"] = []map[string]interface{}{}
95+
}
8396
return r, err
8497
}
8598

0 commit comments

Comments
 (0)