Skip to content

Commit 769108c

Browse files
committed
Merge remote-tracking branch 'origin/feat/message-composer' into feat/message-composer
2 parents fa3c4fd + 1ce05a8 commit 769108c

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

src/client.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,21 @@ import type {
230230
import { ChannelManager } from './channel_manager';
231231
import { NotificationManager } from './notifications';
232232
import { StateStore } from './store';
233-
import type { MessageComposerOptions } from './messageComposer';
234-
import { MessageComposer } from './messageComposer';
233+
import type { MessageComposer } from './messageComposer';
235234

236235
function isString(x: unknown): x is string {
237236
return typeof x === 'string' || x instanceof String;
238237
}
239238

240-
type MessageComposerDefine = ({
241-
constructorParameters,
242-
}: {
243-
constructorParameters: MessageComposerOptions;
244-
}) => MessageComposer;
239+
type MessageComposerTearDownFunction = () => void;
245240

246-
type MessageComposerApplyModifications = ({
241+
type MessageComposerSetupFunction = ({
247242
composer,
248243
}: {
249244
composer: MessageComposer;
250-
}) => void | (() => void);
245+
}) => void | MessageComposerTearDownFunction;
251246

252-
// TODO: maybe template modifications
253-
// { template1: { applyModifications... }, template2: {applyModifications} }
254-
// new MessageComposer({ channel, modificationTemplate: 'template1' })
255247
type MessageComposerSetupState = {
256-
define: MessageComposerDefine;
257248
/**
258249
* Each `MessageComposer` runs this function each time its signature changes or
259250
* whenever you run `MessageComposer.registerSubscriptions`. Function returned
@@ -262,12 +253,7 @@ type MessageComposerSetupState = {
262253
* modified parts is the general way to go but if your setup gets a bit
263254
* complicated, feel free to restore the whole composer with `MessageComposer.restore`.
264255
*/
265-
applyModifications: MessageComposerApplyModifications | null;
266-
};
267-
268-
const INITIAL_MESSAGE_COMPOSER_SETUP_STATE: MessageComposerSetupState = {
269-
define: ({ constructorParameters }) => new MessageComposer(constructorParameters),
270-
applyModifications: null,
256+
setupFunction: MessageComposerSetupFunction | null;
271257
};
272258

273259
export class StreamChat {
@@ -325,8 +311,12 @@ export class StreamChat {
325311
sdkIdentifier?: SdkIdentifier;
326312
deviceIdentifier?: DeviceIdentifier;
327313
private nextRequestAbortController: AbortController | null = null;
328-
public _messageComposerSetupState: StateStore<MessageComposerSetupState> =
329-
new StateStore(INITIAL_MESSAGE_COMPOSER_SETUP_STATE);
314+
/**
315+
* @private
316+
*/
317+
_messageComposerSetupState = new StateStore<MessageComposerSetupState>({
318+
setupFunction: null,
319+
});
330320

331321
/**
332322
* Initialize a client
@@ -4397,13 +4387,9 @@ export class StreamChat {
43974387
return await this.post<QueryDraftsResponse>(this.baseURL + '/drafts/query', payload);
43984388
}
43994389

4400-
// TODO: this might not be needed
4401-
public createMessageComposer: MessageComposerDefine = (setup) =>
4402-
this._messageComposerSetupState.getLatestValue().define(setup);
4403-
4404-
public setMessageComposerApplyModifications = (
4405-
applyModifications: MessageComposerSetupState['applyModifications'],
4390+
public setMessageComposerSetupFunction = (
4391+
setupFunction: MessageComposerSetupState['setupFunction'],
44064392
) => {
4407-
this._messageComposerSetupState.partialNext({ applyModifications });
4393+
this._messageComposerSetupState.partialNext({ setupFunction });
44084394
};
44094395
}

src/messageComposer/messageComposer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,19 +425,19 @@ export class MessageComposer {
425425
};
426426

427427
private subscribeMessageComposerSetupStateChange = () => {
428-
let cleanupBefore: (() => void) | null = null;
428+
let tearDown: (() => void) | null = null;
429429
const unsubscribe = this.client._messageComposerSetupState.subscribeWithSelector(
430-
({ applyModifications }) => ({
431-
applyModifications,
430+
({ setupFunction: setup }) => ({
431+
setup,
432432
}),
433-
({ applyModifications }) => {
434-
cleanupBefore?.();
435-
cleanupBefore = applyModifications?.({ composer: this }) ?? null;
433+
({ setup }) => {
434+
tearDown?.();
435+
tearDown = setup?.({ composer: this }) ?? null;
436436
},
437437
);
438438

439439
return () => {
440-
cleanupBefore?.();
440+
tearDown?.();
441441
unsubscribe();
442442
};
443443
};

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export type ChannelMemberUpdates = CustomMemberData & {
341341
};
342342

343343
export type ChannelMemberResponse = CustomMemberData & {
344-
archived_at?: string;
344+
archived_at?: string | null;
345345
ban_expires?: string;
346346
banned?: boolean;
347347
channel_role?: Role;
@@ -351,7 +351,7 @@ export type ChannelMemberResponse = CustomMemberData & {
351351
invited?: boolean;
352352
is_moderator?: boolean;
353353
notifications_muted?: boolean;
354-
pinned_at?: string;
354+
pinned_at?: string | null;
355355
role?: string;
356356
shadow_banned?: boolean;
357357
status?: InviteStatus;

0 commit comments

Comments
 (0)