Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(threads): handle custom data #1428

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

arnautov-anton
Copy link
Contributor

@arnautov-anton arnautov-anton commented Jan 5, 2025

Description of the changes, What, Why and How?

  • allow querying thread-related data as pure objects instead of instances of Thread class (discarded)
  • handle thread.updated within Thread class and consider custom fields

Custom fields

For Thread to handle custom fields, these custom fields have to be defined within StreamChat.customPropertyKeys.thread - ideally set through options during client instantiation. For type support, declaration file has to be created and ThreadResponseCustomData has to be extended:

// yourFile.d.ts

import 'stream-chat';

declare module 'stream-chat' {
  interface ThreadResponseCustomData {
    myCustomProperty: string;
    myOtherCustomProperty: { meta: Array<{ key: number }> };
  }
}

These keys are then accounted for and picked up by the IDE autocomplete:
Screenshot 2025-01-13 at 5 59 19 PM

When the Thread is instantiated, the custom properties can be accessed from the state:

const thread = await client.getThread('messageId');

const { custom } = thread.state.getLatestValue();

console.log(custom.myCustomProperty, custom.myOtherCustomProperty);

Related to: GetStream/stream-chat-react#2592

@arnautov-anton arnautov-anton changed the title feat: threads 2.0 improvements feat(threads): custom data & plain-object responses Jan 5, 2025
Copy link
Contributor

github-actions bot commented Jan 5, 2025

Size Change: +1.62 kB (+0.35%)

Total Size: 465 kB

Filename Size Change
dist/browser.es.js 101 kB +364 B (+0.36%)
dist/browser.full-bundle.min.js 57.1 kB +182 B (+0.32%)
dist/browser.js 103 kB +357 B (+0.35%)
dist/index.es.js 101 kB +362 B (+0.36%)
dist/index.js 103 kB +355 B (+0.35%)

compressed-size-action

@arnautov-anton arnautov-anton force-pushed the feat/threads-improvements branch from ade824e to 98ab939 Compare January 10, 2025 15:14
src/client.ts Outdated Show resolved Hide resolved
@arnautov-anton arnautov-anton changed the title feat(threads): custom data & plain-object responses feat(threads): handle custom data Jan 13, 2025
@arnautov-anton arnautov-anton marked this pull request as ready for review January 13, 2025 17:11
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