@adminide-stack/yantra-mobile 12.0.69-alpha.4 → 12.0.69-alpha.6
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.
- package/lib/features/messaging/chatOperations.js.map +1 -1
- package/lib/features/messaging/chatRegistrationStorage.js +4 -1
- package/lib/features/messaging/chatRegistrationStorage.js.map +1 -1
- package/lib/features/messaging/useYantraChatMembership.js +9 -6
- package/lib/features/messaging/useYantraChatMembership.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatOperations.js","sources":["../../../src/features/messaging/chatOperations.ts"],"sourcesContent":["/**\n * Every GraphQL operation the chat remote sends, as plain strings.\n *\n * Strings, not `gql` documents, because the remote must not import\n * @apollo/client or graphql - the host parses and executes these on the app's\n * own client (see `ChatGraphQLSeam`). The upside beyond bundle size is that the\n * QUERY SHAPE ships over the air: a missing field or a wrong argument is a\n * surface deploy, not an App Store release.\n *\n * HARD REQUIREMENT - every operation is NAMED, and every subscription's name\n * ends in `_WS`. `portable-devices/mobile/src/config/base-apollo-client.ts`\n * routes ws-vs-http with `operationName.endsWith('_WS')`; an anonymous\n * operation makes that `undefined.endsWith(...)`, which throws for EVERY\n * operation the app sends, not just this one. `chatOperations.test.ts` asserts\n * both properties over every export in this file, so a new operation cannot\n * quietly break the app's transport.\n */\n\n/**\n * Shared field set for a message.\n *\n * `author` and `creator` are both selected on purpose: messenger-box populates\n * `author` on some write paths and `creator` on others (`sendMessage` sets\n * creator), and a transcript that reads only one shows \"Unknown\" for half the\n * messages. `chatModel.pickAuthor` collapses them.\n */\nexport const POST_FIELDS = `\n id\n message\n type\n createdAt\n updatedAt\n editedAt\n deletedAt\n rootId\n parentId\n filenames\n props\n author { id givenName familyName username email picture }\n creator { id givenName familyName username email picture }\n`;\n\nconst CHANNEL_FIELDS = `\n id\n type\n orgName\n title\n displayName\n topic\n lastPostAt\n totalMsgCount\n createdAt\n lastMessage { ${POST_FIELDS} }\n creator { id givenName familyName username email picture }\n members { id user { id givenName familyName username email picture } msgCount lastViewedAt }\n`;\n\n/**\n * The conversation list.\n *\n * `criteria.members.$elemMatch.user` is NOT sent: the server derives membership\n * from the session (`accountId`) and a client-supplied member filter is exactly\n * the kind of thing that lets a caller read someone else's list. Org scoping is\n * likewise server-side now (`channelOrgScope`). Native Messages passes\n * `criteria: { type: DIRECT, orgName: yantra-chat }` via `nativeChatChannelQuery`.\n */\nexport const CHANNELS_QUERY = `\n query ChatChannels($limit: Int, $skip: Int, $criteria: AnyObject, $sort: Sort) {\n channelsByUser(limit: $limit, skip: $skip, criteria: $criteria, sort: $sort) {\n ${CHANNEL_FIELDS}\n }\n }\n`;\n\n/**\n * One page of a transcript, newest first.\n *\n * Paged with `skip`, which is what the server exposes. That is offset paging and\n * it can repeat or drop a row if messages arrive mid-scroll; `chatModel.mergePosts`\n * de-duplicates by id so the visible effect is bounded. A cursor (`before: id`)\n * would be strictly better and is worth adding server-side later.\n */\nexport const MESSAGES_QUERY = `\n query ChatMessages($channelId: ID, $limit: Int! = 30, $skip: Int! = 0, $sort: Sort) {\n messages(channelId: $channelId, limit: $limit, skip: $skip, sort: $sort) {\n totalCount\n data {\n ${POST_FIELDS}\n }\n }\n }\n`;\n\nexport const SEND_MESSAGE_MUTATION = `\n mutation ChatSendMessage($channelId: String!, $messageInput: MessageInput!) {\n sendMessage(channelId: $channelId, messageInput: $messageInput) {\n ${POST_FIELDS}\n }\n }\n`;\n\n/** Marks the channel read for the caller; drives the unread badge to zero. */\nexport const VIEW_CHANNEL_MUTATION = `\n mutation ChatViewChannel($id: ID!) {\n viewChannel(id: $id)\n }\n`;\n\n/**\n * Opens (or returns) the 1:1 conversation with `receiver`.\n *\n * Idempotent server-side: an existing DM for the pair comes back rather than a\n * duplicate, so the UI can call this every time someone taps a contact without\n * checking first.\n */\nexport const CREATE_DIRECT_CHANNEL_MUTATION = `\n mutation ChatCreateDirectChannel($receiver: [ID]!, $displayName: String!) {\n createDirectChannel(receiver: $receiver, displayName: $displayName) {\n ${CHANNEL_FIELDS}\n }\n }\n`;\n\n/**\n * Live messages for one channel.\n *\n * `_WS` suffix is load-bearing - see the file header. `directTo` is left unset:\n * the server treats it as a second, user-scoped topic and passing the wrong one\n * silently delivers nothing.\n */\nexport const MESSAGE_ADDED_SUBSCRIPTION_WS = `\n subscription ChatMessageAdded_WS($channelId: String) {\n chatMessageAdded(channelId: $channelId) {\n ${POST_FIELDS}\n }\n }\n`;\n\n/**\n * Which of these phone numbers already have an account.\n *\n * Sends SHA-256 hashes of E.164 numbers, never the numbers - the server never\n * receives a plaintext address book. Returns AnyObject: a list of\n * `{phoneHash, userId, username, displayName, picture}`.\n */\nexport const CONTACT_MATCHES_QUERY = `\n query ChatContactMatches($phoneHashes: [String!]!) {\n chatContactMatches(phoneHashes: $phoneHashes)\n }\n`;\n\nexport const YANTRA_CHAT_REGISTRATION_STATUS_QUERY = `\n query YantraChatRegistrationStatus {\n yantraChatRegistrationStatus {\n registered\n phoneE164\n memberId\n organizationId\n }\n }\n`;\n\nexport const REGISTER_YANTRA_CHAT_MEMBER_MUTATION = `\n mutation RegisterYantraChatMember($phoneE164: String!, $displayName: String) {\n registerYantraChatMember(phoneE164: $phoneE164, displayName: $displayName) {\n registered\n phoneE164\n memberId\n organizationId\n }\n }\n`;\n\nexport const MATCH_YANTRA_CHAT_MEMBERS_QUERY = `\n query MatchYantraChatMembersByPhone($phones: [String!]!, $viewerPhoneE164: String) {\n matchYantraChatMembersByPhone(phones: $phones, viewerPhoneE164: $viewerPhoneE164) {\n phoneE164\n userId\n displayName\n avatarUrl\n }\n }\n`;\n\nexport const YANTRA_CHAT_MEMBERS_QUERY = `\n query YantraChatMembers {\n yantraChatMembers {\n phoneE164\n userId\n displayName\n avatarUrl\n }\n }\n`;\n\n/** Composer draft persistence, server-side and per (member, channel). */\nexport const SET_DRAFT_MUTATION = `\n mutation ChatSetDraft($channelId: ID!, $text: String!) {\n setChannelDraft(channelId: $channelId, text: $text)\n }\n`;\n\nexport const DRAFT_QUERY = `\n query ChatDraft($channelId: ID!) {\n channelDraft(channelId: $channelId)\n }\n`;\n\n/** Every operation, for the contract test and for host-side preflight. */\nexport const CHAT_OPERATIONS: Readonly<Record<string, string>> = Object.freeze({\n CHANNELS_QUERY,\n CONTACT_MATCHES_QUERY,\n YANTRA_CHAT_REGISTRATION_STATUS_QUERY,\n REGISTER_YANTRA_CHAT_MEMBER_MUTATION,\n MATCH_YANTRA_CHAT_MEMBERS_QUERY,\n YANTRA_CHAT_MEMBERS_QUERY,\n MESSAGES_QUERY,\n SEND_MESSAGE_MUTATION,\n VIEW_CHANNEL_MUTATION,\n CREATE_DIRECT_CHANNEL_MUTATION,\n MESSAGE_ADDED_SUBSCRIPTION_WS,\n SET_DRAFT_MUTATION,\n DRAFT_QUERY,\n});\n\n/**\n * The operation name inside a document string.\n *\n * Used by the contract test and by the host seam for logging. Intentionally a\n * regex rather than a parse: pulling in `graphql` to read a name would defeat\n * the whole point of shipping strings.\n */\nexport function operationNameOf(document: string): string | null {\n const match = /\\b(?:query|mutation|subscription)\\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(document);\n return match ? match[1] : null;\n}\n\nexport function operationTypeOf(document: string): 'query' | 'mutation' | 'subscription' | null {\n const match = /\\b(query|mutation|subscription)\\s+[A-Za-z_]/.exec(document);\n return match ? (match[1] as 'query' | 'mutation' | 'subscription') : null;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chatOperations.js","sources":["../../../src/features/messaging/chatOperations.ts"],"sourcesContent":["/**\n * Every GraphQL operation the chat remote sends, as plain strings.\n *\n * Strings, not `gql` documents, because the remote must not import\n * @apollo/client or graphql - the host parses and executes these on the app's\n * own client (see `ChatGraphQLSeam`). The upside beyond bundle size is that the\n * QUERY SHAPE ships over the air: a missing field or a wrong argument is a\n * surface deploy, not an App Store release.\n *\n * HARD REQUIREMENT - every operation is NAMED, and every subscription's name\n * ends in `_WS`. `portable-devices/mobile/src/config/base-apollo-client.ts`\n * routes ws-vs-http with `operationName.endsWith('_WS')`; an anonymous\n * operation makes that `undefined.endsWith(...)`, which throws for EVERY\n * operation the app sends, not just this one. `chatOperations.test.ts` asserts\n * both properties over every export in this file, so a new operation cannot\n * quietly break the app's transport.\n */\n\n/**\n * Shared field set for a message.\n *\n * `author` and `creator` are both selected on purpose: messenger-box populates\n * `author` on some write paths and `creator` on others (`sendMessage` sets\n * creator), and a transcript that reads only one shows \"Unknown\" for half the\n * messages. `chatModel.pickAuthor` collapses them.\n */\nexport const POST_FIELDS = `\n id\n message\n type\n createdAt\n updatedAt\n editedAt\n deletedAt\n rootId\n parentId\n filenames\n props\n author { id givenName familyName username email picture }\n creator { id givenName familyName username email picture }\n reactionSummary { reaction count userIds }\n`;\n\nconst CHANNEL_FIELDS = `\n id\n type\n orgName\n title\n displayName\n topic\n lastPostAt\n totalMsgCount\n createdAt\n lastMessage { ${POST_FIELDS} }\n creator { id givenName familyName username email picture }\n members { id user { id givenName familyName username email picture } msgCount lastViewedAt }\n`;\n\n/**\n * The conversation list.\n *\n * `criteria.members.$elemMatch.user` is NOT sent: the server derives membership\n * from the session (`accountId`) and a client-supplied member filter is exactly\n * the kind of thing that lets a caller read someone else's list. Org scoping is\n * likewise server-side now (`channelOrgScope`). Native Messages passes\n * `criteria: { type: DIRECT, orgName: yantra-chat }` via `nativeChatChannelQuery`.\n */\nexport const CHANNELS_QUERY = `\n query ChatChannels($limit: Int, $skip: Int, $criteria: AnyObject, $sort: Sort) {\n channelsByUser(limit: $limit, skip: $skip, criteria: $criteria, sort: $sort) {\n ${CHANNEL_FIELDS}\n }\n }\n`;\n\n/**\n * One page of a transcript, newest first.\n *\n * Paged with `skip`, which is what the server exposes. That is offset paging and\n * it can repeat or drop a row if messages arrive mid-scroll; `chatModel.mergePosts`\n * de-duplicates by id so the visible effect is bounded. A cursor (`before: id`)\n * would be strictly better and is worth adding server-side later.\n */\nexport const MESSAGES_QUERY = `\n query ChatMessages($channelId: ID, $limit: Int! = 30, $skip: Int! = 0, $sort: Sort) {\n messages(channelId: $channelId, limit: $limit, skip: $skip, sort: $sort) {\n totalCount\n data {\n ${POST_FIELDS}\n }\n }\n }\n`;\n\nexport const SEND_MESSAGE_MUTATION = `\n mutation ChatSendMessage($channelId: String!, $messageInput: MessageInput!) {\n sendMessage(channelId: $channelId, messageInput: $messageInput) {\n ${POST_FIELDS}\n }\n }\n`;\n\n/** Marks the channel read for the caller; drives the unread badge to zero. */\nexport const VIEW_CHANNEL_MUTATION = `\n mutation ChatViewChannel($id: ID!) {\n viewChannel(id: $id)\n }\n`;\n\n/**\n * Opens (or returns) the 1:1 conversation with `receiver`.\n *\n * Idempotent server-side: an existing DM for the pair comes back rather than a\n * duplicate, so the UI can call this every time someone taps a contact without\n * checking first.\n */\nexport const CREATE_DIRECT_CHANNEL_MUTATION = `\n mutation ChatCreateDirectChannel($receiver: [ID]!, $displayName: String!) {\n createDirectChannel(receiver: $receiver, displayName: $displayName) {\n ${CHANNEL_FIELDS}\n }\n }\n`;\n\n/**\n * Live messages for one channel.\n *\n * `_WS` suffix is load-bearing - see the file header. `directTo` is left unset:\n * the server treats it as a second, user-scoped topic and passing the wrong one\n * silently delivers nothing.\n */\nexport const MESSAGE_ADDED_SUBSCRIPTION_WS = `\n subscription ChatMessageAdded_WS($channelId: String) {\n chatMessageAdded(channelId: $channelId) {\n ${POST_FIELDS}\n }\n }\n`;\n\n/**\n * Set the viewer's single Tapback on a message; `reaction: null` removes it.\n * Returns the message's reactions after the change.\n */\nexport const SET_MESSAGE_REACTION_MUTATION = `\n mutation ChatSetMessageReaction($channelId: String!, $postId: ID!, $reaction: String) {\n setMessageReaction(channelId: $channelId, postId: $postId, reaction: $reaction) {\n reaction\n count\n userIds\n }\n }\n`;\n\n/** Live reaction changes for one channel. `_WS` suffix is load-bearing - see the file header. */\nexport const REACTION_CHANGED_SUBSCRIPTION_WS = `\n subscription ChatReactionChanged_WS($channelId: String!) {\n chatReactionChanged(channelId: $channelId) {\n channelId\n postId\n reactions { reaction count userIds }\n }\n }\n`;\n\n/**\n * Which of these phone numbers already have an account.\n *\n * Sends SHA-256 hashes of E.164 numbers, never the numbers - the server never\n * receives a plaintext address book. Returns AnyObject: a list of\n * `{phoneHash, userId, username, displayName, picture}`.\n */\nexport const CONTACT_MATCHES_QUERY = `\n query ChatContactMatches($phoneHashes: [String!]!) {\n chatContactMatches(phoneHashes: $phoneHashes)\n }\n`;\n\nexport const YANTRA_CHAT_REGISTRATION_STATUS_QUERY = `\n query YantraChatRegistrationStatus {\n yantraChatRegistrationStatus {\n registered\n phoneE164\n memberId\n organizationId\n }\n }\n`;\n\nexport const REGISTER_YANTRA_CHAT_MEMBER_MUTATION = `\n mutation RegisterYantraChatMember($phoneE164: String!, $displayName: String) {\n registerYantraChatMember(phoneE164: $phoneE164, displayName: $displayName) {\n registered\n phoneE164\n memberId\n organizationId\n }\n }\n`;\n\nexport const MATCH_YANTRA_CHAT_MEMBERS_QUERY = `\n query MatchYantraChatMembersByPhone($phones: [String!]!, $viewerPhoneE164: String) {\n matchYantraChatMembersByPhone(phones: $phones, viewerPhoneE164: $viewerPhoneE164) {\n phoneE164\n userId\n displayName\n avatarUrl\n }\n }\n`;\n\nexport const YANTRA_CHAT_MEMBERS_QUERY = `\n query YantraChatMembers {\n yantraChatMembers {\n phoneE164\n userId\n displayName\n avatarUrl\n }\n }\n`;\n\n/** Composer draft persistence, server-side and per (member, channel). */\nexport const SET_DRAFT_MUTATION = `\n mutation ChatSetDraft($channelId: ID!, $text: String!) {\n setChannelDraft(channelId: $channelId, text: $text)\n }\n`;\n\nexport const DRAFT_QUERY = `\n query ChatDraft($channelId: ID!) {\n channelDraft(channelId: $channelId)\n }\n`;\n\n/** Every operation, for the contract test and for host-side preflight. */\nexport const CHAT_OPERATIONS: Readonly<Record<string, string>> = Object.freeze({\n CHANNELS_QUERY,\n CONTACT_MATCHES_QUERY,\n YANTRA_CHAT_REGISTRATION_STATUS_QUERY,\n REGISTER_YANTRA_CHAT_MEMBER_MUTATION,\n MATCH_YANTRA_CHAT_MEMBERS_QUERY,\n YANTRA_CHAT_MEMBERS_QUERY,\n MESSAGES_QUERY,\n SEND_MESSAGE_MUTATION,\n VIEW_CHANNEL_MUTATION,\n CREATE_DIRECT_CHANNEL_MUTATION,\n MESSAGE_ADDED_SUBSCRIPTION_WS,\n SET_MESSAGE_REACTION_MUTATION,\n REACTION_CHANGED_SUBSCRIPTION_WS,\n SET_DRAFT_MUTATION,\n DRAFT_QUERY,\n});\n\n/**\n * The operation name inside a document string.\n *\n * Used by the contract test and by the host seam for logging. Intentionally a\n * regex rather than a parse: pulling in `graphql` to read a name would defeat\n * the whole point of shipping strings.\n */\nexport function operationNameOf(document: string): string | null {\n const match = /\\b(?:query|mutation|subscription)\\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(document);\n return match ? match[1] : null;\n}\n\nexport function operationTypeOf(document: string): 'query' | 'mutation' | 'subscription' | null {\n const match = /\\b(query|mutation|subscription)\\s+[A-Za-z_]/.exec(document);\n return match ? (match[1] as 'query' | 'mutation' | 'subscription') : null;\n}\n"],"names":[],"mappings":"AA8KO,MAAM,qCAAwC,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU9C,MAAM,oCAAuC,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA"}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
const YANTRA_CHAT_PHONE_STORAGE_KEY = "yantra-chat-registered-phone-e164";
|
|
1
|
+
const YANTRA_CHAT_PHONE_STORAGE_KEY = "yantra-chat-registered-phone-e164";
|
|
2
|
+
function yantraChatPhoneStorageKey(userId) {
|
|
3
|
+
return `${YANTRA_CHAT_PHONE_STORAGE_KEY}:${userId}`;
|
|
4
|
+
}export{YANTRA_CHAT_PHONE_STORAGE_KEY,yantraChatPhoneStorageKey};//# sourceMappingURL=chatRegistrationStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatRegistrationStorage.js","sources":["../../../src/features/messaging/chatRegistrationStorage.ts"],"sourcesContent":["/**\n * AsyncStorage cache for Yantra Chat registration (issue #1312).\n * Mongo `organizationMembers` is the source of truth (`yantraChatRegistrationStatus`);\n * this key only avoids flashing the registration screen while the status query runs.\n * It is not cleared on network/GraphQL errors (Metro reload, backend restart).\n */\nexport const YANTRA_CHAT_PHONE_STORAGE_KEY = 'yantra-chat-registered-phone-e164';\n"],"names":[],"mappings":"AAMO,MAAM,6BAAgC,GAAA"}
|
|
1
|
+
{"version":3,"file":"chatRegistrationStorage.js","sources":["../../../src/features/messaging/chatRegistrationStorage.ts"],"sourcesContent":["/**\n * AsyncStorage cache for Yantra Chat registration (issue #1312).\n * Mongo `organizationMembers` is the source of truth (`yantraChatRegistrationStatus`);\n * this key only avoids flashing the registration screen while the status query runs.\n * It is not cleared on network/GraphQL errors (Metro reload, backend restart).\n */\nexport const YANTRA_CHAT_PHONE_STORAGE_KEY = 'yantra-chat-registered-phone-e164';\n\n/** Per account, so a cached registration is never trusted for a different user on the same device. */\nexport function yantraChatPhoneStorageKey(userId: string): string {\n return `${YANTRA_CHAT_PHONE_STORAGE_KEY}:${userId}`;\n}\n"],"names":[],"mappings":"AAMO,MAAM,6BAAgC,GAAA;AAGtC,SAAS,0BAA0B,MAAwB,EAAA;AAChE,EAAO,OAAA,CAAA,EAAG,6BAA6B,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AACnD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useState,useCallback,useEffect,useMemo}from'react';import {useApolloClient,gql}from'@apollo/client/index.js';import AsyncStorage from'@react-native-async-storage/async-storage';import {YANTRA_CHAT_REGISTRATION_STATUS_QUERY,REGISTER_YANTRA_CHAT_MEMBER_MUTATION}from'./chatOperations.js';import {
|
|
1
|
+
import {useState,useCallback,useEffect,useMemo}from'react';import {useApolloClient,gql}from'@apollo/client/index.js';import AsyncStorage from'@react-native-async-storage/async-storage';import {YANTRA_CHAT_REGISTRATION_STATUS_QUERY,REGISTER_YANTRA_CHAT_MEMBER_MUTATION}from'./chatOperations.js';import {yantraChatPhoneStorageKey}from'./chatRegistrationStorage.js';const REGISTRATION_STATUS_DOCUMENT = gql(YANTRA_CHAT_REGISTRATION_STATUS_QUERY);
|
|
2
2
|
const REGISTER_MEMBER_DOCUMENT = gql(REGISTER_YANTRA_CHAT_MEMBER_MUTATION);
|
|
3
3
|
function useYantraChatMembership(userId, displayName) {
|
|
4
4
|
const client = useApolloClient();
|
|
@@ -14,8 +14,11 @@ function useYantraChatMembership(userId, displayName) {
|
|
|
14
14
|
}
|
|
15
15
|
setError(null);
|
|
16
16
|
try {
|
|
17
|
-
const cached = await AsyncStorage.getItem(
|
|
18
|
-
if (cached)
|
|
17
|
+
const cached = await AsyncStorage.getItem(yantraChatPhoneStorageKey(userId));
|
|
18
|
+
if (cached) {
|
|
19
|
+
setPhoneE164(cached);
|
|
20
|
+
setLoading(false);
|
|
21
|
+
}
|
|
19
22
|
const res = await client.query({
|
|
20
23
|
query: REGISTRATION_STATUS_DOCUMENT,
|
|
21
24
|
fetchPolicy: "network-only"
|
|
@@ -28,10 +31,10 @@ function useYantraChatMembership(userId, displayName) {
|
|
|
28
31
|
if ((status == null ? void 0 : status.registered) && status.phoneE164) {
|
|
29
32
|
setPhoneE164(status.phoneE164);
|
|
30
33
|
setOrganizationId(status.organizationId);
|
|
31
|
-
await AsyncStorage.setItem(
|
|
34
|
+
await AsyncStorage.setItem(yantraChatPhoneStorageKey(userId), status.phoneE164);
|
|
32
35
|
} else if (status && status.registered === false) {
|
|
33
36
|
setPhoneE164(null);
|
|
34
|
-
await AsyncStorage.removeItem(
|
|
37
|
+
await AsyncStorage.removeItem(yantraChatPhoneStorageKey(userId));
|
|
35
38
|
}
|
|
36
39
|
} catch (err) {
|
|
37
40
|
setError(err instanceof Error ? err.message : "Could not load chat registration");
|
|
@@ -59,7 +62,7 @@ function useYantraChatMembership(userId, displayName) {
|
|
|
59
62
|
}
|
|
60
63
|
setPhoneE164(payload.phoneE164);
|
|
61
64
|
setOrganizationId(payload.organizationId);
|
|
62
|
-
await AsyncStorage.setItem(
|
|
65
|
+
await AsyncStorage.setItem(yantraChatPhoneStorageKey(userId), payload.phoneE164);
|
|
63
66
|
return payload.phoneE164;
|
|
64
67
|
}, [client, userId, displayName]);
|
|
65
68
|
const needsRegistration = useMemo(() => Boolean(userId) && !loading && !phoneE164, [userId, loading, phoneE164]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useYantraChatMembership.js","sources":["../../../src/features/messaging/useYantraChatMembership.ts"],"sourcesContent":["/**\n * Yantra Chat registration status + register mutation (issue #1312).\n */\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { gql, useApolloClient } from '@apollo/client';\nimport AsyncStorage from '@react-native-async-storage/async-storage';\nimport { REGISTER_YANTRA_CHAT_MEMBER_MUTATION, YANTRA_CHAT_REGISTRATION_STATUS_QUERY } from './chatOperations';\nimport {
|
|
1
|
+
{"version":3,"file":"useYantraChatMembership.js","sources":["../../../src/features/messaging/useYantraChatMembership.ts"],"sourcesContent":["/**\n * Yantra Chat registration status + register mutation (issue #1312).\n */\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { gql, useApolloClient } from '@apollo/client';\nimport AsyncStorage from '@react-native-async-storage/async-storage';\nimport { REGISTER_YANTRA_CHAT_MEMBER_MUTATION, YANTRA_CHAT_REGISTRATION_STATUS_QUERY } from './chatOperations';\nimport { yantraChatPhoneStorageKey } from './chatRegistrationStorage';\n\nconst REGISTRATION_STATUS_DOCUMENT = gql(YANTRA_CHAT_REGISTRATION_STATUS_QUERY);\nconst REGISTER_MEMBER_DOCUMENT = gql(REGISTER_YANTRA_CHAT_MEMBER_MUTATION);\n\ninterface RegistrationPayload {\n registered: boolean;\n phoneE164: string | null;\n memberId: string | null;\n organizationId: string;\n}\n\nexport function useYantraChatMembership(userId: string | null, displayName: string) {\n const client = useApolloClient();\n const [phoneE164, setPhoneE164] = useState<string | null>(null);\n const [organizationId, setOrganizationId] = useState<string | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<string | null>(null);\n\n const refresh = useCallback(async () => {\n if (!userId) {\n setLoading(false);\n return;\n }\n setError(null);\n try {\n const cached = await AsyncStorage.getItem(yantraChatPhoneStorageKey(userId));\n if (cached) {\n // Already registered on this device: open chat now and confirm with the server in the\n // background. A server \"not registered\" still clears this and shows registration.\n setPhoneE164(cached);\n setLoading(false);\n }\n\n const res = await client.query<{ yantraChatRegistrationStatus?: RegistrationPayload }>({\n query: REGISTRATION_STATUS_DOCUMENT,\n fetchPolicy: 'network-only',\n });\n\n if (res.errors?.length) {\n setError(res.errors[0]?.message ?? 'Could not load chat registration');\n // Keep AsyncStorage + in-memory phone on transient GraphQL errors (Metro reload, backend restart).\n return;\n }\n\n const status = res.data?.yantraChatRegistrationStatus;\n if (status?.registered && status.phoneE164) {\n setPhoneE164(status.phoneE164);\n setOrganizationId(status.organizationId);\n await AsyncStorage.setItem(yantraChatPhoneStorageKey(userId), status.phoneE164);\n } else if (status && status.registered === false) {\n setPhoneE164(null);\n await AsyncStorage.removeItem(yantraChatPhoneStorageKey(userId));\n }\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Could not load chat registration');\n // Network failure: do not clear cached registration.\n } finally {\n setLoading(false);\n }\n }, [client, userId]);\n\n useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const register = useCallback(\n async (phone: string) => {\n if (!userId) throw new Error('Not signed in');\n setError(null);\n const res = await client.mutate<{ registerYantraChatMember?: RegistrationPayload }>({\n mutation: REGISTER_MEMBER_DOCUMENT,\n variables: { phoneE164: phone, displayName },\n });\n const payload = res.data?.registerYantraChatMember;\n if (!payload?.registered || !payload.phoneE164) {\n throw new Error('Registration did not complete');\n }\n setPhoneE164(payload.phoneE164);\n setOrganizationId(payload.organizationId);\n await AsyncStorage.setItem(yantraChatPhoneStorageKey(userId), payload.phoneE164);\n return payload.phoneE164;\n },\n [client, userId, displayName],\n );\n\n const needsRegistration = useMemo(() => Boolean(userId) && !loading && !phoneE164, [userId, loading, phoneE164]);\n\n return {\n phoneE164,\n organizationId,\n loading,\n error,\n needsRegistration,\n register,\n refresh,\n };\n}\n"],"names":[],"mappings":"2WAQA,MAAM,4BAAA,GAA+B,IAAI,qCAAqC,CAAA;AAC9E,MAAM,wBAAA,GAA2B,IAAI,oCAAoC,CAAA;AAOzD,SAAA,uBAAA,CAAwB,QAAuB,WAAqB,EAAA;AAClF,EAAA,MAAM,SAAS,eAAgB,EAAA;AAC/B,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAwB,IAAI,CAAA;AAC9D,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CAAA,GAAI,SAAwB,IAAI,CAAA;AACxE,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,IAAI,CAAA;AAC3C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAwB,IAAI,CAAA;AACtD,EAAM,MAAA,OAAA,GAAU,YAAY,YAAY;AAtB1C,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAuBI,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAA,UAAA,CAAW,KAAK,CAAA;AAChB,MAAA;AAAA;AAEF,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAI,IAAA;AACF,MAAA,MAAM,SAAS,MAAM,YAAA,CAAa,OAAQ,CAAA,yBAAA,CAA0B,MAAM,CAAC,CAAA;AAC3E,MAAA,IAAI,MAAQ,EAAA;AAGV,QAAA,YAAA,CAAa,MAAM,CAAA;AACnB,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA;AAElB,MAAM,MAAA,GAAA,GAAM,MAAM,MAAA,CAAO,KAEtB,CAAA;AAAA,QACD,KAAO,EAAA,4BAAA;AAAA,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A,IACA;AAAA,GACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/yantra-mobile",
|
|
3
|
-
"version": "12.0.69-alpha.
|
|
3
|
+
"version": "12.0.69-alpha.6",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@messenger-box/platform-mobile": "*",
|
|
42
42
|
"@react-native-async-storage/async-storage": "*",
|
|
43
43
|
"@react-navigation/native": "*",
|
|
44
|
-
"common": "12.0.69-alpha.
|
|
44
|
+
"common": "12.0.69-alpha.4",
|
|
45
45
|
"expo-constants": "*",
|
|
46
46
|
"expo-secure-store": "*",
|
|
47
47
|
"lodash": "*",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"typescript": {
|
|
58
58
|
"definition": "lib/index.d.ts"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "37d9f7f5bcd6ef3d89b8db1536ce1a7ca5b8adab"
|
|
61
61
|
}
|