Skip to content

Commit 8bc6dae

Browse files
committed
add deserialization for file unshared event
1 parent 413153e commit 8bc6dae

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

slackevents/inner_events.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ type FileSharedEvent struct {
182182
EventTimestamp string `json:"event_ts"`
183183
}
184184

185+
// FileUnsharedEvent represents the information associated with the File
186+
// unshared event.
187+
type FileUnsharedEvent struct {
188+
Type string `json:"type"`
189+
FileID string `json:"file_id"`
190+
File FileEventFile `json:"file"`
191+
}
192+
185193
// FileEventFile represents information on the specific file being shared in a
186194
// file-related Slack event.
187195
type FileEventFile struct {
@@ -555,6 +563,8 @@ const (
555563
FileDeleted = EventsAPIType("file_deleted")
556564
// FileShared is sent when a file is shared.
557565
FileShared = EventsAPIType("file_shared")
566+
// FileUnshared is sent when a file is unshared.
567+
FileUnshared = EventsAPIType("file_unshared")
558568
// GridMigrationFinished An enterprise grid migration has finished on this workspace.
559569
GridMigrationFinished = EventsAPIType("grid_migration_finished")
560570
// GridMigrationStarted An enterprise grid migration has started on this workspace.
@@ -608,6 +618,7 @@ var EventsAPIInnerEventMapping = map[EventsAPIType]interface{}{
608618
FileChange: FileChangeEvent{},
609619
FileDeleted: FileDeletedEvent{},
610620
FileShared: FileSharedEvent{},
621+
FileUnshared: FileUnsharedEvent{},
611622
GroupDeleted: GroupDeletedEvent{},
612623
GroupArchive: GroupArchiveEvent{},
613624
GroupUnarchive: GroupUnarchiveEvent{},

slackevents/inner_events_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ func TestFileSharedEvent(t *testing.T) {
126126
}
127127
}
128128

129+
func TestFileUnsharedEvent(t *testing.T) {
130+
rawE := []byte(`
131+
{
132+
"type": "file_unshared",
133+
"file_id": "F1234567890",
134+
"file": {
135+
"id": "F1234567890"
136+
}
137+
}
138+
`)
139+
140+
var e FileUnsharedEvent
141+
if err := json.Unmarshal(rawE, &e); err != nil {
142+
t.Fatal(err)
143+
}
144+
if e.Type != "file_unshared" {
145+
t.Errorf("type should be file_shared, was %s", e.Type)
146+
}
147+
if e.FileID != "F1234567890" {
148+
t.Errorf("file ID should be F1234567890, was %s", e.FileID)
149+
}
150+
if e.File.ID != "F1234567890" {
151+
t.Errorf("file.id should be F1234567890, was %s", e.File.ID)
152+
}
153+
}
154+
129155
func TestGridMigrationFinishedEvent(t *testing.T) {
130156
rawE := []byte(`
131157
{

0 commit comments

Comments
 (0)