Skip to content

Commit 384d68b

Browse files
committed
fix: Mark read channel if shouldMarkActiveChannelAsRead switched on
1 parent b041d93 commit 384d68b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

projects/stream-chat-angular/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"rules": {
5656
"jsdoc/require-param-type": 0,
5757
"jsdoc/require-returns-type": 0,
58+
"jsdoc/require-returns": 0,
5859
"jsdoc/newline-after-description": 0,
5960
"jsdoc/require-param-description": 0,
6061
"jsdoc/require-param": 2,

projects/stream-chat-angular/src/lib/channel.service.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ describe('ChannelService', () => {
367367
service.setAsActiveChannel(activeChannel);
368368

369369
expect(activeChannel.markRead).not.toHaveBeenCalledWith();
370+
371+
service.shouldMarkActiveChannelAsRead = true;
372+
373+
expect(activeChannel.markRead).toHaveBeenCalledWith();
370374
});
371375

372376
it(`shouldn't make "markRead" call, if user dosen't have 'read-events' capability`, async () => {

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ export class ChannelService<
224224
url: string,
225225
channel: Channel<T>
226226
) => Promise<void>;
227-
/**
228-
* If set to false, read events won't be sent as new messages are received
229-
*/
230-
shouldMarkActiveChannelAsRead = true;
231227
private channelsSubject = new BehaviorSubject<Channel<T>[] | undefined>(
232228
undefined
233229
);
@@ -261,6 +257,7 @@ export class ChannelService<
261257
private usersTypingInThreadSubject = new BehaviorSubject<UserResponse<T>[]>(
262258
[]
263259
);
260+
private _shouldMarkActiveChannelAsRead = true;
264261

265262
private channelListSetter = (
266263
channels: (Channel<T> | ChannelResponse<T>)[]
@@ -349,6 +346,23 @@ export class ChannelService<
349346
this.latestMessageDateByUserByChannelsSubject.asObservable();
350347
}
351348

349+
/**
350+
* If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.
351+
*/
352+
get shouldMarkActiveChannelAsRead() {
353+
return this._shouldMarkActiveChannelAsRead;
354+
}
355+
356+
/**
357+
* If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.
358+
*/
359+
set shouldMarkActiveChannelAsRead(shouldMarkActiveChannelAsRead: boolean) {
360+
if (!this._shouldMarkActiveChannelAsRead && shouldMarkActiveChannelAsRead) {
361+
this.activeChannelSubject.getValue()?.markRead();
362+
}
363+
this._shouldMarkActiveChannelAsRead = shouldMarkActiveChannelAsRead;
364+
}
365+
352366
/**
353367
* Sets the given `channel` as active and marks it as read.
354368
* @param channel

0 commit comments

Comments
 (0)