Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into user_block1
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeadi committed May 8, 2024
2 parents 8df75d4 + 7e02ac8 commit 1bc4c7c
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"{**/*.{js,ts,md,css,scss,json}, .eslintrc.json, .prettierrc, .babelrc}": "prettier --list-different",
"**/*.{js,md,ts}": "eslint --max-warnings 0"
"**/*.{js,md,ts}, !test": "eslint --max-warnings 0"
}
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [8.31.0](https://github.com/GetStream/stream-chat-js/compare/v8.30.0...v8.31.0) (2024-05-02)


### Features

* ability to send poll with campaigns ([#1292](https://github.com/GetStream/stream-chat-js/issues/1292)) ([cace193](https://github.com/GetStream/stream-chat-js/commit/cace1935dc808c03a291a28a084898ee5531d087))
* member_limit option on queryThreads and getThread endpoint ([#1291](https://github.com/GetStream/stream-chat-js/issues/1291)) ([78fae3d](https://github.com/GetStream/stream-chat-js/commit/78fae3d7364150b6b3a7640b4f9b37204702a161))

## [8.30.0](https://github.com/GetStream/stream-chat-js/compare/v8.29.0...v8.30.0) (2024-04-30)


### Features

* "include_soft_deleted_channels" option to export channels api ([#1288](https://github.com/GetStream/stream-chat-js/issues/1288)) ([dcd7621](https://github.com/GetStream/stream-chat-js/commit/dcd7621594accdadc255b0eb091616d1a83cb602))
* support privacy settings ([#1283](https://github.com/GetStream/stream-chat-js/issues/1283)) ([f16552b](https://github.com/GetStream/stream-chat-js/commit/f16552b1e50606d47485b7a77925a1340e046626))

## [8.29.0](https://github.com/GetStream/stream-chat-js/compare/v8.28.0...v8.29.0) (2024-04-30)


### Features

* add reaction groups fallback ([#1286](https://github.com/GetStream/stream-chat-js/issues/1286)) ([7183154](https://github.com/GetStream/stream-chat-js/commit/7183154a663701c24d9c573832288d66e9214565))


### Bug Fixes

* fix filter type for query reactions ([#1287](https://github.com/GetStream/stream-chat-js/issues/1287)) ([65174a5](https://github.com/GetStream/stream-chat-js/commit/65174a55fd30eec445033cb9af745e6d4164f23d))

## [8.28.0](https://github.com/GetStream/stream-chat-js/compare/v8.27.0...v8.28.0) (2024-04-29)


### Features

* add reactiongroups in `MessageResponse` ([#1278](https://github.com/GetStream/stream-chat-js/issues/1278)) ([0d5f87f](https://github.com/GetStream/stream-chat-js/commit/0d5f87fe29dc946044dedd1ad6df0e8780a04e8f))
* sort option on getReplies endpoint ([#1284](https://github.com/GetStream/stream-chat-js/issues/1284)) ([9ad65d3](https://github.com/GetStream/stream-chat-js/commit/9ad65d3ee6e275dc3ac22be1c2f87b082cf58de4))

## [8.27.0](https://github.com/GetStream/stream-chat-js/compare/v8.26.0...v8.27.0) (2024-04-24)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stream-chat",
"version": "8.27.0",
"version": "8.31.0",
"description": "JS SDK for the Stream Chat API",
"author": "GetStream",
"homepage": "https://getstream.io/chat/",
Expand Down
15 changes: 13 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
QueryChannelAPIResponse,
PollVoteData,
SendMessageOptions,
AscDesc,
} from './types';
import { Role } from './permissions';

Expand Down Expand Up @@ -655,7 +656,7 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
* @param {string} [parent_id] set this field to `message.id` to indicate that typing event is happening in a thread
*/
async keystroke(parent_id?: string, options?: { user_id: string }) {
if (!this.getConfig()?.typing_events) {
if (!this._isTypingIndicatorsEnabled()) {
return;
}
const now = new Date();
Expand All @@ -679,7 +680,7 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
* @param {string} [parent_id] set this field to `message.id` to indicate that typing event is happening in a thread
*/
async stopTyping(parent_id?: string, options?: { user_id: string }) {
if (!this.getConfig()?.typing_events) {
if (!this._isTypingIndicatorsEnabled()) {
return;
}
this.lastTypingEvent = null;
Expand All @@ -691,6 +692,13 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
} as Event<StreamChatGenerics>);
}

_isTypingIndicatorsEnabled(): boolean {
if (!this.getConfig()?.typing_events) {
return false;
}
return this.getClient().user?.privacy_settings?.typing_indicators?.enabled ?? true;
}

/**
* lastMessage - return the last message, takes into account that last few messages might not be perfectly sorted
*
Expand Down Expand Up @@ -823,10 +831,13 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
async getReplies(
parent_id: string,
options: MessagePaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string },
sort?: { created_at: AscDesc }[],
) {
const normalizedSort = sort ? normalizeQuerySort(sort) : undefined;
const data = await this.getClient().get<GetRepliesAPIResponse<StreamChatGenerics>>(
this.getClient().baseURL + `/messages/${parent_id}/replies`,
{
sort: normalizedSort,
...options,
},
);
Expand Down
29 changes: 23 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export type QueryReactionsOptions = Pager;

export type QueryReactionsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
reactions: ReactionResponse<StreamChatGenerics>[];
next?: string;
};

export type QueryChannelsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
Expand Down Expand Up @@ -524,6 +525,7 @@ export type PartialThreadUpdate = {

export type QueryThreadsOptions = {
limit?: number;
member_limit?: number;
next?: string;
participant_limit?: number;
reply_limit?: number;
Expand All @@ -536,6 +538,7 @@ export type QueryThreadsAPIResponse<StreamChatGenerics extends ExtendableGeneric
};

export type GetThreadOptions = {
member_limit?: number;
participant_limit?: number;
reply_limit?: number;
watch?: boolean;
Expand Down Expand Up @@ -627,7 +630,6 @@ export type MessageResponse<
export type MessageResponseBase<
StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
> = MessageBase<StreamChatGenerics> & {
reaction_groups: Record<string, ReactionGroupResponse>;
type: MessageLabel;
args?: string;
before_message_send_failed?: boolean;
Expand All @@ -651,6 +653,7 @@ export type MessageResponseBase<
pinned_by?: UserResponse<StreamChatGenerics> | null;
poll?: PollResponse<StreamChatGenerics>;
reaction_counts?: { [key: string]: number } | null;
reaction_groups?: { [key: string]: ReactionGroupResponse } | null;
reaction_scores?: { [key: string]: number } | null;
reply_count?: number;
shadowed?: boolean;
Expand Down Expand Up @@ -715,6 +718,7 @@ export type OwnUserBase<StreamChatGenerics extends ExtendableGenerics = DefaultG
unread_count: number;
unread_threads: number;
invisible?: boolean;
privacy_settings?: PrivacySettings;
roles?: string[];
};

Expand Down Expand Up @@ -832,12 +836,22 @@ export type UserResponse<StreamChatGenerics extends ExtendableGenerics = Default
language?: TranslationLanguages | '';
last_active?: string;
online?: boolean;
privacy_settings?: PrivacySettings;
push_notifications?: PushNotificationSettings;
revoke_tokens_issued_before?: string;
shadow_banned?: boolean;
updated_at?: string;
};

export type PrivacySettings = {
read_receipts?: {
enabled?: boolean;
};
typing_indicators?: {
enabled?: boolean;
};
};

export type PushNotificationSettings = {
disabled?: boolean;
disabled_until?: string | null;
Expand Down Expand Up @@ -1395,11 +1409,7 @@ export type ReactionFilters<StreamChatGenerics extends ExtendableGenerics = Defa
created_at?:
| RequireOnlyOne<Pick<QueryFilter<PollResponse['created_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>>
| PrimitiveFilter<PollResponse['created_at']>;
} & {
[Key in keyof Omit<ReactionResponse<StreamChatGenerics>, 'user_id' | 'type' | 'created_at'>]: RequireOnlyOne<
QueryFilter<ReactionResponse<StreamChatGenerics>[Key]>
>;
}
}
>;

export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = QueryFilters<
Expand Down Expand Up @@ -1669,6 +1679,11 @@ export type UserFilters<StreamChatGenerics extends ExtendableGenerics = DefaultG
>
>
| PrimitiveFilter<UserResponse<StreamChatGenerics>['name']>;
notifications_muted?:
| RequireOnlyOne<{
$eq?: PrimitiveFilter<UserResponse<StreamChatGenerics>['notifications_muted']>;
}>
| boolean;
teams?:
| RequireOnlyOne<{
$contains?: PrimitiveFilter<string>;
Expand Down Expand Up @@ -2314,6 +2329,7 @@ export type ExportChannelRequest = {
export type ExportChannelOptions = {
clear_deleted_message_text?: boolean;
export_users?: boolean;
include_soft_deleted_channels?: boolean;
include_truncated_messages?: boolean;
version?: string;
};
Expand Down Expand Up @@ -2783,6 +2799,7 @@ export type CampaignData = {
text: string;
attachments?: Attachment[];
custom?: {};
poll_id?: string;
};
name?: string;
segment_ids?: string[];
Expand Down
32 changes: 32 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UserResponse,
MessageResponse,
FormatMessageResponse,
ReactionGroupResponse,
} from './types';
import { AxiosRequestConfig } from 'axios';

Expand Down Expand Up @@ -86,6 +87,7 @@ export function isOwnUserBaseProperty(property: string) {
unread_count: true,
unread_threads: true,
invisible: true,
privacy_settings: true,
roles: true,
};

Expand Down Expand Up @@ -295,6 +297,11 @@ export function formatMessage<StreamChatGenerics extends ExtendableGenerics = De
created_at: message.created_at ? new Date(message.created_at) : new Date(),
updated_at: message.updated_at ? new Date(message.updated_at) : new Date(),
status: message.status || 'received',
reaction_groups: maybeGetReactionGroupsFallback(
message.reaction_groups,
message.reaction_counts,
message.reaction_scores,
),
};
}

Expand Down Expand Up @@ -364,3 +371,28 @@ export function addToMessageList<StreamChatGenerics extends ExtendableGenerics =
}
return [...messageArr];
}

function maybeGetReactionGroupsFallback(
groups: { [key: string]: ReactionGroupResponse } | null | undefined,
counts: { [key: string]: number } | null | undefined,
scores: { [key: string]: number } | null | undefined,
): { [key: string]: ReactionGroupResponse } | null {
if (groups) {
return groups;
}

if (counts && scores) {
const fallback: { [key: string]: ReactionGroupResponse } = {};

for (const type of Object.keys(counts)) {
fallback[type] = {
count: counts[type],
sum_scores: scores[type],
};
}

return fallback;
}

return null;
}
41 changes: 40 additions & 1 deletion test/unit/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chai from 'chai';
import { axiosParamsSerializer, generateUUIDv4, normalizeQuerySort } from '../../src/utils';
import { axiosParamsSerializer, formatMessage, normalizeQuerySort } from '../../src/utils';
import sinon from 'sinon';

const expect = chai.expect;
Expand Down Expand Up @@ -100,3 +100,42 @@ describe('axiosParamsSerializer', () => {
}
});
});

describe('reaction groups fallback', () => {
it('uses groups if present', () => {
const date = '2024-04-30T11:03:39.217974Z';
const groups = {
love: {
count: 1,
sum_scores: 1,
first_reaction_at: date,
last_reaction_at: date,
},
};

const message = formatMessage({ reaction_groups: groups });
expect(message.reaction_groups).to.be.equal(groups);
});

it('falls back to counts + scores', () => {
const counts = { love: 1, sad: 1 };
const scores = { love: 1, sad: 2 };

const message = formatMessage({
reaction_groups: null,
reaction_counts: counts,
reaction_scores: scores,
});

expect(message.reaction_groups).to.deep.equal({
love: {
count: 1,
sum_scores: 1,
},
sad: {
count: 1,
sum_scores: 2,
},
});
});
});

0 comments on commit 1bc4c7c

Please sign in to comment.