Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allows filtering inbox by accountId #474

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client-graphql/src/inbox/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client } from "urql";
import { IActionElemental } from "./message";

export interface IGetInboxMessagesParams {
accountId?: string;
archived?: boolean;
from?: string | number;
limit?: number;
Expand Down
8 changes: 7 additions & 1 deletion packages/react-hooks/src/inbox/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Brand, IInboxMessagePreview } from "@trycourier/react-provider";
import {
Brand,
IInboxMessagePreview,
OnEvent,
} from "@trycourier/react-provider";
export interface IInbox<T = IInboxMessagePreview> {
accountId?: string;
brand?: Brand;
from?: number;
isLoading?: boolean;
isOpen?: boolean;
lastMarkedAllRead?: number;
lastMessagesFetched?: number;
messages?: Array<T>;
onEvent?: OnEvent;
pinned?: Array<T>;
startCursor?: string;
unreadMessageCount?: number;
Expand Down
6 changes: 5 additions & 1 deletion packages/react-hooks/src/inbox/use-inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useInboxActions, { IInboxActions } from "./use-inbox-actions";
import { IInbox } from "./types";

const useInbox = (): IInbox<IInboxMessagePreview> & IInboxActions => {
const { dispatch, inbox, transport, brand } =
const { dispatch, inbox, transport, brand, accountId } =
useCourier<{
inbox: IInbox;
}>();
Expand All @@ -22,6 +22,10 @@ const useInbox = (): IInbox<IInboxMessagePreview> & IInboxActions => {
inbox.brand = deepExtend({}, brand ?? {}, inbox.brand ?? {});
}

if (accountId) {
inbox.accountId = accountId ?? inbox.accountId;
suhasdeshpande marked this conversation as resolved.
Show resolved Hide resolved
}
suhasdeshpande marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
transport?.listen({
id: "message-listener",
Expand Down
8 changes: 6 additions & 2 deletions packages/react-inbox/src/components/Messages2.0/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const Messages: React.ForwardRefExoticComponent<
const { fetchRecipientPreferences } = usePreferences();

const {
accountId,
brand,
fetchMessages,
getUnreadMessageCount,
Expand All @@ -227,9 +228,12 @@ const Messages: React.ForwardRefExoticComponent<
}

fetchMessages({
params: currentView?.params,
params: {
...currentView?.params,
accountId,
},
});
}, [view, currentView]);
}, [accountId, view, currentView]);

useOnScroll(
messageListRef,
Expand Down
9 changes: 3 additions & 6 deletions packages/react-inbox/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Brand,
PinDetails,
IInboxMessagePreview,
EventType,
OnEvent,
} from "@trycourier/react-provider";
import { IGetInboxMessagesParams } from "@trycourier/client-graphql";

Expand Down Expand Up @@ -39,12 +39,9 @@ export interface InboxTheme {
root?: CSSObject;
unreadIndicator?: CSSObject;
}
export type OnEvent = (eventParams: {
messageId?: string;
message?: IInboxMessagePreview;
event: EventType;
}) => void;

export interface InboxProps {
accountId?: string;
brand?: Brand;
className?: string;
defaultIcon?: false | string;
Expand Down
4 changes: 4 additions & 0 deletions packages/react-provider/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import createReducer from "react-use/lib/factory/createReducer";

import {
Brand,
EventType,
ICourierContext,
ICourierProviderProps,
PinDetails,
WSOptions,
OnEvent,
} from "./types";
import { CourierTransport } from "./transports/courier";
import {
Expand Down Expand Up @@ -54,6 +56,8 @@ export type {
Middleware,
PinDetails,
WSOptions,
EventType,
OnEvent,
};

export const CourierContext =
Expand Down
2 changes: 1 addition & 1 deletion packages/react-provider/src/transports/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ICourierEventMessage {
event: "read" | "unread" | "archive" | "mark-all-read" | "opened";
event: "read" | "unread" | "archive" | "mark-all-read" | "opened" | "unpin";
suhasdeshpande marked this conversation as resolved.
Show resolved Hide resolved
type: "event";
messageId?: string;
error?: string;
Expand Down
8 changes: 7 additions & 1 deletion packages/react-provider/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CourierTransport, Transport } from "./transports";
import { Interceptor } from "./transports/types";
import { IInboxMessagePreview, Interceptor } from "./transports/types";
import { ErrorEvent } from "reconnecting-websocket";
export { IInboxMessagePreview } from "@trycourier/client-graphql";

Expand All @@ -14,6 +14,12 @@ export type WSOptions = {
connectionTimeout?: number;
};

export type OnEvent = (eventParams: {
messageId?: string;
message?: IInboxMessagePreview;
event: EventType;
}) => void;

export interface PinDetails {
id: string;
label: {
Expand Down
5 changes: 5 additions & 0 deletions packages/react-provider/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class WS {
event?: string;
callback: ICourierEventCallback;
}>;
private accountId?: string;
private clientSourceId?: string;
private authorization?: string;
private clientKey?: string;
Expand All @@ -31,18 +32,21 @@ export class WS {
protected messageCallback;

constructor({
accountId,
authorization,
clientKey,
options,
clientSourceId,
userSignature,
}: {
accountId?: string;
authorization?: string;
clientSourceId?: string;
clientKey?: string;
options?: WSOptions;
userSignature?: string;
}) {
this.accountId = accountId;
this.connectionCount = 0;
this.authorization = authorization;
this.messageCallback = null;
Expand Down Expand Up @@ -173,6 +177,7 @@ export class WS {
this.send({
action: "subscribe",
data: {
accountId: this.accountId,
channel,
clientKey: this.clientKey,
clientSourceId: this.clientSourceId,
Expand Down