Skip to content

Commit ec46387

Browse files
authored
Merge pull request #593 from rusq/i62
Custom User Profile Fields
2 parents 883dff9 + 51b626c commit ec46387

File tree

20 files changed

+365
-31
lines changed

20 files changed

+365
-31
lines changed

cmd/slackdump/internal/archive/archive.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ func runDBArchive(ctx context.Context, cmd *base.Command, args []string) error {
121121
}
122122
defer conn.Close()
123123

124-
flags := control.Flags{MemberOnly: cfg.MemberOnly, RecordFiles: cfg.RecordFiles, ChannelUsers: cfg.OnlyChannelUsers, ChannelTypes: cfg.ChannelTypes}
124+
flags := control.Flags{
125+
MemberOnly: cfg.MemberOnly,
126+
RecordFiles: cfg.RecordFiles,
127+
ChannelUsers: cfg.OnlyChannelUsers,
128+
IncludeLabels: cfg.IncludeCustomLabels,
129+
ChannelTypes: cfg.ChannelTypes,
130+
}
125131

126132
ctrl, err := DBController(ctx, cmd.Name(), conn, client, dirname, flags, []stream.Option{})
127133
if err != nil {
@@ -246,10 +252,11 @@ func ArchiveController(ctx context.Context, cd *chunk.Directory, client client.S
246252
erc := directory.NewERC(cd, lg)
247253

248254
flags := control.Flags{
249-
MemberOnly: cfg.MemberOnly,
250-
RecordFiles: cfg.RecordFiles,
251-
ChannelUsers: cfg.OnlyChannelUsers,
252-
ChannelTypes: cfg.ChannelTypes,
255+
MemberOnly: cfg.MemberOnly,
256+
RecordFiles: cfg.RecordFiles,
257+
ChannelUsers: cfg.OnlyChannelUsers,
258+
IncludeLabels: cfg.IncludeCustomLabels,
259+
ChannelTypes: cfg.ChannelTypes,
253260
}
254261

255262
ctrl, err := control.New(

cmd/slackdump/internal/archive/archive_wizard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func configuration() cfgui.Configuration {
3535
cfgui.ChannelIDs(&entryList, false),
3636
cfgui.MemberOnly(),
3737
cfgui.OnlyChannelUsers(),
38+
cfgui.IncludeCustomLabels(),
3839
cfgui.RecordFiles(),
3940
cfgui.Avatars(),
4041
cfgui.ChannelTypes(),

cmd/slackdump/internal/cfg/cfg.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ var (
3636
MachineIDOvr string // Machine ID override
3737
NoEncryption bool // disable encryption
3838

39-
MemberOnly bool
40-
OnlyChannelUsers bool
39+
MemberOnly bool
40+
OnlyChannelUsers bool
41+
IncludeCustomLabels bool // Requests labels for user custom fields, use with caution due to request throttling.
4142
// ChannelTypes lists channel types to fetch.
4243
ChannelTypes = slackChanTypes(slackdump.AllChanTypes)
4344

@@ -198,6 +199,7 @@ func SetBaseFlags(fs *flag.FlagSet, mask FlagMask) {
198199
if mask&OmitCustomUserFlags == 0 {
199200
fs.BoolVar(&MemberOnly, "member-only", false, "export only channels, which the current user belongs to (if no channels are specified)")
200201
fs.BoolVar(&OnlyChannelUsers, "channel-users", false, "export only users involved in the channel, and skip fetching of all users")
202+
fs.BoolVar(&IncludeCustomLabels, "custom-labels", false, "request user's custom fields labels, may result in requests being throttled hard")
201203
}
202204
if mask&OmitChunkFileMode == 0 {
203205
fs.BoolVar(&UseChunkFiles, "legacy", false, "use chunk files for data storage instead of sqlite database (incompatible with resuming)")

cmd/slackdump/internal/export/v3.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ func exportv31(ctx context.Context, sess client.Slack, fsa fsadapter.FS, list *s
7979
)
8080

8181
flags := control.Flags{
82-
MemberOnly: cfg.MemberOnly,
83-
RecordFiles: false, // archive format is transitory, don't need extra info.
84-
ChannelUsers: cfg.OnlyChannelUsers,
85-
ChannelTypes: cfg.ChannelTypes,
82+
MemberOnly: cfg.MemberOnly,
83+
RecordFiles: false, // archive format is transitory, don't need extra info.
84+
ChannelUsers: cfg.OnlyChannelUsers,
85+
ChannelTypes: cfg.ChannelTypes,
86+
IncludeLabels: cfg.IncludeCustomLabels,
8687
}
8788
ctr, err := control.New(
8889
ctx,
@@ -167,10 +168,11 @@ func export(ctx context.Context, sess client.Slack, fsa fsadapter.FS, list *stru
167168
)
168169

169170
flags := control.Flags{
170-
MemberOnly: cfg.MemberOnly,
171-
RecordFiles: false, // archive format is transitory, don't need extra info.
172-
ChannelUsers: cfg.OnlyChannelUsers,
173-
ChannelTypes: cfg.ChannelTypes,
171+
MemberOnly: cfg.MemberOnly,
172+
RecordFiles: false, // archive format is transitory, don't need extra info.
173+
ChannelUsers: cfg.OnlyChannelUsers,
174+
IncludeLabels: cfg.IncludeCustomLabels,
175+
ChannelTypes: cfg.ChannelTypes,
174176
}
175177
ctr := control.NewDir(
176178
chunkdir,

cmd/slackdump/internal/export/wizard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (fl *exportFlags) configuration() cfgui.Configuration {
5252
},
5353
cfgui.MemberOnly(),
5454
cfgui.OnlyChannelUsers(),
55+
cfgui.IncludeCustomLabels(),
5556
cfgui.Avatars(),
5657
{
5758
Name: "Export Token",

cmd/slackdump/internal/resume/resume.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ func runResume(ctx context.Context, cmd *base.Command, args []string) error {
125125
defer wconn.Close()
126126

127127
cf := control.Flags{
128-
Refresh: resumeFlags.Refresh,
129-
ChannelUsers: cfg.OnlyChannelUsers,
130-
ChannelTypes: cfg.ChannelTypes,
128+
Refresh: resumeFlags.Refresh,
129+
ChannelUsers: cfg.OnlyChannelUsers,
130+
ChannelTypes: cfg.ChannelTypes,
131+
IncludeLabels: cfg.IncludeCustomLabels,
132+
MemberOnly: cfg.MemberOnly,
131133
}
132134
// inclusive is false, because we don't want to include the latest message
133135
// which is already in the database.
@@ -146,10 +148,6 @@ func runResume(ctx context.Context, cmd *base.Command, args []string) error {
146148
return nil
147149
}
148150

149-
// oldestAdjustment is one second adjustment for Oldest timestamp to allow for
150-
// fetching thread messages (see #584)
151-
const oldestAdjustment = -1 * time.Hour
152-
153151
func latest(ctx context.Context, src source.Resumer, includeThreads bool, lookBack time.Duration) (*structures.EntityList, error) {
154152
if lookBack > 0 {
155153
lookBack = -lookBack

cmd/slackdump/internal/resume/wizard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func configuration() cfgui.Configuration {
5454
Name: "Optional parameters",
5555
Params: []cfgui.Parameter{
5656
cfgui.OnlyChannelUsers(),
57+
cfgui.IncludeCustomLabels(),
5758
cfgui.Avatars(),
5859
},
5960
},

cmd/slackdump/internal/ui/cfgui/common_params.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@ func ChannelTypes() Parameter {
9898
Options(options...)),
9999
}
100100
}
101+
102+
func IncludeCustomLabels() Parameter {
103+
return Parameter{
104+
Name: "Include Custom Field Labels",
105+
Value: Checkbox(cfg.IncludeCustomLabels),
106+
Description: "Channel users custom user profile fields labels (may result in request throttling).",
107+
Updater: updaters.NewBool(&cfg.IncludeCustomLabels),
108+
}
109+
}

internal/chunk/control/control.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ func (c *Controller) mkSuperprocessor(ctx context.Context, rec *chunk.Recorder,
9393
ucoll := newMsgUserIDsCollector()
9494
conv = processor.PrependMessenger(conv, ucoll)
9595
streamer = &userCollectingStreamer{
96-
Streamer: streamer,
97-
userIDC: ucoll.C(),
96+
Streamer: streamer,
97+
userIDC: ucoll.C(),
98+
includeLabels: c.flags.IncludeLabels,
9899
}
99100
}
100101

internal/chunk/control/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Streamer interface {
2323
SearchMessages(ctx context.Context, proc processor.MessageSearcher, query string) error
2424
SearchFiles(ctx context.Context, proc processor.FileSearcher, query string) error
2525
UsersBulk(ctx context.Context, proc processor.Users, ids ...string) error
26+
UsersBulkWithCustom(ctx context.Context, proc processor.Users, includeLabels bool, ids ...string) error
2627
}
2728

2829
type TransformStarter interface {

0 commit comments

Comments
 (0)