feat(forwarder): support forward single grouped message with --single flag. close #487

This commit is contained in:
iyear 2024-02-09 15:46:06 +08:00
parent 757011033a
commit fce339c7d7
6 changed files with 8 additions and 1 deletions

View File

@ -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 }

View File

@ -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) {
@ -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),

View File

@ -24,6 +24,7 @@ type iterOptions struct {
mode forwarder.Mode
silent bool
dryRun bool
grouped bool
}
type iter struct {

View File

@ -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
}

View File

@ -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

View File

@ -23,4 +23,5 @@ type Elem interface {
AsSilent() bool
AsDryRun() bool
AsGrouped() bool // detect and forward grouped messages
}