Skip to content

Commit

Permalink
feat(forwarder): support forward single grouped message with `--singl…
Browse files Browse the repository at this point in the history
…e` flag. close #487
  • Loading branch information
iyear committed Feb 9, 2024
1 parent 7570110 commit fce339c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/forward/elem.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ func (i *iterElem) Thread() int { return i.thread }
func (i *iterElem) AsSilent() bool { return i.opts.silent }

func (i *iterElem) AsDryRun() bool { return i.opts.dryRun }

func (i *iterElem) AsGrouped() bool { return i.opts.grouped }
2 changes: 2 additions & 0 deletions app/forward/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Options struct {
Mode forwarder.Mode
Silent bool
DryRun bool
Single bool
}

func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr error) {
Expand Down Expand Up @@ -84,6 +85,7 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
mode: opts.Mode,
silent: opts.Silent,
dryRun: opts.DryRun,
grouped: !opts.Single,
}),
Progress: newProgress(fwProgress),
PartSize: viper.GetInt(consts.FlagPartSize),
Expand Down
1 change: 1 addition & 0 deletions app/forward/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type iterOptions struct {
mode forwarder.Mode
silent bool
dryRun bool
grouped bool
}

type iter struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewForward() *cobra.Command {
cmd.Flags().Var(&opts.Mode, "mode", fmt.Sprintf("forward mode: [%s]", strings.Join(forwarder.ModeNames(), ", ")))
cmd.Flags().BoolVar(&opts.Silent, "silent", false, "send messages silently")
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "do not actually send messages, just show how they would be sent")
cmd.Flags().BoolVar(&opts.Single, "single", false, "do not automatically detect and forward grouped messages")

return cmd
}
2 changes: 1 addition & 1 deletion pkg/forwarder/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (f *Forwarder) Forward(ctx context.Context) error {
continue
}

if _, ok := elem.Msg().GetGroupedID(); ok {
if _, ok := elem.Msg().GetGroupedID(); ok && elem.AsGrouped() {
grouped, err := utils.Telegram.GetGroupedMessages(ctx, f.opts.Pool.Default(ctx), elem.From().InputPeer(), elem.Msg())
if err != nil {
continue
Expand Down
1 change: 1 addition & 0 deletions pkg/forwarder/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type Elem interface {

AsSilent() bool
AsDryRun() bool
AsGrouped() bool // detect and forward grouped messages
}

0 comments on commit fce339c

Please sign in to comment.