Skip to content

Commit

Permalink
Merge branch 'develop' into add-vale-doc-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenleenarts authored Dec 19, 2022
2 parents 1bc54a6 + 0441789 commit 65b2d88
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [10.4.1](https://github.com/GetStream/stream-chat-react/compare/v10.4.0...v10.4.1) (2022-11-18)


### Bug Fixes

* add linkify.test check before any URL instantiation ([#1838](https://github.com/GetStream/stream-chat-react/issues/1838)) ([ef1dd0a](https://github.com/GetStream/stream-chat-react/commit/ef1dd0ae5df511d0796c04808a08ee3ebfc00bc6))

# [10.4.0](https://github.com/GetStream/stream-chat-react/compare/v10.3.1...v10.4.0) (2022-11-04)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The function to send a `message` on `Channel`. Takes a `message` object with the
|----------|
| function |

### setQuoteMessage
### setQuotedMessage

The function to send a `QuotedMessage` on a `Channel`, take a `message` object.

Expand Down
27 changes: 19 additions & 8 deletions docusaurus/docs/React/guides/customization/channel-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,37 @@ To override the search method, completely use the `searchFunction` prop. This pr
and for only channels that the current logged in user is a member of. See the example below for this.
```jsx
const customSearchFunction = async (props: ChannelSearchFunctionParams, event: { target: { value: SetStateAction<string>; }; }) => {
const { setResults, setResultsOpen, setSearching, setQuery } = props;
const { client } = useChatContext();
const customSearchFunction = async (
props: ChannelSearchFunctionParams,
event: { target: { value: SetStateAction<string> } },
client: StreamChat
) => {
const { setResults, setSearching, setQuery } = props;
const value = event.target.value;

const filters = {
name: { $autocomplete: event.target.value },
name: { $autocomplete: value },
members: { $in: client.userID }
}

setSearching(true);
setQuery(event.target.value);
const channels = await chatClient.queryChannels(filters);
setQuery(value);
const channels = await client.queryChannels(filters);
setResults(channels);
setResultsOpen(true);
setSearching(false);
};
```
```jsx
const { client } = useChatContext();

<ChannelList
additionalChannelSearchProps={{
searchFunction: (params, event) => {
return customSearchFunction(params, event, client);
},
}}
showChannelSearch
additionalChannelSearchProps={{searchFunction: customSearchFunction}}
/>
```
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@braintree/sanitize-url": "6.0.0",
"@popperjs/core": "^2.11.5",
"@stream-io/stream-chat-css": "^3.6.0",
"@stream-io/stream-chat-css": "^3.7.1",
"clsx": "^1.1.1",
"dayjs": "^1.10.4",
"emoji-mart": "3.0.1",
Expand Down Expand Up @@ -95,7 +95,7 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-typescript": "8.2.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/git": "^10.0.1",
"@stream-io/rollup-plugin-node-builtins": "^2.1.5",
"@testing-library/jest-dom": "^5.16.4",
Expand Down Expand Up @@ -168,7 +168,7 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-url": "^3.0.1",
"rollup-plugin-visualizer": "^4.2.0",
"semantic-release": "^19.0.2",
"semantic-release": "^19.0.5",
"semantic-release-cli": "^5.4.4",
"stream-chat": "^7.1.0",
"style-loader": "^2.0.0",
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/__snapshots__/utils.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renderText handles the special case where there's at least one mention and @ symbol at the end 1`] = `
<p>
<span
className="str-chat__message-mention"
data-user-id="[email protected]"
>
@[email protected]
</span>
@
</p>
`;

exports[`renderText handles the special case where user name matches to an e-mail pattern - 1 1`] = `
<p>
Hello
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,12 @@ describe(`renderText`, () => {
const tree = renderer.create(Markdown).toJSON();
expect(tree).toMatchSnapshot();
});

it("handles the special case where there's at least one mention and @ symbol at the end", () => {
const Markdown = renderText('@[email protected] @', [
{ id: '[email protected]', name: '[email protected]' },
]);
const tree = renderer.create(Markdown).toJSON();
expect(tree).toMatchSnapshot();
});
});
34 changes: 20 additions & 14 deletions src/components/MessageInput/hooks/useCooldownTimer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import { useChatContext } from '../../../context/ChatContext';
import { useChannelStateContext } from '../../../context/ChannelStateContext';
Expand All @@ -17,30 +17,36 @@ export const useCooldownTimer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
>(): CooldownTimerState => {
const { latestMessageDatesByChannels } = useChatContext<StreamChatGenerics>('useCooldownTimer');
const { channel } = useChannelStateContext<StreamChatGenerics>('useCooldownTimer');
const { channel, messages = [] } = useChannelStateContext<StreamChatGenerics>('useCooldownTimer');
const { client } = useChatContext<StreamChatGenerics>('useCooldownTimer');
const [cooldownRemaining, setCooldownRemaining] = useState<number>();

const { cooldown: cooldownInterval, own_capabilities } = (channel.data ||
{}) as ChannelResponse<StreamChatGenerics>;

const [cooldownRemaining, setCooldownRemaining] = useState<number>();

const skipCooldown = !own_capabilities?.includes('slow-mode');

const ownLatestMessageDate = useMemo(
() =>
latestMessageDatesByChannels[channel.cid] ??
[...messages]
.sort((a, b) => (b.created_at as Date)?.getTime() - (a.created_at as Date)?.getTime())
.find((v) => v.user?.id === client.user?.id)?.created_at,
[messages, client.user?.id, latestMessageDatesByChannels, channel.cid],
) as Date;

useEffect(() => {
const latestMessageDate = latestMessageDatesByChannels[channel.cid];
if (!cooldownInterval || !latestMessageDate) {
return;
}
if (skipCooldown || !cooldownInterval || !ownLatestMessageDate) return;

const remainingCooldown = Math.round(
cooldownInterval - (new Date().getTime() - latestMessageDate.getTime()) / 1000,
cooldownInterval - (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000,
);
if (remainingCooldown > 0 && !skipCooldown) {
setCooldownRemaining(remainingCooldown);
}
}, [channel.id, cooldownInterval, latestMessageDatesByChannels[channel.cid]]);

if (remainingCooldown > 0) setCooldownRemaining(remainingCooldown);
}, [cooldownInterval, ownLatestMessageDate, skipCooldown]);

return {
cooldownInterval: cooldownInterval || 0,
cooldownInterval: cooldownInterval ?? 0,
cooldownRemaining,
setCooldownRemaining,
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/MessageInput/hooks/useUserTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const useUserTrigger = <
id: { $ne: client.userID },
...mentionQueryParams.filters,
},
{ id: 1, ...mentionQueryParams.sort },
Array.isArray(mentionQueryParams.sort)
? [{ id: 1 }, ...mentionQueryParams.sort]
: { id: 1, ...mentionQueryParams.sort },
{ limit: 10, ...mentionQueryParams.options },
);

