Skip to content

Implement logic which allow to force clear blocks or attachments on message update. - #486

Merged
yyakhnytsia merged 2 commits into
HubSpot:masterfrom
yyakhnytsia:yyakhnytsia/force-skip-attachments-on-update
Oct 14, 2026
Merged

yyakhnytsia merged 2 commits into
HubSpot:masterfrom
yyakhnytsia:yyakhnytsia/force-skip-attachments-on-update

Conversation

@yyakhnytsia

Copy link
Copy Markdown
Contributor

Why

Slack's chat.update keeps a field when it's omitted and clears it only when sent as []. Since ChatUpdateMessageParams is @JsonInclude(NON_EMPTY), an empty attachments/blocks list is dropped — so there's currently no way to clear attachments or blocks via the typed client. This blocks updating a message from one representation to another (e.g. legacy attachments → Block Kit blocks): the old field lingers and the message renders both stacked.

What changed

  • ChatUpdateMessageParamsIF — two @JsonIgnore @Default false flags, shouldClearAttachments() / shouldClearBlocks(). When set, the field serializes as []; default-off means serialization is unchanged for all existing callers.
  • ForceEmitPropertyWriter (new) — BeanPropertyWriter that force-emits an empty field when the flag is set, else defers to the default writer.
  • ChatUpdateMessageParamsSerializerModifier (new) — BeanSerializerModifier that swaps only the attachments/blocks writers on ChatUpdateMessageParams; all other fields keep their default writers.
  • ObjectMapperUtils — registers the modifier on the shared mapper (early-returns for every other type).

Testing

ChatUpdateMessageParamsSerializationTest: 13 tests (omit-when-off, emit-[]-when-on, non-empty preserved, flag independence, flags don't leak, drift guard, other-types-untouched). Full slack-base suite: 369/369 pass.

@Viktor-Pelepiak Viktor-Pelepiak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yyakhnytsia
yyakhnytsia merged commit 548d336 into HubSpot:master Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants