From 406b0b00e49ce4a747d27c3f3257510891365611 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Fri, 29 Sep 2023 13:37:16 +0200 Subject: [PATCH] fix: Ensure failed operation is also undone --- message.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/message.go b/message.go index 629bdbd..0d489c3 100644 --- a/message.go +++ b/message.go @@ -138,9 +138,9 @@ func (c *Client) LabelMessages(ctx context.Context, messageIDs []string, labelID } if ok, errStr := res.ok(); !ok { - tokens := xslices.Map(results, func(res LabelMessagesRes) UndoToken { + tokens := append(xslices.Map(results, func(res LabelMessagesRes) UndoToken { return res.UndoToken - }) + }), res.UndoToken) if _, undoErr := c.UndoActions(ctx, tokens...); undoErr != nil { return fmt.Errorf("failed to undo label actions (undo reason: %v): %w", errStr, undoErr) @@ -171,9 +171,9 @@ func (c *Client) UnlabelMessages(ctx context.Context, messageIDs []string, label } if ok, errStr := res.ok(); !ok { - tokens := xslices.Map(results, func(res LabelMessagesRes) UndoToken { + tokens := append(xslices.Map(results, func(res LabelMessagesRes) UndoToken { return res.UndoToken - }) + }), res.UndoToken) if _, undoErr := c.UndoActions(ctx, tokens...); undoErr != nil { return fmt.Errorf("failed to undo unlabel actions (undo reason: %v): %w", errStr, undoErr)