Documentation ¶
Overview ¶
Package structures provides functions to parse Slack data types.
Index ¶
- Constants
- Variables
- func ChannelType(ch slack.Channel) int
- func ExtractWorkspace(workspace string) (string, error)
- func FormatSlackTS(ts time.Time) string
- func HasExcludePrefix(s string) bool
- func IsThreadStart(m *slack.Message) bool
- func IsURL(s string) bool
- func IsValidSlackURL(s string) bool
- func NVL(s string, ss ...string) string
- func ParseSlackTS(timestamp string) (time.Time, error)
- func ParseThreadID(threadID string) (time.Time, error)
- func ResolveURLs(idsOrURLs []string) ([]string, error)
- func SplitEntryList(s string) []string
- func ValidateEntityList(s string) error
- func ValidateToken(token string) error
- type DM
- type EntityIndex
- type EntityList
- type ExportIndex
- type SlackLink
- type UserIndex
Constants ¶
const ( CUnknown = iota CIM CMPIM CPrivate CPublic )
const (
LatestReplyNoReplies = "0000000000.000000"
)
const LinkSep = ":"
const (
SubTypeThreadBroadcast = "thread_broadcast"
)
Variables ¶
var ( ErrMaxFileSize = errors.New("maximum file size exceeded") ErrEmptyList = errors.New("empty list") )
var ( ErrNoChannel = errors.New("empty channel data base") ErrNoUsers = errors.New("empty users data base") ErrNoIdent = errors.New("empty user identity") )
var ( ErrUnsupportedURL = errors.New("unsupported URL type") ErrNoURL = errors.New("no url provided") ErrNotSlackURL = errors.New("not a slack URL") ErrInvalidLink = errors.New("invalid link") )
var ErrInvalidDomain = errors.New("invalid domain")
Functions ¶
func ChannelType ¶
func ExtractWorkspace ¶
ExtractWorkspace takes a workspace name or URL and returns the workspace name.
func FormatSlackTS ¶
func HasExcludePrefix ¶
func IsThreadStart ¶
func IsValidSlackURL ¶
IsValidSlackURL returns true if the value looks like valid Slack URL, false if not.
func ParseSlackTS ¶
ParseSlackTS parses the slack timestamp.
func ParseThreadID ¶
ParseThreadID parses the thread id (ie. p1577694990000400) and returns time.Time.
func ResolveURLs ¶
ResolveURLs normalises all channels to ID form. If the idsOrURLs[i] is a channel ID, it is unmodified, if it is URL - it is parsed and replaced with the channel ID. If the channel is marked for exclusion in the list it will retain this status.
func SplitEntryList ¶
SplitEntryList splits the string by space.
func ValidateEntityList ¶
ValidateEntityList validates a space-separated list of entities.
func ValidateToken ¶
Types ¶
type DM ¶
type DM struct { ID string `json:"id"` Created int64 `json:"created"` Members []string `json:"members"` }
DM respresents a direct Message entry in dms.json. Structure is based on this post:
https://github.com/RocketChat/Rocket.Chat/issues/13905#issuecomment-477500022
type EntityIndex ¶
func (EntityIndex) IsExcluded ¶
func (ei EntityIndex) IsExcluded(ent string) bool
IsExcluded returns true if the entity is excluded (is in the list, and has value false).
func (EntityIndex) IsIncluded ¶
func (ei EntityIndex) IsIncluded(ent string) bool
IsIncluded returns true if the entity is included (is in the list, and has value true).
type EntityList ¶
type EntityList struct { Include []string Exclude []string // contains filtered or unexported fields }
EntityList is an Inclusion/Exclusion list
func LoadEntityList ¶
func LoadEntityList(filename string) (*EntityList, error)
LoadEntityList creates an EntityList from a slice of IDs or URLs (entites).
func NewEntityList ¶
func NewEntityList(entities []string) (*EntityList, error)
NewEntityList creates an EntityList from a slice of IDs or URLs (entites).
func NewEntityListFromString ¶
func NewEntityListFromString(s string) (*EntityList, error)
NewEntityListFromString creates an EntityList from a space-separated list of entities.
func (*EntityList) C ¶
func (el *EntityList) C(ctx context.Context) <-chan string
C returns a channel where all included entries are streamed. The channel is closed when all entries have been sent, or when the context is cancelled.
func (*EntityList) HasExcludes ¶
func (el *EntityList) HasExcludes() bool
HasExcludes returns true if there's any excluded entities.
func (*EntityList) HasIncludes ¶
func (el *EntityList) HasIncludes() bool
HasIncludes returns true if there's any included entities.
func (*EntityList) Index ¶
func (el *EntityList) Index() EntityIndex
Index returns a map where key is entity, and value show if the entity should be processed (true) or not (false).
func (*EntityList) IsEmpty ¶
func (el *EntityList) IsEmpty() bool
IsEmpty returns true if there's no entries in the list.
type ExportIndex ¶
type ExportIndex struct { Channels []slack.Channel `filename:"channels.json"` Groups []slack.Channel `filename:"groups.json,omitempty"` MPIMs []slack.Channel `filename:"mpims.json,omitempty"` DMs []DM `filename:"dms.json,omitempty"` Users []slack.User `filename:"users.json"` }
ExportIndex is the ExportIndex of the export archive. filename tags are used to serialize the structure to JSON files.
func MakeExportIndex ¶
func MakeExportIndex(channels []slack.Channel, users []slack.User, currentUserID string) (*ExportIndex, error)
MakeExportIndex creates a channels and users index for export archive, splitting channels in group/mpims/dms/public channels. currentUserID should contain the current user ID.
func (*ExportIndex) Marshal ¶
func (idx *ExportIndex) Marshal(fs fsadapter.FS) error
Marshal writes the index to the filesystem in a set of files specified in `filename` tags of the structure.
func (*ExportIndex) Restore ¶
func (idx *ExportIndex) Restore() []slack.Channel
Restore restores the index to the original channels slice (minus the lost data from DMs).
type SlackLink ¶
func ParseLink ¶
ParseLink parses the slack link string. It supports the following formats:
- XXXXXXX - channel ID
- XXXXXXX:99999999.99999 - channel ID and thread ID
- https://<valid slack URL> - slack URL link.
It returns the SlackLink or error.
func ParseURL ¶
ParseURL parses the slack link in the format of https://xxxx.slack.com/archives/XXXXX[/p99999999]
type UserIndex ¶
UserIndex is a mapping of user ID to the *slack.User.
func NewUserIndex ¶
NewUserIndex creates a new UserIndex from slack Users slice
func (UserIndex) ChannelName ¶
ChannelName return the "beautified" name of the channel.
func (UserIndex) DisplayName ¶
DisplayName tries to resolve the display name by ID. if the index is empty, it returns the user ID. If the user is not found in index, is assumes that it is an external user and returns ID with "external" prefix. If it does find the user and display name is unavailble, it returns the Real Name.
func (UserIndex) IsDeleted ¶
IsDeleted checks if the user is deleted and returns appropriate value. It will assume user is not deleted, if it's not present in the user index.