Skip to content

Commit

Permalink
fix: payload for sendmessage to prevent upsert user
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Apr 5, 2024
1 parent 8580735 commit 9b1c6c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func TestClient_CheckPush(t *testing.T) {
ch := initChannel(t, c)
ctx := context.Background()
user := randomUser(t, c)
msgResp, _ := ch.SendMessage(ctx, &Message{Text: "text"}, user.ID)
msgResp, err := ch.SendMessage(ctx, &Message{Text: "text"}, user.ID)
require.NoError(t, err)
skipDevices := true

req := &CheckPushRequest{MessageID: msgResp.Message.ID, SkipDevices: &skipDevices, UserID: user.ID}
Expand Down
6 changes: 4 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Message struct {
Silent bool `json:"silent,omitempty"`

User *User `json:"user"`
UserID string `json:"user_id"`
Attachments []*Attachment `json:"attachments"`
LatestReactions []*Reaction `json:"latest_reactions"` // last reactions
OwnReactions []*Reaction `json:"own_reactions"`
Expand Down Expand Up @@ -94,7 +95,7 @@ func (m *Message) toRequest() messageRequest {
Text: m.Text,
Type: m.Type,
Attachments: m.Attachments,
User: messageRequestUser{ID: m.User.ID},
UserID: m.UserID,
ExtraData: m.ExtraData,
Pinned: m.Pinned,
ParentID: m.ParentID,
Expand Down Expand Up @@ -127,7 +128,7 @@ type messageRequestMessage struct {
Text string `json:"text"`
Type MessageType `json:"type" validate:"omitempty,oneof=system"`
Attachments []*Attachment `json:"attachments"`
User messageRequestUser `json:"user"`
UserID string `json:"user_id"`
MentionedUsers []string `json:"mentioned_users"`
ParentID string `json:"parent_id"`
ShowInChannel bool `json:"show_in_channel"`
Expand Down Expand Up @@ -257,6 +258,7 @@ func (ch *Channel) SendMessage(ctx context.Context, message *Message, userID str
}

message.User = &User{ID: userID}
message.UserID = userID
p := path.Join("channels", url.PathEscape(ch.Type), url.PathEscape(ch.ID), "message")

req := message.toRequest()
Expand Down

0 comments on commit 9b1c6c7

Please sign in to comment.