Expand Down
4 changes: 2 additions & 2 deletions src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const mentionsMarkdownPlugin = <
if (!parent) return;

const nextChild = parent.children.at(index + 1) as Element;
const nextChildHref = nextChild?.properties?.href as string;
const nextChildHref = nextChild?.properties?.href as string | undefined;

if (
node.type === 'text' &&
Expand All @@ -197,7 +197,7 @@ export const mentionsMarkdownPlugin = <
// valid cases: "text @", "@", " @"
// invalid cases: "text@", "@text",
/.?\s?@$|^@$/.test(node.value) &&
nextChildHref.startsWith('mailto:')
nextChildHref?.startsWith('mailto:')
) {
const newTextValue = node.value.replace(/@$/, '');
const username = nextChildHref.replace('mailto:', '');
Expand Down
50 changes: 22 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1962,14 +1962,14 @@
estree-walker "^2.0.2"
picomatch "^2.3.1"

"@semantic-release/changelog@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@semantic-release/changelog/-/changelog-6.0.1.tgz#8dd0334fd8c7d50cda747d2591e4f18f816b3c9c"
integrity sha512-FT+tAGdWHr0RCM3EpWegWnvXJ05LQtBkQUaQRIExONoXjVjLuOILNm4DEKNaV+GAQyJjbLRVs57ti//GypH6PA==
"@semantic-release/changelog@^6.0.2":
version "6.0.2"
resolved "https://registry.yarnpkg.com/@semantic-release/changelog/-/changelog-6.0.2.tgz#fdcdbd368788c8fcc69c4af29bf2064f4afb45f4"
integrity sha512-jHqfTkoPbDEOAgAP18mGP53IxeMwxTISN+GwTRy9uLu58UjARoZU8ScCgWGeO2WPkEsm57H8AkyY02W2ntIlIw==
dependencies:
"@semantic-release/error" "^3.0.0"
aggregate-error "^3.0.0"
fs-extra "^9.0.0"
fs-extra "^11.0.0"
lodash "^4.17.4"

"@semantic-release/commit-analyzer@^9.0.2":
Expand Down Expand Up @@ -2099,10 +2099,10 @@
crypto-browserify "^3.11.0"
process-es6 "^0.11.2"

"@stream-io/stream-chat-css@^3.6.0":
version "3.6.0"
resolved "https://registry.yarnpkg.com/@stream-io/stream-chat-css/-/stream-chat-css-3.6.0.tgz#ed8e28b3e745ad3335c0a3120ecfa4f22900727f"
integrity sha512-LYUXW031EaQoBN1DfrqJ2iZNUPyd+3oXCczbj4C8Jt36USW9eUipaLpSU1e4XoJbA5RH81WY7/ix2NT0dHq9ng==
"@stream-io/stream-chat-css@^3.7.1":
version "3.7.1"
resolved "https://registry.yarnpkg.com/@stream-io/stream-chat-css/-/stream-chat-css-3.7.1.tgz#425391953064cc825be34a20ff9bee0a8cf3b76e"
integrity sha512-6l6uqog+5hIKU7ARE2n8rOOEoFGKtPqVSBWdDjFv2bMuN70I3kvAcmFrd+k6J0K0dyMbK/E0h1im0q0iADiaww==

"@stream-io/transliterate@^1.5.5":
version "1.5.5"
Expand Down Expand Up @@ -3326,11 +3326,6 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=

at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

atob@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
Expand Down Expand Up @@ -7399,6 +7394,15 @@ fs-extra@^10.0.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^11.0.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed"
integrity sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^8.0.1, fs-extra@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
Expand All @@ -7408,16 +7412,6 @@ fs-extra@^8.0.1, fs-extra@^8.1.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^9.0.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-merger@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/fs-merger/-/fs-merger-3.2.1.tgz#a225b11ae530426138294b8fbb19e82e3d4e0b3b"
Expand Down Expand Up @@ -14486,10 +14480,10 @@ semantic-release-cli@^5.4.4:
user-home "^2.0.0"
validator "^12.0.0"

semantic-release@^19.0.2:
version "19.0.2"
resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-19.0.2.tgz#6011683c06d7b416e5faa5a3f43b22bbf3798aa8"
integrity sha512-7tPonjZxukKECmClhsfyMKDt0GR38feIC2HxgyYaBi+9tDySBLjK/zYDLhh+m6yjnHIJa9eBTKYE7k63ZQcYbw==
semantic-release@^19.0.5:
version "19.0.5"
resolved "https://registry.yarnpkg.com/semantic-release/-/semantic-release-19.0.5.tgz#d7fab4b33fc20f1288eafd6c441e5d0938e5e174"
integrity sha512-NMPKdfpXTnPn49FDogMBi36SiBfXkSOJqCkk0E4iWOY1tusvvgBwqUmxTX1kmlT6kIYed9YwNKD1sfPpqa5yaA==
dependencies:
"@semantic-release/commit-analyzer" "^9.0.2"
"@semantic-release/error" "^3.0.0"
Expand Down

0 comments on commit 65b2d88

Please sign in to comment.