Skip to content

Commit

Permalink
feat: Add Properties.Canvas to Channel (#1228)
Browse files Browse the repository at this point in the history
* Add Properties.Canvas to Channel

* Trigger GitHub Actions

---------

Co-authored-by: Lorenzo Aiello <lorenzo.aiello@slack-corp.com>
  • Loading branch information
ku and lorenzoaiello authored Aug 15, 2024
1 parent 50e7414 commit 5345c06
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
9 changes: 5 additions & 4 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type channelResponseFull struct {
// Channel contains information about the channel
type Channel struct {
GroupConversation
IsChannel bool `json:"is_channel"`
IsGeneral bool `json:"is_general"`
IsMember bool `json:"is_member"`
Locale string `json:"locale"`
IsChannel bool `json:"is_channel"`
IsGeneral bool `json:"is_general"`
IsMember bool `json:"is_member"`
Locale string `json:"locale"`
Properties *Properties `json:"properties"`
}

func (api *Client) channelRequest(ctx context.Context, path string, values url.Values) (*channelResponseFull, error) {
Expand Down
11 changes: 11 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ type Purpose struct {
LastSet JSONTime `json:"last_set"`
}

// Properties contains the Canvas associated to the channel.
type Properties struct {
Canvas Canvas `json:"canvas"`
}

type Canvas struct {
FileId string `json:"file_id"`
IsEmpty bool `json:"is_empty"`
QuipThreadId string `json:"quip_thread_id"`
}

type GetUsersInConversationParameters struct {
ChannelID string
Cursor string
Expand Down
79 changes: 79 additions & 0 deletions conversation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,85 @@ func TestCreateSimpleGroup(t *testing.T) {
assertSimpleGroup(t, group)
}

// Channel with Canvas
var channelWithCanvas = `{
"id": "C024BE91L",
"name": "fun",
"is_channel": true,
"created": 1360782804,
"creator": "U024BE7LH",
"is_archived": false,
"is_general": false,
"members": [
"U024BE7LH"
],
"topic": {
"value": "Fun times",
"creator": "U024BE7LV",
"last_set": 1369677212
},
"purpose": {
"value": "This channel is for fun",
"creator": "U024BE7LH",
"last_set": 1360782804
},
"is_member": true,
"last_read": "1401383885.000061",
"unread_count": 0,
"unread_count_display": 0,
"properties": {
"canvas": {
"file_id": "F05RQ01LJU0",
"is_empty": true,
"quip_thread_id": "XFB9AAlvIyJ"
}
}
}`

func unmarshalChannelWithCanvas(j string) (*Channel, error) {
channel := &Channel{}
if err := json.Unmarshal([]byte(j), &channel); err != nil {
return nil, err
}
return channel, nil
}

func TestChannelWithCanvas(t *testing.T) {
channel, err := unmarshalChannelWithCanvas(channelWithCanvas)
assert.Nil(t, err)
assertChannelWithCanvas(t, channel)
}

func assertChannelWithCanvas(t *testing.T, channel *Channel) {
assertSimpleChannel(t, channel)
assert.Equal(t, "F05RQ01LJU0", channel.Properties.Canvas.FileId)
assert.Equal(t, true, channel.Properties.Canvas.IsEmpty)
assert.Equal(t, "XFB9AAlvIyJ", channel.Properties.Canvas.QuipThreadId)
}

func TestCreateChannelWithCanvas(t *testing.T) {
channel := &Channel{}
channel.ID = "C024BE91L"
channel.Name = "fun"
channel.IsChannel = true
channel.Created = JSONTime(1360782804)
channel.Creator = "U024BE7LH"
channel.IsArchived = false
channel.IsGeneral = false
channel.IsMember = true
channel.LastRead = "1401383885.000061"
channel.UnreadCount = 0
channel.UnreadCountDisplay = 0
channel.Properties = &Properties{
Canvas: Canvas{
FileId: "F05RQ01LJU0",
IsEmpty: true,
QuipThreadId: "XFB9AAlvIyJ",
},
}
assertChannelWithCanvas(t, channel)
}

// IM
var simpleIM = `{
"id": "D024BFF1M",
Expand Down

0 comments on commit 5345c06

Please sign in to comment.