Skip to content

Commit 61f476f

Browse files
authored
Merge pull request #1185 from GetStream/unread-handler
add active unread handler function to Channel
2 parents b5453f4 + 7dbe9c0 commit 61f476f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [6.8.0](https://github.com/GetStream/stream-chat-react/releases/tag/v6.8.0) 2021-09-17
4+
5+
### Feature
6+
7+
- Improve user mention experience by ignoring diacritics, adding a `useMentionsTransliteration` prop to install an optional transliteration dependency, and using Levenshtein distance to match similar names [#1176](https://github.com/GetStream/stream-chat-react/pull/1176)
8+
- Add event listener to `ChannelPreview` to handle `markAllRead` function calls on the client [#1178](https://github.com/GetStream/stream-chat-react/pull/1178)
9+
- Add `setText` function to `MessageInputContext`, which overrides and sets the value of the `MessageInput` component's `textarea` element [#1184](https://github.com/GetStream/stream-chat-react/pull/1184)
10+
- Add `activeUnreadHandler` prop to `Channel`, which runs when the active channel has unread messages [#1185](https://github.com/GetStream/stream-chat-react/pull/1185)
11+
12+
### Chore
13+
- Remove all SCSS files and import library styles from `stream-chat-css` dependency. This is non-breaking as the build process injects the external styles into the exact distributed directory as before. [#1168](https://github.com/GetStream/stream-chat-react/pull/1168)
14+
- Upgrade `stream-chat` and `react-file-utils` dependencies [#1178](https://github.com/GetStream/stream-chat-react/pull/1178)
15+
316
## [6.7.2](https://github.com/GetStream/stream-chat-react/releases/tag/v6.7.2) 2021-09-15
417

518
### Feature

docusaurus/docs/React/core-components/channel.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ A list of accepted file upload types.
8686
| -------- |
8787
| string[] |
8888

89+
### activeUnreadHandler
90+
91+
Custom handler function that runs when the active channel has unread messages (i.e., when chat is running on a separate browser tab).
92+
93+
| Type |
94+
| ----------------------------------------------- |
95+
| (unread: number, documentTitle: string) => void |
96+
8997
### Attachment
9098

9199
Custom UI component to display a message attachment.

src/components/Channel/Channel.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export type ChannelProps<
8282
> = {
8383
/** List of accepted file types */
8484
acceptedFiles?: string[];
85+
/** Custom handler function that runs when the active channel has unread messages (i.e., when chat is running on a separate browser tab) */
86+
activeUnreadHandler?: (unread: number, documentTitle: string) => void;
8587
/** Custom UI component to display a message attachment, defaults to and accepts same props as: [Attachment](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Attachment/Attachment.tsx) */
8688
Attachment?: ComponentContextValue<At, Ch, Co, Ev, Me, Re, Us>['Attachment'];
8789
/** Optional UI component to override the default suggestion Header component, defaults to and accepts same props as: [Header](https://github.com/GetStream/stream-chat-react/blob/master/src/components/AutoCompleteTextarea/Header.tsx) */
@@ -270,6 +272,7 @@ const ChannelInner = <
270272
) => {
271273
const {
272274
acceptedFiles,
275+
activeUnreadHandler,
273276
channel,
274277
children,
275278
doMarkReadRequest,
@@ -388,7 +391,12 @@ const ChannelInner = <
388391
markReadThrottled();
389392
} else if (channel.getConfig()?.read_events && !channel.muteStatus().muted) {
390393
const unread = channel.countUnread(lastRead.current);
391-
document.title = `(${unread}) ${originalTitle.current}`;
394+
395+
if (activeUnreadHandler) {
396+
activeUnreadHandler(unread, originalTitle.current);
397+
} else {
398+
document.title = `(${unread}) ${originalTitle.current}`;
399+
}
392400
}
393401
}
394402
}

0 commit comments

Comments
 (0)