Skip to content

Commit

Permalink
Merge pull request novuhq#5021 from vichustephen/headless_api_issue_fix
Browse files Browse the repository at this point in the history
fix: headless api client remove/refetch query scenarios
  • Loading branch information
jainpawan21 authored Jan 5, 2024
2 parents 1f1f78f + f0575c5 commit 4bdb723
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/headless/src/lib/headless.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ describe('headless.service', () => {
});
await promiseResolveTimeout(0);

expect(mockServiceInstance.getNotificationsList).toBeCalledTimes(2);
expect(notificationsListener).toHaveBeenCalledTimes(4);
expect(mockServiceInstance.getNotificationsList).toBeCalledTimes(3);
expect(notificationsListener).toHaveBeenCalledTimes(8);
expect(notificationsListener).toHaveBeenNthCalledWith(
4,
expect.objectContaining({
Expand Down Expand Up @@ -673,7 +673,7 @@ describe('headless.service', () => {
await promiseResolveTimeout(0);

expect(mockServiceInstance.getNotificationsList).toBeCalledTimes(2);
expect(notificationsListener).toHaveBeenCalledTimes(4);
expect(notificationsListener).toHaveBeenCalledTimes(6);
expect(notificationsListener).toHaveBeenNthCalledWith(
4,
expect.objectContaining({
Expand Down Expand Up @@ -769,7 +769,7 @@ describe('headless.service', () => {
await promiseResolveTimeout(0);

expect(mockServiceInstance.getNotificationsList).toBeCalledTimes(2);
expect(notificationsListener).toHaveBeenCalledTimes(4);
expect(notificationsListener).toHaveBeenCalledTimes(6);
expect(notificationsListener).toHaveBeenNthCalledWith(
4,
expect.objectContaining({
Expand Down
12 changes: 3 additions & 9 deletions packages/headless/src/lib/headless.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class HeadlessService {
WebSocketEventEnum.RECEIVED,
(data?: { message: IMessage }) => {
if (data?.message) {
this.queryClient.removeQueries(NOTIFICATIONS_QUERY_KEY, {
this.queryClient.refetchQueries(NOTIFICATIONS_QUERY_KEY, {
exact: false,
});
listener(data.message);
Expand Down Expand Up @@ -365,9 +365,6 @@ export class HeadlessService {
WebSocketEventEnum.UNSEEN,
(data?: { unseenCount: number }) => {
if (Number.isInteger(data?.unseenCount)) {
this.queryClient.removeQueries(NOTIFICATIONS_QUERY_KEY, {
exact: false,
});
this.queryClient.setQueryData<{ count: number }>(
UNSEEN_COUNT_QUERY_KEY,
(oldData) => ({ count: data?.unseenCount ?? oldData.count })
Expand Down Expand Up @@ -397,9 +394,6 @@ export class HeadlessService {
WebSocketEventEnum.UNREAD,
(data?: { unreadCount: number }) => {
if (Number.isInteger(data?.unreadCount)) {
this.queryClient.removeQueries(NOTIFICATIONS_QUERY_KEY, {
exact: false,
});
this.queryClient.setQueryData<{ count: number }>(
UNREAD_COUNT_QUERY_KEY,
(oldData) => ({ count: data?.unreadCount ?? oldData.count })
Expand Down Expand Up @@ -789,7 +783,7 @@ export class HeadlessService {
options: {
mutationFn: (variables) => this.api.removeMessage(variables.messageId),
onSuccess: (data) => {
this.queryClient.removeQueries(NOTIFICATIONS_QUERY_KEY, {
this.queryClient.refetchQueries(NOTIFICATIONS_QUERY_KEY, {
exact: false,
});
},
Expand Down Expand Up @@ -982,7 +976,7 @@ export class HeadlessService {
mutationFn: (variables) =>
this.api.removeAllMessages(variables?.feedId),
onSuccess: (data) => {
this.queryClient.refetchQueries(NOTIFICATIONS_QUERY_KEY, {
this.queryClient.removeQueries(NOTIFICATIONS_QUERY_KEY, {
exact: false,
});
},
Expand Down

0 comments on commit 4bdb723

Please sign in to comment.