-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
144 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package processors | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/slack-go/slack" | ||
) | ||
|
||
// EventType is the type of event that was recorded. There are three types: | ||
// messages, thread messages, and files. | ||
type EventType int | ||
|
||
const ( | ||
EventMessages EventType = iota | ||
EventThreadMessages | ||
EventFiles | ||
) | ||
|
||
type Event struct { | ||
Type EventType `json:"type,omitempty"` | ||
TS int64 `json:"event_ts,omitempty"` | ||
ChannelID string `json:"channel_id,omitempty"` | ||
IsThreadMessage bool `json:"is_thread_message,omitempty"` | ||
Size int `json:"size,omitempty"` // number of messages or files | ||
Parent *slack.Message `json:"parent,omitempty"` | ||
Messages []slack.Message `json:"messages,omitempty"` | ||
Files []slack.File `json:"files,omitempty"` | ||
} | ||
|
||
func (e *Event) messageID() string { | ||
return e.ChannelID | ||
} | ||
|
||
func (e *Event) threadID() string { | ||
return threadID(e.ChannelID, e.Parent.ThreadTimestamp) | ||
} | ||
|
||
func threadID(channelID, threadTS string) string { | ||
return "t" + channelID + ":" + threadTS | ||
} | ||
|
||
func (e *Event) fileID() string { | ||
return fileID(e.ChannelID, e.Parent.Timestamp) | ||
} | ||
|
||
func fileID(channelID, parentTS string) string { | ||
return "f" + channelID + ":" + parentTS | ||
} | ||
|
||
func (e *Event) ID() string { | ||
switch e.Type { | ||
case EventMessages: | ||
return e.messageID() | ||
case EventThreadMessages: | ||
return e.threadID() | ||
case EventFiles: | ||
return e.fileID() | ||
} | ||
return fmt.Sprintf("<unknown:%d>", e.Type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.