@planningcenter/chat-react-native 3.31.0 → 3.31.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,7 +65,7 @@ export const findConversationWithExactTeams = (apiClient, groupIdentifiers) => {
65
65
  url: '/me/conversations',
66
66
  data: {
67
67
  fields: {
68
- Conversation: ['stream_channel', 'title'],
68
+ Conversation: ['title'],
69
69
  },
70
70
  filter: 'with_exact_groups',
71
71
  gids: groupIdentifiers.join(','),
@@ -85,7 +85,7 @@ export const findExactTeamConversation = (apiClient, groupIdentifiers) => {
85
85
  url: '/me/conversations',
86
86
  data: {
87
87
  fields: {
88
- Conversation: ['stream_channel', 'title'],
88
+ Conversation: ['title'],
89
89
  },
90
90
  filter: 'with_exact_groups',
91
91
  gids: groupIdentifiers.join(','),
@@ -1 +1 @@
1
- {"version":3,"file":"use_find_or_create_services_conversation.js","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAQ/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAa,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAa3D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAS,EAAE,EAAE;IAC3F,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,iBAAiB,GAAsB,OAAO,CAClD,GAAG,EAAE,CACH,MAAM,CACJ;QACE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI;QACnC,OAAO,EAAE,MAAM;KAChB,EACD,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UAAoB,EAAE,EAAE,MAAe,EAAE,EAAE;IAChF,OAAO,MAAM,CACX;QACE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1B,OAAO,EAAE,MAAM;KAChB,EACD,KAAK,CACN,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { useMutation, useQuery } from '@tanstack/react-query'\nimport { omitBy, isNil } from 'lodash'\nimport { useMemo } from 'react'\nimport {\n ApiCollection,\n ApiResource,\n ConversationResource,\n ServicesChatGroupIdentifiersResource,\n ServicesChatPayloadResource,\n} from '../../types'\nimport { throwResponseError } from '../../utils/response_error'\nimport { ApiClient, useApiClient } from '../use_api_client'\n\ninterface Props {\n teamIds?: number[]\n planId?: number\n onSuccess?: (conversation: ConversationResource) => void\n}\n\ninterface TeamAndPlanParams {\n team_id?: string | null\n plan_id?: number\n}\n\nexport const useFindOrCreateServicesConversation = ({ teamIds, planId, onSuccess }: Props) => {\n const apiClient = useApiClient()\n\n const teamAndPlanParams: TeamAndPlanParams = useMemo(\n () =>\n omitBy(\n {\n team_id: teamIds?.join(',') || null,\n plan_id: planId,\n },\n isNil\n ),\n [teamIds, planId]\n )\n\n const { data: selectionHasConversation = false, isLoading: isLoadingConversationCheck } =\n useQuery({\n queryKey: ['conversation-with-group-exists', teamAndPlanParams],\n queryFn: () => checkIfConversationWithGroupExists(apiClient, teamAndPlanParams),\n enabled: !!(teamIds?.length || planId),\n })\n\n const mutation = useMutation({\n throwOnError: true,\n onSuccess: result => {\n onSuccess && onSuccess(result)\n },\n mutationFn: async () => findOrCreateServicesConversation(apiClient, teamAndPlanParams),\n })\n\n return { ...mutation, selectionHasConversation, isLoadingConversationCheck }\n}\n\nexport const findOrCreateServicesConversation = async (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n const foundConversations = await getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findConversationWithExactTeams(apiClient, groupIdentifiers))\n .catch(() => null)\n const foundConversation = foundConversations?.data[0]\n\n if (foundConversation?.id) {\n return foundConversation\n }\n\n return fetchServicesPayload(apiClient, teamAndPlanParams)\n .then(res => res.data.payload)\n .then(payload => createConversation(apiClient, payload))\n .then(res => res.data)\n .catch(throwResponseError)\n}\n\nexport const fetchServicesPayload = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return apiClient.services.get({\n url: `/chat`,\n data: {\n ...teamAndPlanParams,\n fields: {\n Chat: ['payload'],\n },\n },\n }) as Promise<ApiResource<ServicesChatPayloadResource>>\n}\n\nexport const getGroupIdsFromServices = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return apiClient.services.get({\n url: '/chat',\n data: {\n ...teamAndPlanParams,\n fields: {\n Chat: ['group_identifiers'],\n },\n },\n }) as Promise<ApiResource<ServicesChatGroupIdentifiersResource>>\n}\n\nexport const findConversationWithExactTeams = (\n apiClient: ApiClient,\n groupIdentifiers: string[]\n) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['stream_channel', 'title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const createConversation = (apiClient: ApiClient, payload: string) => {\n return apiClient.chat.post({\n url: '/me/conversations',\n data: {\n data: { type: 'Conversation', attributes: { payload } },\n },\n }) as Promise<ApiResource<ConversationResource>>\n}\n\nexport const findExactTeamConversation = (apiClient: ApiClient, groupIdentifiers: string[]) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['stream_channel', 'title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const checkIfConversationWithGroupExists = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findExactTeamConversation(apiClient, groupIdentifiers))\n .then(response => response.data.length > 0)\n}\n\nexport const buildTeamAndPlanParams = (teamIds: number[] = [], planId?: number) => {\n return omitBy(\n {\n team_id: teamIds.join(','),\n plan_id: planId,\n },\n isNil\n )\n}\n"]}
1
+ {"version":3,"file":"use_find_or_create_services_conversation.js","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAQ/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAa,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAa3D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAS,EAAE,EAAE;IAC3F,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,iBAAiB,GAAsB,OAAO,CAClD,GAAG,EAAE,CACH,MAAM,CACJ;QACE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI;QACnC,OAAO,EAAE,MAAM;KAChB,EACD,KAAK,CACN,EACH,CAAC,OAAO,EAAE,MAAM,CAAC,CAClB,CAAA;IAED,MAAM,EAAE,IAAI,EAAE,wBAAwB,GAAG,KAAK,EAAE,SAAS,EAAE,0BAA0B,EAAE,GACrF,QAAQ,CAAC;QACP,QAAQ,EAAE,CAAC,gCAAgC,EAAE,iBAAiB,CAAC;QAC/D,OAAO,EAAE,GAAG,EAAE,CAAC,kCAAkC,CAAC,SAAS,EAAE,iBAAiB,CAAC;QAC/E,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,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;SACxD;KACF,CAA+C,CAAA;AAClD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,SAAoB,EAAE,gBAA0B,EAAE,EAAE;IAC5F,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;QACxB,GAAG,EAAE,mBAAmB;QACxB,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,YAAY,EAAE,CAAC,OAAO,CAAC;aACxB;YACD,MAAM,EAAE,mBAAmB;YAC3B,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;SACjC;KACF,CAAiD,CAAA;AACpD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,SAAoB,EACpB,iBAAoC,EACpC,EAAE;IACF,OAAO,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,CAAC;SACzD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;SACtC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,yBAAyB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;SAChF,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,UAAoB,EAAE,EAAE,MAAe,EAAE,EAAE;IAChF,OAAO,MAAM,CACX;QACE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1B,OAAO,EAAE,MAAM;KAChB,EACD,KAAK,CACN,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { useMutation, useQuery } from '@tanstack/react-query'\nimport { omitBy, isNil } from 'lodash'\nimport { useMemo } from 'react'\nimport {\n ApiCollection,\n ApiResource,\n ConversationResource,\n ServicesChatGroupIdentifiersResource,\n ServicesChatPayloadResource,\n} from '../../types'\nimport { throwResponseError } from '../../utils/response_error'\nimport { ApiClient, useApiClient } from '../use_api_client'\n\ninterface Props {\n teamIds?: number[]\n planId?: number\n onSuccess?: (conversation: ConversationResource) => void\n}\n\ninterface TeamAndPlanParams {\n team_id?: string | null\n plan_id?: number\n}\n\nexport const useFindOrCreateServicesConversation = ({ teamIds, planId, onSuccess }: Props) => {\n const apiClient = useApiClient()\n\n const teamAndPlanParams: TeamAndPlanParams = useMemo(\n () =>\n omitBy(\n {\n team_id: teamIds?.join(',') || null,\n plan_id: planId,\n },\n isNil\n ),\n [teamIds, planId]\n )\n\n const { data: selectionHasConversation = false, isLoading: isLoadingConversationCheck } =\n useQuery({\n queryKey: ['conversation-with-group-exists', teamAndPlanParams],\n queryFn: () => checkIfConversationWithGroupExists(apiClient, teamAndPlanParams),\n enabled: !!(teamIds?.length || planId),\n })\n\n const mutation = useMutation({\n throwOnError: true,\n onSuccess: result => {\n onSuccess && onSuccess(result)\n },\n mutationFn: async () => findOrCreateServicesConversation(apiClient, teamAndPlanParams),\n })\n\n return { ...mutation, selectionHasConversation, isLoadingConversationCheck }\n}\n\nexport const findOrCreateServicesConversation = async (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n const foundConversations = await getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findConversationWithExactTeams(apiClient, groupIdentifiers))\n .catch(() => null)\n const foundConversation = foundConversations?.data[0]\n\n if (foundConversation?.id) {\n return foundConversation\n }\n\n return fetchServicesPayload(apiClient, teamAndPlanParams)\n .then(res => res.data.payload)\n .then(payload => createConversation(apiClient, payload))\n .then(res => res.data)\n .catch(throwResponseError)\n}\n\nexport const fetchServicesPayload = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return apiClient.services.get({\n url: `/chat`,\n data: {\n ...teamAndPlanParams,\n fields: {\n Chat: ['payload'],\n },\n },\n }) as Promise<ApiResource<ServicesChatPayloadResource>>\n}\n\nexport const getGroupIdsFromServices = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return apiClient.services.get({\n url: '/chat',\n data: {\n ...teamAndPlanParams,\n fields: {\n Chat: ['group_identifiers'],\n },\n },\n }) as Promise<ApiResource<ServicesChatGroupIdentifiersResource>>\n}\n\nexport const findConversationWithExactTeams = (\n apiClient: ApiClient,\n groupIdentifiers: string[]\n) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const createConversation = (apiClient: ApiClient, payload: string) => {\n return apiClient.chat.post({\n url: '/me/conversations',\n data: {\n data: { type: 'Conversation', attributes: { payload } },\n },\n }) as Promise<ApiResource<ConversationResource>>\n}\n\nexport const findExactTeamConversation = (apiClient: ApiClient, groupIdentifiers: string[]) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const checkIfConversationWithGroupExists = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findExactTeamConversation(apiClient, groupIdentifiers))\n .then(response => response.data.length > 0)\n}\n\nexport const buildTeamAndPlanParams = (teamIds: number[] = [], planId?: number) => {\n return omitBy(\n {\n team_id: teamIds.join(','),\n plan_id: planId,\n },\n isNil\n )\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/chat-react-native",
3
- "version": "3.31.0",
3
+ "version": "3.31.1-rc.0",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -64,5 +64,5 @@
64
64
  "react-native-url-polyfill": "^2.0.0",
65
65
  "typescript": "<5.6.0"
66
66
  },
67
- "gitHead": "9f8030f650386f929d466fe2fb7f4c8b060eda18"
67
+ "gitHead": "cff503cd0a7f12f9151acbc45abc582fff9c513f"
68
68
  }
@@ -114,7 +114,7 @@ export const findConversationWithExactTeams = (
114
114
  url: '/me/conversations',
115
115
  data: {
116
116
  fields: {
117
- Conversation: ['stream_channel', 'title'],
117
+ Conversation: ['title'],
118
118
  },
119
119
  filter: 'with_exact_groups',
120
120
  gids: groupIdentifiers.join(','),
@@ -136,7 +136,7 @@ export const findExactTeamConversation = (apiClient: ApiClient, groupIdentifiers
136
136
  url: '/me/conversations',
137
137
  data: {
138
138
  fields: {
139
- Conversation: ['stream_channel', 'title'],
139
+ Conversation: ['title'],
140
140
  },
141
141
  filter: 'with_exact_groups',
142
142
  gids: groupIdentifiers.join(','),