Skip to content

Commit

Permalink
moar edge
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 26, 2024
1 parent e528f5c commit 034f065
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 12 deletions.
18 changes: 18 additions & 0 deletions cmd/slackdump/internal/diag/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ func runEdge(ctx context.Context, cmd *base.Command, args []string) error {
return err
}

lg.Printf("*** IMs test ***")
ims, err := cl.IMs(ctx)
if err != nil {
return err
}
if err := save("ims.json", ims); err != nil {
return err
}

lg.Printf("*** Counts ***")
counts, err := cl.Counts(ctx)
if err != nil {
return err
}
if err := save("counts.json", counts); err != nil {
return err
}

return nil
}

Expand Down
22 changes: 22 additions & 0 deletions internal/edge/bookmarks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package edge

import "encoding/json"

/*
channel: GM27XUQT0
include_folders: true
include_legacy_workflows: true
*/
type bookmarksListForm struct {
BaseRequest
Channel string `json:"channel"`
IncludeFolders bool `json:"include_folders"`
IncludeLegacyWorkflows bool `json:"include_legacy_workflows"`
}

type bookmarksListResponse struct {
BaseResponse
Bookmarks []json.RawMessage `json:"bookmarks"`
}

//"bookmarks.list"
54 changes: 42 additions & 12 deletions internal/edge/dms.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (cl *Client) DMs(ctx context.Context) ([]DM, error) {
if err := cl.ParseResponse(&r, resp); err != nil {
return nil, err
}
IMs = append(IMs, r.IMs...)
if r.ResponseMetadata.NextCursor == "" {
break
}
IMs = append(IMs, r.IMs...)
time.Sleep(300 * time.Millisecond) //TODO: hax
form.Cursor = r.ResponseMetadata.NextCursor
}
Expand Down Expand Up @@ -123,25 +123,16 @@ func (cl *Client) IMs(ctx context.Context) ([]Channel, error) {
if err := cl.ParseResponse(&r, resp); err != nil {
return nil, err
}
IMs = append(IMs, r.IMs...)
if r.ResponseMetadata.NextCursor == "" {
break
}
IMs = append(IMs, r.IMs...)
time.Sleep(300 * time.Millisecond) //TODO: hax
form.Cursor = r.ResponseMetadata.NextCursor
}
return IMs, nil
}

/*
thread_counts_by_channel: true
org_wide_aware: true
include_file_channels: true
_x_reason: client-counts-api/fetchClientCounts
_x_mode: online
_x_sonic: true
_x_app_name: client
*/
type countsForm struct {
BaseRequest
ThreadCountsByChannel bool `json:"thread_counts_by_channel"`
Expand All @@ -150,4 +141,43 @@ type countsForm struct {
WebClientFields
}

// func (cl *Client) Counts(ctx context.Context)
type CountsResponse struct {
BaseResponse
Channels []ChannelSnapshot `json:"channels,omitempty"`
MPIMs []ChannelSnapshot `json:"mpims,omitempty"`
IMs []ChannelSnapshot `json:"ims,omitempty"`
}

type ChannelSnapshot struct {
ID string `json:"id"`
LastRead string `json:"last_read"`
Latest string `json:"latest"`
HistoryInvalid string `json:"history_invalid"`
MentionCount int `json:"mention_count"`
HasUnreads bool `json:"has_unreads"`
}

func (cl *Client) Counts(ctx context.Context) (CountsResponse, error) {
form := countsForm{
BaseRequest: BaseRequest{Token: cl.token},
ThreadCountsByChannel: true,
OrgWideAware: true,
IncludeFileChannels: true,
WebClientFields: WebClientFields{
XReason: "client-counts-api/fetchClientCounts",
XMode: "online",
XSonic: true,
XAppName: "client",
},
}

resp, err := cl.PostForm(ctx, "client.counts", values(form, true))
if err != nil {
return CountsResponse{}, err
}
r := CountsResponse{}
if err := cl.ParseResponse(&r, resp); err != nil {
return CountsResponse{}, err
}
return r, nil
}

0 comments on commit 034f065

Please sign in to comment.