From 3ed9d735e26e29a35b15dd92f2d2951c1d7d6f51 Mon Sep 17 00:00:00 2001 From: Lennart Kuijs Date: Tue, 28 Jan 2025 15:30:52 +0100 Subject: [PATCH] add support for restricted visibility --- channel_test.go | 18 ++++++++++++++++++ message.go | 7 ++++--- utils_test.go | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/channel_test.go b/channel_test.go index 3116311..bb60653 100644 --- a/channel_test.go +++ b/channel_test.go @@ -396,6 +396,24 @@ func TestChannel_SendSystemMessage(t *testing.T) { assert.Equal(t, MessageTypeSystem, msg.Type, "message type is system") } +func TestChannel_SendRestrictedVisibilityMessage(t *testing.T) { + c := initClient(t) + ch := initChannel(t, c) + ctx := context.Background() + adminUser := randomUserWithRole(t, c, "admin") + user := randomUser(t, c) + msg := &Message{ + Text: "test message", + RestrictedVisibility: []string{ + user.ID, + }, + } + + resp, err := ch.SendMessage(ctx, msg, adminUser.ID) + require.NoError(t, err, "send message") + assert.Equal(t, resp.Message.RestrictedVisibility, msg.RestrictedVisibility) +} + func TestChannel_Truncate(t *testing.T) { c := initClient(t) ch := initChannel(t, c) diff --git a/message.go b/message.go index 87a8bca..fd68804 100644 --- a/message.go +++ b/message.go @@ -42,9 +42,10 @@ type Message struct { ShowInChannel bool `json:"show_in_channel,omitempty"` // show reply message also in channel ThreadParticipants []*User `json:"thread_participants,omitempty"` - ReplyCount int `json:"reply_count,omitempty"` - QuotedMessageID string `json:"quoted_message_id,omitempty"` - MentionedUsers []*User `json:"mentioned_users"` + ReplyCount int `json:"reply_count,omitempty"` + QuotedMessageID string `json:"quoted_message_id,omitempty"` + MentionedUsers []*User `json:"mentioned_users"` + RestrictedVisibility []string `json:"restricted_visibility,omitempty"` Command string `json:"command,omitempty"` diff --git a/utils_test.go b/utils_test.go index 7d20c9f..dac78af 100644 --- a/utils_test.go +++ b/utils_test.go @@ -70,6 +70,27 @@ func randomUser(t *testing.T, c *Client) *User { return resp.User } +func randomUserWithRole(t *testing.T, c *Client, role string) *User { + t.Helper() + + ctx := context.Background() + resp, err := c.UpsertUser(ctx, &User{ + ID: randomString(10), + Role: role, + }) + require.NoError(t, err) + + t.Cleanup(func() { + _, _ = c.DeleteUsers(ctx, []string{resp.User.ID}, DeleteUserOptions{ + User: HardDelete, + Messages: HardDelete, + Conversations: HardDelete, + }) + }) + + return resp.User +} + func randomUsers(t *testing.T, c *Client, n int) []*User { t.Helper()