Skip to content

Commit

Permalink
Merge branch 'master' into threads
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored Feb 23, 2024
2 parents ed261bf + cf27583 commit 8c339ec
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 293 deletions.
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if ! yarn run lint-staged; then
echo
echo "Some files were not formatted correctly (see output above), commit aborted!"
echo "Consider running \"yarn run fix-staged\" to attempt auto-fix."
exit 1
fi
4 changes: 4 additions & 0 deletions .lintstagedrc.fix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"{**/*.{js,ts,md,css,scss,json}, .eslintrc.json, .prettierrc, .babelrc}": "prettier --write",
"**/*.{js,md,ts}": "eslint --fix"
}
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"{**/*.{js,ts,md,css,scss,json}, .eslintrc.json, .prettierrc, .babelrc}": "prettier --list-different",
"**/*.{js,md,ts}": "eslint --max-warnings 0"
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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.18.0](https://github.com/GetStream/stream-chat-js/compare/v8.17.0...v8.18.0) (2024-02-22)


### Features

* campaigns api ([#1225](https://github.com/GetStream/stream-chat-js/issues/1225)) ([bcb8ad7](https://github.com/GetStream/stream-chat-js/commit/bcb8ad784009216fa6252dba294afa8d900e4625))

## [8.17.0](https://github.com/GetStream/stream-chat-js/compare/v8.16.0...v8.17.0) (2024-02-22)


### Features

* dispatch capabilties.changed event on partial update if own_capabilties are changed ([#1230](https://github.com/GetStream/stream-chat-js/issues/1230)) ([0b935a9](https://github.com/GetStream/stream-chat-js/commit/0b935a907edc1d1b3d8627ba3d8fef5ea90c5a4e))


### Bug Fixes

* add missing in$ operator for teams filter in queryUsers ([#1226](https://github.com/GetStream/stream-chat-js/issues/1226)) ([3c2166c](https://github.com/GetStream/stream-chat-js/commit/3c2166c226e303475f54bf516079a4e9c5592e23))
* markRead and markUnread can be called from server-side ([#1228](https://github.com/GetStream/stream-chat-js/issues/1228)) ([c477fef](https://github.com/GetStream/stream-chat-js/commit/c477fef26ba7b109e8206ac46c186105ba7462f6))
* segment ts issue ([#1220](https://github.com/GetStream/stream-chat-js/issues/1220)) ([e2c385c](https://github.com/GetStream/stream-chat-js/commit/e2c385c31e4d684399b005f2b2d6354cfd6498e9))

## [8.16.0](https://github.com/GetStream/stream-chat-js/compare/v8.15.0...v8.16.0) (2024-02-05)


Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stream-chat",
"version": "8.16.0",
"version": "8.18.0",
"description": "JS SDK for the Stream Chat API",
"author": "GetStream",
"homepage": "https://getstream.io/chat/",
Expand Down Expand Up @@ -94,7 +94,7 @@
"eslint-plugin-sonarjs": "^0.6.0",
"eslint-plugin-typescript-sort-keys": "1.5.0",
"husky": "^4.3.8",
"lint-staged": "^10.5.4",
"lint-staged": "^15.2.2",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
Expand Down Expand Up @@ -124,16 +124,12 @@
"testwatch": "NODE_ENV=test nodemon ./node_modules/.bin/mocha --timeout 20000 --require test-entry.js test/test.js",
"lint": "yarn run prettier && yarn run eslint",
"lint-fix": "yarn run prettier-fix && yarn run eslint-fix",
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
"prepare": "yarn run build",
"preversion": "yarn && yarn lint && yarn test-unit",
"version": "git add yarn.lock",
"postversion": "git push && git push --tags && npm publish"
},
"husky": {
"hooks": {
"pre-commit": "yarn run lint"
}
},
"engines": {
"node": ">=16"
}
Expand Down
97 changes: 97 additions & 0 deletions src/campaign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { StreamChat } from './client';
import { APIResponse, CampaignData, DefaultGenerics, ExtendableGenerics } from './types';

export class Campaign<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
id: string | null;
data?: CampaignData;
client: StreamChat<StreamChatGenerics>;

constructor(client: StreamChat<StreamChatGenerics>, id: string | null, data?: CampaignData) {
this.client = client;
this.id = id;
this.data = data;
}

async create() {
const body = {
id: this.id,
message_template: this.data?.message_template,
segment_ids: this.data?.segment_ids,
sender_id: this.data?.sender_id,
channel_template: this.data?.channel_template,
create_channels: this.data?.create_channels,
description: this.data?.description,
name: this.data?.name,
user_ids: this.data?.user_ids,
};

const result = await this.client.createCampaign(body);

this.id = result.campaign.id;
this.data = result.campaign;
return result;
}

verifyCampaignId() {
if (!this.id) {
throw new Error(
'Campaign id is missing. Either create the campaign using campaign.create() or set the id during instantiation - const campaign = client.campaign(id)',
);
}
}

async start(scheduledFor?: string) {
this.verifyCampaignId();

return await this.client.startCampaign(this.id as string, scheduledFor);
}

async update(data: Partial<CampaignData>) {
this.verifyCampaignId();

return this.client.updateCampaign(this.id as string, data);
}

async delete() {
this.verifyCampaignId();

return await this.client.delete<APIResponse>(this.client.baseURL + `/campaigns/${this.id}`);
}

async schedule(params: { scheduledFor: number }) {
this.verifyCampaignId();

const { scheduledFor } = params;
const { campaign } = await this.client.patch<{ campaign: Campaign }>(
this.client.baseURL + `/campaigns/${this.id}/schedule`,
{
scheduled_for: scheduledFor,
},
);
return campaign;
}

async stop() {
this.verifyCampaignId();

return this.client.patch<{ campaign: Campaign }>(this.client.baseURL + `/campaigns/${this.id}/stop`);
}

async pause() {
this.verifyCampaignId();

return this.client.patch<{ campaign: Campaign }>(this.client.baseURL + `/campaigns/${this.id}/pause`);
}

async resume() {
this.verifyCampaignId();

return this.client.patch<{ campaign: Campaign }>(this.client.baseURL + `/campaigns/${this.id}/resume`);
}

async get() {
this.verifyCampaignId();

return this.client.getCampaign(this.id as string);
}
}
16 changes: 14 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,19 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
this._channelURL(),
update,
);

const areCapabilitiesChanged =
[...(data.channel.own_capabilities || [])].sort().join() !==
[...(Array.isArray(this.data?.own_capabilities) ? (this.data?.own_capabilities as string[]) : [])].sort().join();
this.data = data.channel;
// If the capabiltities are changed, we trigger the `capabilities.changed` event.
if (areCapabilitiesChanged) {
this.getClient().dispatchEvent({
type: 'capabilities.changed',
cid: this.cid,
own_capabilities: data.channel.own_capabilities,
});
}
return data;
}

Expand Down Expand Up @@ -708,7 +720,7 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
async markRead(data: MarkReadOptions<StreamChatGenerics> = {}) {
this._checkInitialized();

if (!this.getConfig()?.read_events) {
if (!this.getConfig()?.read_events && !this.getClient()._isUsingServerAuth()) {
return Promise.resolve(null);
}

Expand All @@ -726,7 +738,7 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
async markUnread(data: MarkUnreadOptions<StreamChatGenerics>) {
this._checkInitialized();

if (!this.getConfig()?.read_events) {
if (!this.getConfig()?.read_events && !this.getClient()._isUsingServerAuth()) {
return Promise.resolve(null);
}

Expand Down
Loading

0 comments on commit 8c339ec

Please sign in to comment.