@messenger-box/platform-client 10.0.3-alpha.7 → 10.0.3-alpha.74

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/lib/graphql/fragments/post-message.gql +36 -0
  3. package/lib/graphql/mutations/channel-mutation.gql +5 -0
  4. package/lib/graphql/mutations/messages-mutation.gql +37 -0
  5. package/lib/graphql/policies/channel-policies.d.ts.map +1 -1
  6. package/lib/graphql/policies/channel-policies.js +150 -2
  7. package/lib/graphql/policies/channel-policies.js.map +1 -1
  8. package/lib/graphql/policies/messages-policies.d.ts.map +1 -1
  9. package/lib/graphql/policies/messages-policies.js +229 -37
  10. package/lib/graphql/policies/messages-policies.js.map +1 -1
  11. package/lib/graphql/policies/post-thread-policies.d.ts.map +1 -1
  12. package/lib/graphql/policies/post-thread-policies.js +136 -31
  13. package/lib/graphql/policies/post-thread-policies.js.map +1 -1
  14. package/lib/graphql/policies/teams-policies.d.ts.map +1 -1
  15. package/lib/graphql/policies/teams-policies.js +13 -1
  16. package/lib/graphql/policies/teams-policies.js.map +1 -1
  17. package/lib/graphql/queries/channels-by-user.gql +26 -0
  18. package/lib/graphql/queries/messages.gql +2 -2
  19. package/lib/graphql/queries/organization-query.gql +78 -35
  20. package/lib/graphql/queries/post-thread-message.gql +4 -0
  21. package/lib/graphql/queries/teams-query.gql +79 -29
  22. package/lib/graphql/queries/user-account.gql +1 -1
  23. package/lib/graphql/queries/users.gql +1 -1
  24. package/lib/graphql/subscription/fileUpdated.gql +11 -0
  25. package/lib/graphql/subscription/fragmentUpdated.gql +7 -0
  26. package/lib/graphql/subscription/sandboxError.gql +17 -0
  27. package/lib/hooks/use-upload-file.hook.d.ts.map +1 -1
  28. package/lib/hooks/use-upload-file.hook.js +1 -1
  29. package/lib/hooks/use-upload-file.hook.js.map +1 -1
  30. package/lib/hooks/use-upload-file.hook.native.d.ts.map +1 -1
  31. package/lib/hooks/use-upload-file.hook.native.js +1 -1
  32. package/lib/hooks/use-upload-file.hook.native.js.map +1 -1
  33. package/lib/hooks/use-upload-files.hook.d.ts.map +1 -1
  34. package/lib/hooks/use-upload-files.hook.js +1 -1
  35. package/lib/hooks/use-upload-files.hook.js.map +1 -1
  36. package/lib/hooks/use-upload-files.hook.native.d.ts.map +1 -1
  37. package/lib/hooks/use-upload-files.hook.native.js +1 -1
  38. package/lib/hooks/use-upload-files.hook.native.js.map +1 -1
  39. package/package.json +4 -4
  40. package/src/graphql/fragments/post-message.gql +36 -0
  41. package/src/graphql/mutations/channel-mutation.gql +5 -0
  42. package/src/graphql/mutations/messages-mutation.gql +37 -0
  43. package/src/graphql/policies/channel-policies.ts +148 -2
  44. package/src/graphql/policies/messages-policies.ts +251 -39
  45. package/src/graphql/policies/post-thread-policies.ts +151 -31
  46. package/src/graphql/policies/teams-policies.ts +13 -1
  47. package/src/graphql/queries/channels-by-user.gql +26 -0
  48. package/src/graphql/queries/messages.gql +2 -2
  49. package/src/graphql/queries/organization-query.gql +78 -35
  50. package/src/graphql/queries/post-thread-message.gql +4 -0
  51. package/src/graphql/queries/teams-query.gql +79 -29
  52. package/src/graphql/queries/user-account.gql +1 -1
  53. package/src/graphql/queries/users.gql +1 -1
  54. package/src/graphql/subscription/fileUpdated.gql +11 -0
  55. package/src/graphql/subscription/fragmentUpdated.gql +7 -0
  56. package/src/graphql/subscription/sandboxError.gql +17 -0
  57. package/src/hooks/use-upload-file.hook.native.ts +1 -4
  58. package/src/hooks/use-upload-file.hook.ts +1 -4
  59. package/src/hooks/use-upload-files.hook.native.ts +1 -4
  60. package/src/hooks/use-upload-files.hook.ts +1 -4
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-file.hook.native.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-file.hook.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,uEAAuE,CAAC;AAM3H,eAAO,MAAM,aAAa,QAAO,UAAU,CAAC,OAAO,iBAAiB,CAkB9D,CAAC"}
1
+ {"version":3,"file":"use-upload-file.hook.native.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-file.hook.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,uEAAuE,CAAC;AAG3H,eAAO,MAAM,aAAa,QAAO,UAAU,CAAC,OAAO,iBAAiB,CAkB9D,CAAC"}
@@ -1,4 +1,4 @@
1
- import {useUploadFile as useUploadFile$1}from'@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';import {useAttachUploadedFileToMessageMutation,useCreateMessageFileUploadLinkMutation}from'common/lib/generated/generated.js';const useUploadFile = () => useUploadFile$1({
1
+ import {useUploadFile as useUploadFile$1}from'@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';import {useAttachUploadedFileToMessageMutation,useCreateMessageFileUploadLinkMutation}from'common/graphql';const useUploadFile = () => useUploadFile$1({
2
2
  createUploadLink: {
3
3
  name: 'createMessageFileUploadLink',
4
4
  mutation: useCreateMessageFileUploadLinkMutation,
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-file.hook.native.js","sources":["../../src/hooks/use-upload-file.hook.native.ts"],"sourcesContent":[null],"names":["useBaseUploadFile"],"mappings":"yPAMa,aAAa,GAAG,MACzBA,eAAiB,CAAC;AACd,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,6BAAmC;AACnC,IAAA,QAAA,EAAA,sCAAgD;oBAChC,EAAA,CAAA,IAAG,EAAI,eAAa;cACxB,EAAA,KAAA,CAAE,OAAM,CAAA,IAAA,CAAO,GAAK,IAAE,CAAC,CAAC,OAAO,GAAE,IAAK,CAAC,IAAK;AACpD,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,6BAAmC;AACnC,IAAA,QAAA,EAAA,sCAAgD;oBAChC,EAAA,CAAA,IAAG,EAAI,eAAa;;AAEhC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
1
+ {"version":3,"file":"use-upload-file.hook.native.js","sources":["../../src/hooks/use-upload-file.hook.native.ts"],"sourcesContent":[null],"names":["useBaseUploadFile"],"mappings":"sOAGa,aAAa,GAAG,MACzBA,eAAiB,CAAC;AACd,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,6BAAmC;AACnC,IAAA,QAAA,EAAA,sCAAgD;oBAChC,EAAA,CAAA,IAAG,EAAI,eAAa;cACxB,EAAA,KAAA,CAAE,OAAM,CAAA,IAAA,CAAO,GAAK,IAAE,CAAC,CAAC,OAAO,GAAE,IAAK,CAAC,IAAK;AACpD,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,6BAAmC;AACnC,IAAA,QAAA,EAAA,sCAAgD;oBAChC,EAAA,CAAA,IAAG,EAAI,eAAa;;AAEhC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-files.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-files.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gEAAgE,CAAC;AAM/F,eAAO,MAAM,cAAc,QAAO,UAAU,CAAC,OAAO,aAAa,CAkB3D,CAAC"}
1
+ {"version":3,"file":"use-upload-files.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-files.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gEAAgE,CAAC;AAG/F,eAAO,MAAM,cAAc,QAAO,UAAU,CAAC,OAAO,aAAa,CAkB3D,CAAC"}
@@ -1,4 +1,4 @@
1
- import {useUploadFile}from'@container-stack/file-info-client/lib/hooks/use-upload-file.js';import {useAttachUploadedFilesToMessageMutation,useCreateMessageFilesUploadLinkMutation}from'common/lib/generated/generated.js';const useUploadFiles = () => useUploadFile({
1
+ import {useUploadFile}from'@container-stack/file-info-client/lib/hooks/use-upload-file.js';import {useAttachUploadedFilesToMessageMutation,useCreateMessageFilesUploadLinkMutation}from'common/graphql';const useUploadFiles = () => useUploadFile({
2
2
  createUploadLink: {
3
3
  name: 'createMessageFilesUploadLink',
4
4
  mutation: useCreateMessageFilesUploadLinkMutation,
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-files.hook.js","sources":["../../src/hooks/use-upload-files.hook.ts"],"sourcesContent":[null],"names":[],"mappings":"iOAMa,cAAc,GAAG,MAC1B,aAAa,CAAC;AACV,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;AACjC,MAAA,SAAA,EAAA,KAAW,CAAA,OAAM,CAAA,KAAO,CAAC,GAAA,KAAQ,CAAC,GAAK,CAAA,QAAU,IAAA,CAAE,IAAO,CAAA,GAAC,CAAI,KAAE,CAAC,IAAO,CAAA;AACzE,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;;AAEjC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
1
+ {"version":3,"file":"use-upload-files.hook.js","sources":["../../src/hooks/use-upload-files.hook.ts"],"sourcesContent":[null],"names":[],"mappings":"8MAGa,cAAc,GAAG,MAC1B,aAAa,CAAC;AACV,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;AACjC,MAAA,SAAA,EAAA,KAAW,CAAA,OAAM,CAAA,KAAO,CAAC,GAAA,KAAQ,CAAC,GAAK,CAAA,QAAU,IAAA,CAAE,IAAO,CAAA,GAAC,CAAI,KAAE,CAAC,IAAO,CAAA;AACzE,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;;AAEjC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-files.hook.native.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-files.hook.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uEAAuE,CAAC;AAMtG,eAAO,MAAM,cAAc,QAAO,UAAU,CAAC,OAAO,aAAa,CAkB3D,CAAC"}
1
+ {"version":3,"file":"use-upload-files.hook.native.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-files.hook.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uEAAuE,CAAC;AAGtG,eAAO,MAAM,cAAc,QAAO,UAAU,CAAC,OAAO,aAAa,CAkB3D,CAAC"}
@@ -1,4 +1,4 @@
1
- import {useUploadFile}from'@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';import {useAttachUploadedFilesToMessageMutation,useCreateMessageFilesUploadLinkMutation}from'common/lib/generated/generated.js';const useUploadFiles = () => useUploadFile({
1
+ import {useUploadFile}from'@container-stack/file-info-client/lib/hooks/use-file-upload.native.js';import {useAttachUploadedFilesToMessageMutation,useCreateMessageFilesUploadLinkMutation}from'common/graphql';const useUploadFiles = () => useUploadFile({
2
2
  createUploadLink: {
3
3
  name: 'createMessageFilesUploadLink',
4
4
  mutation: useCreateMessageFilesUploadLinkMutation,
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload-files.hook.native.js","sources":["../../src/hooks/use-upload-files.hook.native.ts"],"sourcesContent":[null],"names":[],"mappings":"wOAMa,cAAc,GAAG,MAC1B,aAAa,CAAC;AACV,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;AACjC,MAAA,SAAA,EAAA,KAAW,CAAA,OAAM,CAAA,KAAO,CAAC,GAAA,KAAQ,CAAC,GAAK,CAAA,QAAU,IAAA,CAAE,IAAO,CAAA,GAAC,CAAI,KAAE,CAAC,IAAO,CAAA;AACzE,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;;AAEjC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
1
+ {"version":3,"file":"use-upload-files.hook.native.js","sources":["../../src/hooks/use-upload-files.hook.native.ts"],"sourcesContent":[null],"names":[],"mappings":"qNAGa,cAAc,GAAG,MAC1B,aAAa,CAAC;AACV,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;AACjC,MAAA,SAAA,EAAA,KAAW,CAAA,OAAM,CAAA,KAAO,CAAC,GAAA,KAAQ,CAAC,GAAK,CAAA,QAAU,IAAA,CAAE,IAAO,CAAA,GAAC,CAAI,KAAE,CAAC,IAAO,CAAA;AACzE,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD,GAAA;AACD,EAAA,gBAAA,EAAgB;AACZ,IAAA,IAAA,EAAA,8BAAoC;AACpC,IAAA,QAAA,EAAA,uCAAiD;oBACjC,EAAA,CAAA,KAAQ,EAAA,eAAa;;AAEjC,MAAA,IAAA,OAAI,SAAgB,KAAA,QAAa,GAAA,SAAY,GAAA,EAAA;;AAEpD;AACJ,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@messenger-box/platform-client",
3
- "version": "10.0.3-alpha.7",
3
+ "version": "10.0.3-alpha.74",
4
4
  "description": "Sample core for higher packages to depend on",
5
5
  "license": "ISC",
6
6
  "author": "CDMBase LLC",
@@ -20,8 +20,8 @@
20
20
  "watch": "yarn build:lib:watch"
21
21
  },
22
22
  "dependencies": {
23
- "@container-stack/file-info-client": "^5.4.1-alpha.6",
24
- "@messenger-box/core": "10.0.3-alpha.7",
23
+ "@container-stack/file-info-client": "^5.4.1-alpha.9",
24
+ "@messenger-box/core": "10.0.3-alpha.74",
25
25
  "key-mirror": "1.0.1",
26
26
  "moment-timezone": "0.5.33"
27
27
  },
@@ -35,5 +35,5 @@
35
35
  "typescript": {
36
36
  "definition": "lib/index.d.ts"
37
37
  },
38
- "gitHead": "6c95ed48d37a8f95b0c3db71c1922c0e9e76bcfe"
38
+ "gitHead": "2bfc901f9f0a9da1919294e1ebd8246edec0a3b0"
39
39
  }
@@ -19,6 +19,18 @@ fragment Post on Post {
19
19
  # propsConfiguration {
20
20
  # ...Configuration
21
21
  # }
22
+ propsConfiguration {
23
+ contents
24
+ id
25
+ keys
26
+ resource
27
+ target
28
+ overrides {
29
+ contents
30
+ identifiers
31
+ keys
32
+ }
33
+ }
22
34
  props
23
35
  files {
24
36
  totalCount
@@ -58,6 +70,18 @@ fragment PostReplies on Messages {
58
70
  # propsConfiguration {
59
71
  # ...Configuration
60
72
  # }
73
+ propsConfiguration {
74
+ contents
75
+ id
76
+ keys
77
+ resource
78
+ target
79
+ overrides {
80
+ contents
81
+ identifiers
82
+ keys
83
+ }
84
+ }
61
85
  props
62
86
  files {
63
87
  totalCount
@@ -98,6 +122,18 @@ fragment PostWithoutReplies on Post {
98
122
  # propsConfiguration {
99
123
  # ...Configuration
100
124
  # }
125
+ propsConfiguration {
126
+ contents
127
+ id
128
+ keys
129
+ resource
130
+ target
131
+ overrides {
132
+ contents
133
+ identifiers
134
+ keys
135
+ }
136
+ }
101
137
  props
102
138
  files {
103
139
  totalCount
@@ -70,3 +70,8 @@ mutation saveMembersToChannel($membersIds:[String]!,$channelId:String!){
70
70
  mutation DeleteChannel($ChannelId:ID!){
71
71
  deleteChannel(id: $ChannelId)
72
72
  }
73
+
74
+
75
+ mutation CreateChannelWithProjectId($projectId: String!, $channelInput: ChannelInput!) {
76
+ createChannelWithProjectId(projectId: $projectId, channelInput: $channelInput)
77
+ }
@@ -5,6 +5,7 @@ mutation SendMessages(
5
5
  $postId: ID,
6
6
  $createdBy: ID,
7
7
  $notificationParams:ExpoNotificationData,
8
+ $extraProps:AnyObject
8
9
  ){
9
10
  sendMessage(
10
11
  channelId: $channelId,
@@ -13,6 +14,7 @@ mutation SendMessages(
13
14
  files: $files,
14
15
  createdBy: $createdBy
15
16
  notificationParams: $notificationParams
17
+ extraProps: $extraProps
16
18
  },
17
19
  postId: $postId
18
20
  ){
@@ -95,6 +97,41 @@ mutation DeleteMessageFile($url:String!){
95
97
  }
96
98
 
97
99
 
100
+ mutation GenerateAiCode($messageId: String!, $modelConfig: ModelConfigurationInput) {
101
+ generateAiCode(messageId: $messageId, modelConfig: $modelConfig) {
102
+ eventId
103
+ message
104
+ success
105
+ }
106
+ }
107
+
108
+ mutation RecreateSandbox($messageId: String!, $projectId: String!) {
109
+ recreateSandbox(messageId: $messageId, projectId: $projectId) {
110
+ eventId
111
+ message
112
+ success
113
+ }
114
+ }
115
+
116
+ mutation UpdateSandboxFile($projectId: String!, $messageId: String!, $filePath: String!, $content: String!) {
117
+ updateSandboxFile(projectId: $projectId, messageId: $messageId, filePath: $filePath, content: $content) {
118
+ success
119
+ message
120
+ filePath
121
+ timestamp
122
+ syncStatus
123
+ }
124
+ }
125
+
126
+ mutation RegenerateAiCode($messageId: String!, $modelConfig: ModelConfigurationInput) {
127
+ regenerateAiCode(messageId: $messageId, modelConfig: $modelConfig) {
128
+ eventId
129
+ message
130
+ success
131
+ }
132
+ }
133
+
134
+
98
135
  #mutation PinMessage($messageId:String! , $messageInput:String! , $content:String!) {
99
136
  # pinMessage(
100
137
  # messageId: {
@@ -1,7 +1,153 @@
1
- import { TypePolicies } from '@apollo/client';
1
+ import { TypePolicies, gql } from '@apollo/client';
2
2
 
3
3
  export const channelPolicies: TypePolicies = {
4
4
  Query: {
5
- fields: {},
5
+ fields: {
6
+ channelsByUser: {
7
+ keyArgs: ['role', 'criteria', 'limit', 'skip', 'sort'],
8
+ merge(existing = [], incoming = [], { readField }) {
9
+ // If no existing data, just return incoming
10
+ if (!existing || existing.length === 0) {
11
+ return incoming;
12
+ }
13
+
14
+ // If no incoming data, keep existing
15
+ if (!incoming || incoming.length === 0) {
16
+ return existing;
17
+ }
18
+
19
+ // Create a map for efficient lookup
20
+ const channelMap = new Map();
21
+
22
+ // Add existing channels to map
23
+ for (let i = 0; i < existing.length; i++) {
24
+ const channel = existing[i];
25
+ if (channel) {
26
+ const id = readField('id', channel);
27
+ if (id) {
28
+ channelMap.set(id, channel);
29
+ }
30
+ }
31
+ }
32
+
33
+ // Merge in incoming channels, overwriting existing ones
34
+ for (let i = 0; i < incoming.length; i++) {
35
+ const channel = incoming[i];
36
+ if (channel) {
37
+ const id = readField('id', channel);
38
+ if (id) {
39
+ channelMap.set(id, channel);
40
+ }
41
+ }
42
+ }
43
+
44
+ // Convert map values back to array
45
+ return Array.from(channelMap.values());
46
+ },
47
+ // Add a read function for more control over cache reads
48
+ read(existing, { args }) {
49
+ // Return undefined to force a network request if data doesn't exist
50
+ if (!existing) return undefined;
51
+ return existing;
52
+ },
53
+ },
54
+ },
55
+ },
56
+ Channel: {
57
+ keyFields: ['id'],
58
+ fields: {
59
+ members: {
60
+ merge(existing = [], incoming) {
61
+ return incoming;
62
+ },
63
+ },
64
+ // Add field policies for other Channel fields if needed
65
+ title: {
66
+ read(title) {
67
+ return title || '';
68
+ },
69
+ },
70
+ displayName: {
71
+ read(displayName) {
72
+ return displayName || '';
73
+ },
74
+ },
75
+ // Add computed fields if needed
76
+ memberCount: {
77
+ read(_, { readField }) {
78
+ const members = readField('members') as any[];
79
+ return members && Array.isArray(members) ? members.length : 0;
80
+ },
81
+ },
82
+ lastMessage: {
83
+ merge(existing, incoming, { readField }) {
84
+ // If no incoming message, keep existing
85
+ if (!incoming) return existing;
86
+
87
+ // If no existing message, use incoming
88
+ if (!existing) return incoming;
89
+
90
+ // Compare timestamps to determine which is newer
91
+ const existingCreatedAt = readField('createdAt', existing) as string | number | Date;
92
+ const incomingCreatedAt = readField('createdAt', incoming) as string | number | Date;
93
+
94
+ if (existingCreatedAt && incomingCreatedAt) {
95
+ // Use the more recent message
96
+ return new Date(incomingCreatedAt) > new Date(existingCreatedAt) ? incoming : existing;
97
+ }
98
+
99
+ // If timestamps are not available, prefer incoming
100
+ return incoming;
101
+ },
102
+ read(lastMessage, { readField, cache, args }) {
103
+ // If lastMessage is already available, return it
104
+ if (lastMessage) return lastMessage;
105
+
106
+ // Try to get the channel ID to reference messages cache
107
+ const channelId = readField('id');
108
+ if (!channelId) return null;
109
+
110
+ try {
111
+ // Read messages from cache for this channel
112
+ const messagesQuery = cache.readQuery({
113
+ query: gql`
114
+ query GetChannelMessages($channelId: String!) {
115
+ messages(channelId: $channelId, skip: 0, limit: 1) {
116
+ data {
117
+ id
118
+ content
119
+ createdAt
120
+ updatedAt
121
+ user {
122
+ id
123
+ username
124
+ displayName
125
+ }
126
+ }
127
+ }
128
+ }
129
+ `,
130
+ variables: { channelId },
131
+ }) as any;
132
+
133
+ // Return the first (latest) message if available
134
+ return messagesQuery?.messages?.data?.[0] || null;
135
+ } catch (error) {
136
+ // If messages query fails, return null
137
+ return null;
138
+ }
139
+ },
140
+ },
141
+ },
142
+ },
143
+ // Add policies for ChannelMember type
144
+ ChannelMember: {
145
+ keyFields: ['id'],
146
+ fields: {
147
+ user: {
148
+ // Ensure user references are properly merged
149
+ merge: true,
150
+ },
151
+ },
6
152
  },
7
153
  };