@messenger-box/platform-server 10.0.3-alpha.50 → 10.0.3-alpha.54
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/containers/containers.js.map +1 -1
- package/lib/graphql/resolvers/channel-member.d.ts +2 -1
- package/lib/graphql/resolvers/channel-member.js +13 -3
- package/lib/graphql/resolvers/channel-member.js.map +1 -1
- package/lib/graphql/resolvers/channel.d.ts +2 -1
- package/lib/graphql/resolvers/channel.js +260 -126
- package/lib/graphql/resolvers/channel.js.map +1 -1
- package/lib/graphql/resolvers/extended-token-account.d.ts +2 -1
- package/lib/graphql/resolvers/extended-token-account.js +90 -23
- package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
- package/lib/graphql/resolvers/post-thread.js +285 -179
- package/lib/graphql/resolvers/post-thread.js.map +1 -1
- package/lib/graphql/resolvers/post.js +669 -242
- package/lib/graphql/resolvers/post.js.map +1 -1
- package/lib/graphql/resolvers/reaction.d.ts +2 -1
- package/lib/graphql/resolvers/reaction.js +96 -14
- package/lib/graphql/resolvers/reaction.js.map +1 -1
- package/lib/graphql/schema/channel.graphql +331 -39
- package/lib/graphql/schema/channel.graphql.js +1 -1
- package/lib/graphql/schema/post-thread.graphql +157 -21
- package/lib/graphql/schema/post-thread.graphql.js +1 -1
- package/lib/graphql/schema/post.graphql +265 -40
- package/lib/graphql/schema/post.graphql.js +1 -1
- package/lib/graphql/schema/reaction.graphql +71 -13
- package/lib/graphql/schema/reaction.graphql.js +1 -1
- package/lib/graphql/schema/users.graphql +76 -13
- package/lib/graphql/schema/users.graphql.js +1 -1
- package/lib/plugins/channel-moleculer-service.d.ts +21 -1
- package/lib/plugins/channel-moleculer-service.js +417 -115
- package/lib/plugins/channel-moleculer-service.js.map +1 -1
- package/lib/plugins/extended-token-account-moleculer-service.d.ts +25 -1
- package/lib/plugins/extended-token-account-moleculer-service.js +348 -22
- package/lib/plugins/extended-token-account-moleculer-service.js.map +1 -1
- package/lib/plugins/messenger-notification-moleculer-service.d.ts +26 -3
- package/lib/plugins/messenger-notification-moleculer-service.js +403 -57
- package/lib/plugins/messenger-notification-moleculer-service.js.map +1 -1
- package/lib/plugins/post-moleculer-service.d.ts +84 -20
- package/lib/plugins/post-moleculer-service.js +891 -259
- package/lib/plugins/post-moleculer-service.js.map +1 -1
- package/lib/plugins/post-thread-moleculer-service.d.ts +33 -1
- package/lib/plugins/post-thread-moleculer-service.js +320 -13
- package/lib/plugins/post-thread-moleculer-service.js.map +1 -1
- package/lib/services/channel-service.d.ts +185 -33
- package/lib/services/channel-service.js +767 -282
- package/lib/services/channel-service.js.map +1 -1
- package/lib/services/extended-token-account-service.d.ts +127 -14
- package/lib/services/extended-token-account-service.js +459 -52
- package/lib/services/extended-token-account-service.js.map +1 -1
- package/lib/services/messenger-notification-service.d.ts +106 -13
- package/lib/services/messenger-notification-service.js +824 -442
- package/lib/services/messenger-notification-service.js.map +1 -1
- package/lib/services/post-service.d.ts +176 -16
- package/lib/services/post-service.js +553 -119
- package/lib/services/post-service.js.map +1 -1
- package/lib/services/post-thread-service.d.ts +114 -6
- package/lib/services/post-thread-service.js +397 -18
- package/lib/services/post-thread-service.js.map +1 -1
- package/lib/services/proxy-services/channel-microservice.d.ts +4 -3
- package/lib/services/proxy-services/channel-microservice.js +12 -9
- package/lib/services/proxy-services/channel-microservice.js.map +1 -1
- package/lib/services/proxy-services/messenger-notification-microservice.d.ts +128 -8
- package/lib/services/proxy-services/messenger-notification-microservice.js +324 -29
- package/lib/services/proxy-services/messenger-notification-microservice.js.map +1 -1
- package/lib/services/proxy-services/post-microservice.d.ts +186 -13
- package/lib/services/proxy-services/post-microservice.js +543 -59
- package/lib/services/proxy-services/post-microservice.js.map +1 -1
- package/lib/services/proxy-services/post-thread-microservice.d.ts +134 -4
- package/lib/services/proxy-services/post-thread-microservice.js +387 -10
- package/lib/services/proxy-services/post-thread-microservice.js.map +1 -1
- package/lib/services/proxy-services/reaction-microservice.d.ts +161 -3
- package/lib/services/proxy-services/reaction-microservice.js +474 -2
- package/lib/services/proxy-services/reaction-microservice.js.map +1 -1
- package/lib/services/reaction-service.d.ts +124 -4
- package/lib/services/reaction-service.js +415 -3
- package/lib/services/reaction-service.js.map +1 -1
- package/lib/store/models/channel.d.ts +2 -3
- package/lib/store/models/channel.js +169 -71
- package/lib/store/models/channel.js.map +1 -1
- package/lib/store/models/post-thread.d.ts +3 -3
- package/lib/store/models/post-thread.js +96 -14
- package/lib/store/models/post-thread.js.map +1 -1
- package/lib/store/models/post.d.ts +2 -3
- package/lib/store/models/post.js +85 -18
- package/lib/store/models/post.js.map +1 -1
- package/lib/store/models/reaction.d.ts +2 -3
- package/lib/store/models/reaction.js +67 -8
- package/lib/store/models/reaction.js.map +1 -1
- package/lib/store/repositories/channel-repository.d.ts +6 -6
- package/lib/store/repositories/channel-repository.js +5 -2
- package/lib/store/repositories/channel-repository.js.map +1 -1
- package/lib/store/repositories/post-repository.d.ts +6 -6
- package/lib/store/repositories/post-repository.js +5 -2
- package/lib/store/repositories/post-repository.js.map +1 -1
- package/lib/store/repositories/post-thread-repository.d.ts +6 -6
- package/lib/store/repositories/post-thread-repository.js +5 -2
- package/lib/store/repositories/post-thread-repository.js.map +1 -1
- package/lib/store/repositories/reaction-repository.d.ts +6 -6
- package/lib/store/repositories/reaction-repository.js +5 -2
- package/lib/store/repositories/reaction-repository.js.map +1 -1
- package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
- package/lib/templates/repositories/PostRepository.ts.template +3 -3
- package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
- package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
- package/lib/templates/services/ChannelService.ts.template +277 -38
- package/lib/templates/services/ExtendedTokenAccountService.ts.template +93 -8
- package/lib/templates/services/PostService.ts.template +182 -20
- package/lib/templates/services/PostThreadService.ts.template +100 -5
- package/lib/templates/services/ReactionService.ts.template +129 -2
- package/package.json +3 -3
- package/lib/store/models/common-options.js +0 -20
- package/lib/store/models/common-options.js.map +0 -1
|
@@ -9,140 +9,287 @@ const postResolvers = options => ({
|
|
|
9
9
|
}, args, {
|
|
10
10
|
fileInfoService
|
|
11
11
|
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
options.logger.trace('(FileInfo.url) url [%s]', url);
|
|
13
|
+
try {
|
|
14
|
+
if (!url) {
|
|
15
|
+
options.logger.warn('Missing URL in FileInfo');
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const basePath = fileInfoService.awsS3Service.basePath || 'aws';
|
|
19
|
+
if (!url.includes(basePath)) {
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
return fileInfoService.getResizedImage(url, {
|
|
23
|
+
width: undefined,
|
|
24
|
+
height: undefined
|
|
25
|
+
});
|
|
26
|
+
} catch (error) {
|
|
27
|
+
options.logger.error('Error getting FileInfo URL: %o', error);
|
|
28
|
+
return url; // Fallback to original URL
|
|
15
29
|
}
|
|
16
|
-
return fileInfoService.getResizedImage(url, {
|
|
17
|
-
width: undefined,
|
|
18
|
-
height: undefined
|
|
19
|
-
});
|
|
20
30
|
},
|
|
21
31
|
extension(src) {
|
|
22
|
-
|
|
32
|
+
options.logger.trace('(FileInfo.extension) mimeType [%s]', src?.mimeType);
|
|
33
|
+
try {
|
|
34
|
+
if (!src?.mimeType || typeof src.mimeType !== 'string') {
|
|
35
|
+
options.logger.warn('Missing or invalid mimeType in FileInfo');
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const parts = src.mimeType.split('/');
|
|
39
|
+
return parts.length > 1 ? parts[1] : null;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
options.logger.error('Error getting FileInfo extension: %o', error);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
23
44
|
}
|
|
24
45
|
},
|
|
25
46
|
Post: {
|
|
26
47
|
editedBy(src, args, {
|
|
27
48
|
accountService
|
|
28
49
|
}) {
|
|
29
|
-
|
|
50
|
+
options.logger.trace('(Post.editedBy) editedBy [%s]', src?.editedBy);
|
|
51
|
+
try {
|
|
52
|
+
if (!src?.editedBy) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return accountService.findAccountById(src.editedBy.toString());
|
|
56
|
+
} catch (error) {
|
|
57
|
+
options.logger.error('Error getting Post editedBy: %o', error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
30
60
|
},
|
|
31
61
|
deletedBy(src, args, {
|
|
32
62
|
accountService
|
|
33
63
|
}) {
|
|
34
|
-
|
|
64
|
+
options.logger.trace('(Post.deletedBy) deletedBy [%s]', src?.deletedBy);
|
|
65
|
+
try {
|
|
66
|
+
if (!src?.deletedBy) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return accountService.findAccountById(src.deletedBy.toString());
|
|
70
|
+
} catch (error) {
|
|
71
|
+
options.logger.error('Error getting Post deletedBy: %o', error);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
35
74
|
},
|
|
36
75
|
author(src, args, {
|
|
37
76
|
accountService
|
|
38
77
|
}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
78
|
+
options.logger.trace('(Post.author) author [%s], editedBy [%s]', src?.author, src?.editedBy);
|
|
79
|
+
try {
|
|
80
|
+
const author = src?.author?.toString();
|
|
81
|
+
if (author) {
|
|
82
|
+
return accountService.findAccountById(author);
|
|
83
|
+
}
|
|
84
|
+
// Fallback to editedBy if author is not available
|
|
85
|
+
if (src?.editedBy) {
|
|
86
|
+
return accountService.findAccountById(src.editedBy.toString());
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
options.logger.error('Error getting Post author: %o', error);
|
|
91
|
+
return null;
|
|
42
92
|
}
|
|
43
|
-
return src?.editedBy ? accountService.findAccountById(src.editedBy.toString()) : null;
|
|
44
93
|
},
|
|
45
94
|
channel(src, args, {
|
|
46
95
|
channelService
|
|
47
96
|
}) {
|
|
48
|
-
|
|
97
|
+
options.logger.trace('(Post.channel) channel [%s]', src?.channel);
|
|
98
|
+
try {
|
|
99
|
+
if (!src?.channel) {
|
|
100
|
+
options.logger.warn('Missing channel in Post');
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return channelService.get(src.channel.toString());
|
|
104
|
+
} catch (error) {
|
|
105
|
+
options.logger.error('Error getting Post channel: %o', error);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
49
108
|
},
|
|
50
109
|
props(src, _, {
|
|
51
110
|
userContext
|
|
52
111
|
}) {
|
|
53
|
-
|
|
112
|
+
options.logger.trace('(Post.props) accountId [%s]', userContext?.accountId);
|
|
113
|
+
try {
|
|
114
|
+
if (!userContext?.accountId || !src?.props) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return src.props[`[${userContext.accountId}]`] || null;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
options.logger.error('Error getting Post props: %o', error);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
54
122
|
},
|
|
55
123
|
isRead(src, _, {
|
|
56
124
|
userContext
|
|
57
125
|
}) {
|
|
58
|
-
|
|
126
|
+
options.logger.trace('(Post.isRead) accountId [%s]', userContext?.accountId);
|
|
127
|
+
try {
|
|
128
|
+
if (!userContext?.accountId || !src?.props) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isRead', false);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
options.logger.error('Error getting Post isRead: %o', error);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
59
136
|
},
|
|
60
137
|
isDelivered(src, _, {
|
|
61
138
|
userContext
|
|
62
139
|
}) {
|
|
63
|
-
|
|
140
|
+
options.logger.trace('(Post.isDelivered) accountId [%s]', userContext?.accountId);
|
|
141
|
+
try {
|
|
142
|
+
if (!userContext?.accountId || !src?.props) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isDelivered', false);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
options.logger.error('Error getting Post isDelivered: %o', error);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
64
150
|
},
|
|
65
151
|
async propsConfiguration(src, args, {
|
|
66
152
|
configurationService,
|
|
67
153
|
userContext
|
|
68
154
|
}) {
|
|
69
|
-
|
|
70
|
-
const {
|
|
71
|
-
orgName
|
|
72
|
-
} = userContext;
|
|
73
|
-
console.log('---orgName---', orgName);
|
|
74
|
-
const resource = generateResourceUri('messenger', {
|
|
75
|
-
_id: src.id,
|
|
76
|
-
orgName: orgName
|
|
77
|
-
}, 'props', DEFAULT_TENANT_ID, {
|
|
78
|
-
scheme: Scheme.CDECODE_RESOURCE
|
|
79
|
-
});
|
|
80
|
-
let data = '{}';
|
|
155
|
+
options.logger.trace('(Post.propsConfiguration) postId [%s], orgName [%s]', src?.id, userContext?.orgName);
|
|
81
156
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
157
|
+
if (!src?.id || !userContext?.orgName) {
|
|
158
|
+
options.logger.warn('Missing required data for propsConfiguration');
|
|
159
|
+
throw new Error('Missing post ID or organization name');
|
|
160
|
+
}
|
|
161
|
+
const {
|
|
162
|
+
orgName
|
|
163
|
+
} = userContext;
|
|
164
|
+
options.logger.debug('Processing propsConfiguration for orgName: %s', orgName);
|
|
165
|
+
const resource = generateResourceUri('messenger', {
|
|
166
|
+
_id: src.id,
|
|
167
|
+
orgName: orgName
|
|
168
|
+
}, 'props', DEFAULT_TENANT_ID, {
|
|
169
|
+
scheme: Scheme.CDECODE_RESOURCE
|
|
170
|
+
});
|
|
171
|
+
let data = '{}';
|
|
172
|
+
try {
|
|
173
|
+
data = JSON.stringify(src.props || {});
|
|
174
|
+
} catch (err) {
|
|
175
|
+
options.logger.warn('Error serializing props data: %o', err);
|
|
176
|
+
data = '{}';
|
|
177
|
+
}
|
|
178
|
+
const nodeContext = buildNodeContext(userContext);
|
|
179
|
+
const machineModel = await configurationService.parser(resource.toString(), data, nodeContext, null, false);
|
|
180
|
+
if (machineModel instanceof Error) {
|
|
181
|
+
options.logger.error('Error parsing configuration: %o', machineModel);
|
|
182
|
+
throw machineModel;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
resource,
|
|
186
|
+
contents: machineModel.contents,
|
|
187
|
+
overrides: machineModel.overrides,
|
|
188
|
+
keys: machineModel.keys,
|
|
189
|
+
__typename: ClientCacheTypeNames.MachineConfiguration
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
options.logger.error('Error getting Post propsConfiguration: %o', error);
|
|
193
|
+
throw error;
|
|
92
194
|
}
|
|
93
|
-
return {
|
|
94
|
-
resource,
|
|
95
|
-
contents: machineModel.contents,
|
|
96
|
-
overrides: machineModel.overrides,
|
|
97
|
-
keys: machineModel.keys,
|
|
98
|
-
__typename: ClientCacheTypeNames.MachineConfiguration
|
|
99
|
-
};
|
|
100
195
|
},
|
|
101
196
|
async files(src, args, {
|
|
102
197
|
fileInfoService
|
|
103
198
|
}) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
199
|
+
options.logger.trace('(Post.files) postId [%s], args [%j]', src?.id, args);
|
|
200
|
+
try {
|
|
201
|
+
if (!src?.id) {
|
|
202
|
+
options.logger.warn('Missing post ID for files');
|
|
203
|
+
return {
|
|
204
|
+
data: [],
|
|
205
|
+
totalCount: 0
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (!fileInfoService) {
|
|
209
|
+
options.logger.warn('FileInfoService not available');
|
|
210
|
+
return {
|
|
211
|
+
data: [],
|
|
212
|
+
totalCount: 0
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const {
|
|
216
|
+
data,
|
|
217
|
+
totalCount
|
|
218
|
+
} = await fileInfoService.getAllWithCount({
|
|
219
|
+
...args,
|
|
220
|
+
criteria: {
|
|
221
|
+
...args.criteria,
|
|
222
|
+
refType: 'Post',
|
|
223
|
+
ref: src.id
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const processedData = data.map(({
|
|
117
227
|
url,
|
|
118
228
|
...rest
|
|
119
229
|
}) => ({
|
|
120
230
|
...rest,
|
|
121
231
|
url: fileInfoService.getThumbnailImage(url)
|
|
122
|
-
}))
|
|
123
|
-
|
|
124
|
-
|
|
232
|
+
}));
|
|
233
|
+
options.logger.debug('Retrieved %d files for post %s', processedData.length, src.id);
|
|
234
|
+
return {
|
|
235
|
+
data: processedData,
|
|
236
|
+
totalCount
|
|
237
|
+
};
|
|
238
|
+
} catch (error) {
|
|
239
|
+
options.logger.error('Error getting Post files: %o', error);
|
|
240
|
+
return {
|
|
241
|
+
data: [],
|
|
242
|
+
totalCount: 0
|
|
243
|
+
};
|
|
244
|
+
}
|
|
125
245
|
},
|
|
126
246
|
async replies(src, args, {
|
|
127
247
|
postService
|
|
128
248
|
}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
sort: {
|
|
138
|
-
key: 'createdAt',
|
|
139
|
-
value: SortEnum.Desc
|
|
249
|
+
options.logger.trace('(Post.replies) postId [%s], channelId [%s]', src?.id, src?.channel);
|
|
250
|
+
try {
|
|
251
|
+
if (!src?.id || !src?.channel) {
|
|
252
|
+
options.logger.warn('Missing post ID or channel for replies');
|
|
253
|
+
return {
|
|
254
|
+
data: [],
|
|
255
|
+
totalCount: 0
|
|
256
|
+
};
|
|
140
257
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
258
|
+
if (!postService) {
|
|
259
|
+
options.logger.warn('PostService not available');
|
|
260
|
+
return {
|
|
261
|
+
data: [],
|
|
262
|
+
totalCount: 0
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const {
|
|
266
|
+
data,
|
|
267
|
+
totalCount
|
|
268
|
+
} = (await postService?.getAllWithCount({
|
|
269
|
+
criteria: {
|
|
270
|
+
channel: src.channel.toString(),
|
|
271
|
+
parentId: src.id.toString()
|
|
272
|
+
},
|
|
273
|
+
sort: {
|
|
274
|
+
key: 'createdAt',
|
|
275
|
+
value: SortEnum.Desc
|
|
276
|
+
}
|
|
277
|
+
})) ?? {
|
|
278
|
+
data: [],
|
|
279
|
+
totalCount: 0
|
|
280
|
+
};
|
|
281
|
+
options.logger.debug('Retrieved %d replies for post %s', totalCount, src.id);
|
|
282
|
+
return {
|
|
283
|
+
totalCount,
|
|
284
|
+
data
|
|
285
|
+
};
|
|
286
|
+
} catch (error) {
|
|
287
|
+
options.logger.error('Error getting Post replies: %o', error);
|
|
288
|
+
return {
|
|
289
|
+
data: [],
|
|
290
|
+
totalCount: 0
|
|
291
|
+
};
|
|
292
|
+
}
|
|
146
293
|
}
|
|
147
294
|
},
|
|
148
295
|
Query: {
|
|
@@ -156,26 +303,45 @@ const postResolvers = options => ({
|
|
|
156
303
|
postService,
|
|
157
304
|
userContext
|
|
158
305
|
}) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
sort
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
306
|
+
options.logger.trace('(Query.messages) channelId [%s], parentId [%s], limit [%d], skip [%d]', channelId, parentId, limit, skip);
|
|
307
|
+
try {
|
|
308
|
+
if (!channelId) {
|
|
309
|
+
options.logger.warn('Missing channelId in messages query');
|
|
310
|
+
throw new Error('Channel ID is required');
|
|
311
|
+
}
|
|
312
|
+
if (!userContext?.accountId) {
|
|
313
|
+
options.logger.warn('Missing user context in messages query');
|
|
314
|
+
throw new Error('User authentication required');
|
|
315
|
+
}
|
|
316
|
+
if (!postService) {
|
|
317
|
+
options.logger.warn('PostService not available');
|
|
318
|
+
throw new Error('Post service unavailable');
|
|
319
|
+
}
|
|
320
|
+
const sortBy = sort || {
|
|
321
|
+
key: 'createdAt',
|
|
322
|
+
value: SortEnum.Desc
|
|
323
|
+
};
|
|
324
|
+
const {
|
|
325
|
+
data,
|
|
326
|
+
totalCount
|
|
327
|
+
} = await postService.getAllWithCount({
|
|
328
|
+
criteria: {
|
|
329
|
+
channel: channelId,
|
|
330
|
+
parentId
|
|
331
|
+
},
|
|
332
|
+
limit,
|
|
333
|
+
skip,
|
|
334
|
+
sort: sortBy
|
|
335
|
+
});
|
|
336
|
+
options.logger.debug('Retrieved %d messages for channel %s', totalCount, channelId);
|
|
337
|
+
return {
|
|
338
|
+
totalCount,
|
|
339
|
+
data
|
|
340
|
+
};
|
|
341
|
+
} catch (error) {
|
|
342
|
+
options.logger.error('Error in messages query: %o', error);
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
179
345
|
},
|
|
180
346
|
async publicMessages(src, {
|
|
181
347
|
channelId
|
|
@@ -183,23 +349,38 @@ const postResolvers = options => ({
|
|
|
183
349
|
postService,
|
|
184
350
|
userContext
|
|
185
351
|
}) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
key: 'createdAt',
|
|
196
|
-
value: SortEnum.Desc
|
|
352
|
+
options.logger.trace('(Query.publicMessages) channelId [%s]', channelId);
|
|
353
|
+
try {
|
|
354
|
+
if (!channelId) {
|
|
355
|
+
options.logger.warn('Missing channelId in publicMessages query');
|
|
356
|
+
throw new Error('Channel ID is required');
|
|
357
|
+
}
|
|
358
|
+
if (!postService) {
|
|
359
|
+
options.logger.warn('PostService not available');
|
|
360
|
+
throw new Error('Post service unavailable');
|
|
197
361
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
362
|
+
const {
|
|
363
|
+
data,
|
|
364
|
+
totalCount
|
|
365
|
+
} = await postService.getAllWithCount({
|
|
366
|
+
criteria: {
|
|
367
|
+
channel: channelId,
|
|
368
|
+
type: PostTypeEnum.Public
|
|
369
|
+
},
|
|
370
|
+
sort: {
|
|
371
|
+
key: 'createdAt',
|
|
372
|
+
value: SortEnum.Desc
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
options.logger.debug('Retrieved %d public messages for channel %s', totalCount, channelId);
|
|
376
|
+
return {
|
|
377
|
+
totalCount,
|
|
378
|
+
data
|
|
379
|
+
};
|
|
380
|
+
} catch (error) {
|
|
381
|
+
options.logger.error('Error in publicMessages query: %o', error);
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
203
384
|
}
|
|
204
385
|
},
|
|
205
386
|
Mutation: {
|
|
@@ -208,14 +389,29 @@ const postResolvers = options => ({
|
|
|
208
389
|
}, {
|
|
209
390
|
postService
|
|
210
391
|
}) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
messageId
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
392
|
+
options.logger.trace('(Mutation.deleteMessage) messageId [%j]', messageId);
|
|
393
|
+
try {
|
|
394
|
+
if (!messageId?.channelId || !messageId?.messageId) {
|
|
395
|
+
options.logger.warn('Missing required messageId parameters');
|
|
396
|
+
throw new Error('Channel ID and Message ID are required');
|
|
397
|
+
}
|
|
398
|
+
if (!postService) {
|
|
399
|
+
options.logger.warn('PostService not available');
|
|
400
|
+
throw new Error('Post service unavailable');
|
|
401
|
+
}
|
|
402
|
+
const {
|
|
403
|
+
channelId,
|
|
404
|
+
messageId: id
|
|
405
|
+
} = messageId;
|
|
406
|
+
options.logger.debug('Deleting message %s from channel %s', id, channelId);
|
|
407
|
+
return postService.delete({
|
|
408
|
+
channel: channelId,
|
|
409
|
+
id
|
|
410
|
+
});
|
|
411
|
+
} catch (error) {
|
|
412
|
+
options.logger.error('Error deleting message: %o', error);
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
219
415
|
},
|
|
220
416
|
editMessage(src, {
|
|
221
417
|
messageId,
|
|
@@ -224,12 +420,35 @@ const postResolvers = options => ({
|
|
|
224
420
|
postService,
|
|
225
421
|
userContext
|
|
226
422
|
}) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
423
|
+
options.logger.trace('(Mutation.editMessage) messageId [%j], content length [%d]', messageId, messageInput?.content?.length || 0);
|
|
424
|
+
try {
|
|
425
|
+
if (!messageId?.messageId || !messageId?.channelId) {
|
|
426
|
+
options.logger.warn('Missing required messageId parameters');
|
|
427
|
+
throw new Error('Message ID and Channel ID are required');
|
|
428
|
+
}
|
|
429
|
+
if (!messageInput?.content) {
|
|
430
|
+
options.logger.warn('Missing message content');
|
|
431
|
+
throw new Error('Message content is required');
|
|
432
|
+
}
|
|
433
|
+
if (!userContext?.accountId) {
|
|
434
|
+
options.logger.warn('Missing user context');
|
|
435
|
+
throw new Error('User authentication required');
|
|
436
|
+
}
|
|
437
|
+
if (!postService) {
|
|
438
|
+
options.logger.warn('PostService not available');
|
|
439
|
+
throw new Error('Post service unavailable');
|
|
440
|
+
}
|
|
441
|
+
options.logger.debug('Editing message %s in channel %s', messageId.messageId, messageId.channelId);
|
|
442
|
+
return postService.update(messageId.messageId, {
|
|
443
|
+
message: messageInput.content,
|
|
444
|
+
editedBy: userContext.accountId,
|
|
445
|
+
channel: messageId.channelId,
|
|
446
|
+
files: messageInput.files
|
|
447
|
+
});
|
|
448
|
+
} catch (error) {
|
|
449
|
+
options.logger.error('Error editing message: %o', error);
|
|
450
|
+
throw error;
|
|
451
|
+
}
|
|
233
452
|
},
|
|
234
453
|
async sendMessage(src, {
|
|
235
454
|
channelId,
|
|
@@ -239,30 +458,34 @@ const postResolvers = options => ({
|
|
|
239
458
|
postService,
|
|
240
459
|
userContext
|
|
241
460
|
}) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
461
|
+
options.logger.trace('(Mutation.sendMessage) channelId [%s], postId [%s], content length [%d]', channelId, postId, messageInput?.content?.length || 0);
|
|
462
|
+
try {
|
|
463
|
+
if (!channelId) {
|
|
464
|
+
options.logger.warn('Missing channelId');
|
|
465
|
+
throw new Error('Channel ID is required');
|
|
466
|
+
}
|
|
467
|
+
if (!messageInput?.content) {
|
|
468
|
+
options.logger.warn('Missing message content');
|
|
469
|
+
throw new Error('Message content is required');
|
|
470
|
+
}
|
|
471
|
+
if (!userContext?.accountId) {
|
|
472
|
+
options.logger.warn('Missing user context');
|
|
473
|
+
throw new Error('User authentication required');
|
|
474
|
+
}
|
|
475
|
+
if (!postService) {
|
|
476
|
+
options.logger.warn('PostService not available');
|
|
477
|
+
throw new Error('Post service unavailable');
|
|
478
|
+
}
|
|
479
|
+
const {
|
|
480
|
+
content,
|
|
259
481
|
files,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
482
|
+
createdBy,
|
|
483
|
+
notificationParams
|
|
484
|
+
} = messageInput;
|
|
485
|
+
const {
|
|
486
|
+
accountId
|
|
487
|
+
} = userContext;
|
|
488
|
+
const postData = {
|
|
266
489
|
channel: channelId,
|
|
267
490
|
message: content,
|
|
268
491
|
editedBy: createdBy || accountId,
|
|
@@ -271,17 +494,24 @@ const postResolvers = options => ({
|
|
|
271
494
|
props: notificationParams ? {
|
|
272
495
|
notificationParams
|
|
273
496
|
} : undefined
|
|
274
|
-
}
|
|
497
|
+
};
|
|
498
|
+
let post;
|
|
499
|
+
if (postId) {
|
|
500
|
+
options.logger.debug('Creating message with specific ID %s', postId);
|
|
501
|
+
post = await postService.create({
|
|
502
|
+
_id: postId,
|
|
503
|
+
...postData
|
|
504
|
+
});
|
|
505
|
+
} else {
|
|
506
|
+
options.logger.debug('Creating new message in channel %s', channelId);
|
|
507
|
+
post = await postService.create(postData);
|
|
508
|
+
}
|
|
509
|
+
options.logger.debug('Message created successfully with ID %s', post?.id || post?._id);
|
|
510
|
+
return post;
|
|
511
|
+
} catch (error) {
|
|
512
|
+
options.logger.error('Error sending message: %o', error);
|
|
513
|
+
throw error;
|
|
275
514
|
}
|
|
276
|
-
// const post = await postService.create({
|
|
277
|
-
// channel: channelId as any,
|
|
278
|
-
// message: content,
|
|
279
|
-
// editedBy: accountId as any,
|
|
280
|
-
// author: accountId as any,
|
|
281
|
-
// files,
|
|
282
|
-
// });
|
|
283
|
-
// options.pubsub.publish(`POST_CREATED.${channelId}`, post);
|
|
284
|
-
return post;
|
|
285
515
|
},
|
|
286
516
|
async sendPublicMessage(src, {
|
|
287
517
|
channelId,
|
|
@@ -292,46 +522,71 @@ const postResolvers = options => ({
|
|
|
292
522
|
channelService,
|
|
293
523
|
userContext
|
|
294
524
|
}) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
525
|
+
options.logger.trace('(Mutation.sendPublicMessage) channelId [%s], postId [%s]', channelId, postId);
|
|
526
|
+
try {
|
|
527
|
+
if (!channelId) {
|
|
528
|
+
options.logger.warn('Missing channelId');
|
|
529
|
+
throw new Error('Channel ID is required');
|
|
530
|
+
}
|
|
531
|
+
if (!messageInput?.content) {
|
|
532
|
+
options.logger.warn('Missing message content');
|
|
533
|
+
throw new Error('Message content is required');
|
|
534
|
+
}
|
|
535
|
+
if (!userContext?.accountId) {
|
|
536
|
+
options.logger.warn('Missing user context');
|
|
537
|
+
throw new Error('User authentication required');
|
|
538
|
+
}
|
|
539
|
+
if (!postService || !channelService) {
|
|
540
|
+
options.logger.warn('Required services not available');
|
|
541
|
+
throw new Error('Required services unavailable');
|
|
542
|
+
}
|
|
543
|
+
const {
|
|
544
|
+
content,
|
|
545
|
+
files,
|
|
546
|
+
createdBy
|
|
547
|
+
} = messageInput;
|
|
548
|
+
const {
|
|
549
|
+
accountId
|
|
550
|
+
} = userContext;
|
|
551
|
+
let post = null;
|
|
552
|
+
const channelExists = await channelService.get(channelId);
|
|
553
|
+
if (!channelExists) {
|
|
554
|
+
options.logger.debug('Creating public channel %s', channelId);
|
|
555
|
+
const channel = await channelService.savePublicChannel({
|
|
556
|
+
_id: channelId,
|
|
557
|
+
type: RoomType.Public,
|
|
558
|
+
title: `public-channel-${channelId}`
|
|
320
559
|
});
|
|
560
|
+
if (!channel) {
|
|
561
|
+
options.logger.error('Failed to create public channel %s', channelId);
|
|
562
|
+
throw new Error('Failed to create public channel');
|
|
563
|
+
}
|
|
321
564
|
}
|
|
322
|
-
|
|
323
|
-
post = await postService.createWithoutSubscription({
|
|
324
|
-
_id: postId || undefined,
|
|
565
|
+
const postData = {
|
|
325
566
|
channel: channelId,
|
|
326
567
|
message: content,
|
|
327
568
|
editedBy: createdBy || accountId,
|
|
328
569
|
author: createdBy || accountId,
|
|
329
570
|
files,
|
|
330
571
|
type: PostTypeEnum.Public
|
|
331
|
-
}
|
|
572
|
+
};
|
|
573
|
+
if (postId) {
|
|
574
|
+
post = await postService.createWithoutSubscription({
|
|
575
|
+
_id: postId,
|
|
576
|
+
...postData
|
|
577
|
+
});
|
|
578
|
+
} else {
|
|
579
|
+
post = await postService.createWithoutSubscription(postData);
|
|
580
|
+
}
|
|
581
|
+
if (post) {
|
|
582
|
+
options.logger.debug('Publishing public post created event for channel %s', channelId);
|
|
583
|
+
options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
|
|
584
|
+
}
|
|
585
|
+
return post;
|
|
586
|
+
} catch (error) {
|
|
587
|
+
options.logger.error('Error sending public message: %o', error);
|
|
588
|
+
throw error;
|
|
332
589
|
}
|
|
333
|
-
if (post) options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
|
|
334
|
-
return post;
|
|
335
590
|
},
|
|
336
591
|
async sendExpoNotificationOnPost(_, {
|
|
337
592
|
postId,
|
|
@@ -341,9 +596,29 @@ const postResolvers = options => ({
|
|
|
341
596
|
postService,
|
|
342
597
|
userContext
|
|
343
598
|
}) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
599
|
+
options.logger.trace('(Mutation.sendExpoNotificationOnPost) postId [%s]', postId);
|
|
600
|
+
try {
|
|
601
|
+
if (!postId) {
|
|
602
|
+
options.logger.warn('Missing postId');
|
|
603
|
+
throw new Error('Post ID is required');
|
|
604
|
+
}
|
|
605
|
+
if (!messengerNotificationService || !postService) {
|
|
606
|
+
options.logger.warn('Required services not available');
|
|
607
|
+
throw new Error('Required services unavailable');
|
|
608
|
+
}
|
|
609
|
+
const post = await postService.get(postId.toString());
|
|
610
|
+
if (!post) {
|
|
611
|
+
options.logger.warn('Post not found: %s', postId);
|
|
612
|
+
throw new Error('Post not found');
|
|
613
|
+
}
|
|
614
|
+
options.logger.debug('Sending expo notification for post %s', postId);
|
|
615
|
+
const result = await messengerNotificationService.sendExpoNotificationOnPost(post, notificationData);
|
|
616
|
+
options.logger.debug('Expo notification sent successfully for post %s', postId);
|
|
617
|
+
return result;
|
|
618
|
+
} catch (error) {
|
|
619
|
+
options.logger.error('Error sending expo notification: %o', error);
|
|
620
|
+
throw error;
|
|
621
|
+
}
|
|
347
622
|
},
|
|
348
623
|
createMessageFileUploadLink(_, {
|
|
349
624
|
postId,
|
|
@@ -352,7 +627,25 @@ const postResolvers = options => ({
|
|
|
352
627
|
postService,
|
|
353
628
|
userContext
|
|
354
629
|
}) {
|
|
355
|
-
|
|
630
|
+
options.logger.trace('(Mutation.createMessageFileUploadLink) postId [%s], filename [%s]', postId, filename);
|
|
631
|
+
try {
|
|
632
|
+
if (!postId || !filename) {
|
|
633
|
+
options.logger.warn('Missing postId or filename');
|
|
634
|
+
throw new Error('Post ID and filename are required');
|
|
635
|
+
}
|
|
636
|
+
if (!userContext?.accountId) {
|
|
637
|
+
options.logger.warn('Missing user context');
|
|
638
|
+
throw new Error('User authentication required');
|
|
639
|
+
}
|
|
640
|
+
if (!postService) {
|
|
641
|
+
options.logger.warn('PostService not available');
|
|
642
|
+
throw new Error('Post service unavailable');
|
|
643
|
+
}
|
|
644
|
+
return postService.createFileUploadLink(postId, filename, userContext.accountId);
|
|
645
|
+
} catch (error) {
|
|
646
|
+
options.logger.error('Error creating file upload link: %o', error);
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
356
649
|
},
|
|
357
650
|
attachUploadedFileToMessage(_, {
|
|
358
651
|
postId,
|
|
@@ -361,7 +654,25 @@ const postResolvers = options => ({
|
|
|
361
654
|
postService,
|
|
362
655
|
userContext
|
|
363
656
|
}) {
|
|
364
|
-
|
|
657
|
+
options.logger.trace('(Mutation.attachUploadedFileToMessage) postId [%s], filename [%s]', postId, file?.name);
|
|
658
|
+
try {
|
|
659
|
+
if (!postId || !file) {
|
|
660
|
+
options.logger.warn('Missing postId or file');
|
|
661
|
+
throw new Error('Post ID and file are required');
|
|
662
|
+
}
|
|
663
|
+
if (!userContext?.accountId) {
|
|
664
|
+
options.logger.warn('Missing user context');
|
|
665
|
+
throw new Error('User authentication required');
|
|
666
|
+
}
|
|
667
|
+
if (!postService) {
|
|
668
|
+
options.logger.warn('PostService not available');
|
|
669
|
+
throw new Error('Post service unavailable');
|
|
670
|
+
}
|
|
671
|
+
return postService.attachUploadedFile(postId, file, userContext.accountId);
|
|
672
|
+
} catch (error) {
|
|
673
|
+
options.logger.error('Error attaching uploaded file: %o', error);
|
|
674
|
+
throw error;
|
|
675
|
+
}
|
|
365
676
|
},
|
|
366
677
|
async createMessageFilesUploadLink(_, {
|
|
367
678
|
postId,
|
|
@@ -370,7 +681,25 @@ const postResolvers = options => ({
|
|
|
370
681
|
postService,
|
|
371
682
|
userContext
|
|
372
683
|
}) {
|
|
373
|
-
|
|
684
|
+
options.logger.trace('(Mutation.createMessageFilesUploadLink) postId [%s], fileCount [%d]', postId, filenames?.length || 0);
|
|
685
|
+
try {
|
|
686
|
+
if (!postId || !filenames || !Array.isArray(filenames) || filenames.length === 0) {
|
|
687
|
+
options.logger.warn('Missing postId or filenames');
|
|
688
|
+
throw new Error('Post ID and filenames array are required');
|
|
689
|
+
}
|
|
690
|
+
if (!userContext?.accountId) {
|
|
691
|
+
options.logger.warn('Missing user context');
|
|
692
|
+
throw new Error('User authentication required');
|
|
693
|
+
}
|
|
694
|
+
if (!postService) {
|
|
695
|
+
options.logger.warn('PostService not available');
|
|
696
|
+
throw new Error('Post service unavailable');
|
|
697
|
+
}
|
|
698
|
+
return postService.createFilesUploadLink(postId, filenames, userContext.accountId);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
options.logger.error('Error creating files upload links: %o', error);
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
374
703
|
},
|
|
375
704
|
async attachUploadedFilesToMessage(_, {
|
|
376
705
|
postId,
|
|
@@ -379,14 +708,46 @@ const postResolvers = options => ({
|
|
|
379
708
|
postService,
|
|
380
709
|
userContext
|
|
381
710
|
}) {
|
|
382
|
-
|
|
711
|
+
options.logger.trace('(Mutation.attachUploadedFilesToMessage) postId [%s], fileCount [%d]', postId, files?.length || 0);
|
|
712
|
+
try {
|
|
713
|
+
if (!postId || !files || !Array.isArray(files) || files.length === 0) {
|
|
714
|
+
options.logger.warn('Missing postId or files');
|
|
715
|
+
throw new Error('Post ID and files array are required');
|
|
716
|
+
}
|
|
717
|
+
if (!userContext?.accountId) {
|
|
718
|
+
options.logger.warn('Missing user context');
|
|
719
|
+
throw new Error('User authentication required');
|
|
720
|
+
}
|
|
721
|
+
if (!postService) {
|
|
722
|
+
options.logger.warn('PostService not available');
|
|
723
|
+
throw new Error('Post service unavailable');
|
|
724
|
+
}
|
|
725
|
+
return postService.attachUploadedFiles(postId, files, userContext.accountId);
|
|
726
|
+
} catch (error) {
|
|
727
|
+
options.logger.error('Error attaching uploaded files: %o', error);
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
383
730
|
},
|
|
384
731
|
deleteMessageFile(_, {
|
|
385
732
|
url
|
|
386
733
|
}, {
|
|
387
734
|
postService
|
|
388
735
|
}) {
|
|
389
|
-
|
|
736
|
+
options.logger.trace('(Mutation.deleteMessageFile) url [%s]', url);
|
|
737
|
+
try {
|
|
738
|
+
if (!url) {
|
|
739
|
+
options.logger.warn('Missing URL');
|
|
740
|
+
throw new Error('File URL is required');
|
|
741
|
+
}
|
|
742
|
+
if (!postService) {
|
|
743
|
+
options.logger.warn('PostService not available');
|
|
744
|
+
throw new Error('Post service unavailable');
|
|
745
|
+
}
|
|
746
|
+
return postService.deleteFile(url);
|
|
747
|
+
} catch (error) {
|
|
748
|
+
options.logger.error('Error deleting message file: %o', error);
|
|
749
|
+
throw error;
|
|
750
|
+
}
|
|
390
751
|
},
|
|
391
752
|
async readMessage(src, {
|
|
392
753
|
messageId
|
|
@@ -395,11 +756,30 @@ const postResolvers = options => ({
|
|
|
395
756
|
userContext,
|
|
396
757
|
channelService
|
|
397
758
|
}) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
759
|
+
options.logger.trace('(Mutation.readMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
|
|
760
|
+
try {
|
|
761
|
+
if (!messageId?.channelId || !messageId?.messageId) {
|
|
762
|
+
options.logger.warn('Missing messageId parameters');
|
|
763
|
+
throw new GraphQLError('Message ID and Channel ID are required');
|
|
764
|
+
}
|
|
765
|
+
if (!userContext?.accountId) {
|
|
766
|
+
options.logger.warn('Missing user context');
|
|
767
|
+
throw new GraphQLError('User authentication required');
|
|
768
|
+
}
|
|
769
|
+
if (!postService || !channelService) {
|
|
770
|
+
options.logger.warn('Required services not available');
|
|
771
|
+
throw new GraphQLError('Required services unavailable');
|
|
772
|
+
}
|
|
773
|
+
const member = await channelService.isMember(messageId.channelId, userContext.accountId);
|
|
774
|
+
if (!member) {
|
|
775
|
+
options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
|
|
776
|
+
throw new GraphQLError('Message does not belong to user');
|
|
777
|
+
}
|
|
778
|
+
return postService.readMessage(messageId, userContext.accountId);
|
|
779
|
+
} catch (error) {
|
|
780
|
+
options.logger.error('Error reading message: %o', error);
|
|
781
|
+
throw error;
|
|
401
782
|
}
|
|
402
|
-
return postService.readMessage(messageId, userContext.accountId);
|
|
403
783
|
},
|
|
404
784
|
async deliverMessage(src, {
|
|
405
785
|
messageId
|
|
@@ -408,70 +788,117 @@ const postResolvers = options => ({
|
|
|
408
788
|
userContext,
|
|
409
789
|
channelService
|
|
410
790
|
}) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
791
|
+
options.logger.trace('(Mutation.deliverMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
|
|
792
|
+
try {
|
|
793
|
+
if (!messageId?.channelId || !messageId?.messageId) {
|
|
794
|
+
options.logger.warn('Missing messageId parameters');
|
|
795
|
+
throw new GraphQLError('Message ID and Channel ID are required');
|
|
796
|
+
}
|
|
797
|
+
if (!userContext?.accountId) {
|
|
798
|
+
options.logger.warn('Missing user context');
|
|
799
|
+
throw new GraphQLError('User authentication required');
|
|
800
|
+
}
|
|
801
|
+
if (!postService || !channelService) {
|
|
802
|
+
options.logger.warn('Required services not available');
|
|
803
|
+
throw new GraphQLError('Required services unavailable');
|
|
804
|
+
}
|
|
805
|
+
const member = await channelService.isMember(messageId.channelId, userContext.accountId);
|
|
806
|
+
if (!member) {
|
|
807
|
+
options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
|
|
808
|
+
throw new GraphQLError('Message does not belong to user');
|
|
809
|
+
}
|
|
810
|
+
return postService.deliverMessage(messageId, userContext.accountId);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
options.logger.error('Error delivering message: %o', error);
|
|
813
|
+
throw error;
|
|
414
814
|
}
|
|
415
|
-
return postService.deliverMessage(messageId, userContext.accountId);
|
|
416
815
|
},
|
|
417
|
-
// uploadFile(src, { files, postId }, { fileInfoService, userContext }) {
|
|
418
|
-
// const res = [];
|
|
419
|
-
// files.map((file) =>
|
|
420
|
-
// res.push(
|
|
421
|
-
// fileInfoService.create({
|
|
422
|
-
// refType: FileRefType.Post as never,
|
|
423
|
-
// file,
|
|
424
|
-
// createdBy: userContext.accountId,
|
|
425
|
-
// ref: postId,
|
|
426
|
-
// }),
|
|
427
|
-
// ),
|
|
428
|
-
// );
|
|
429
|
-
// return res;
|
|
430
|
-
// },
|
|
431
816
|
async TestchatMessage(src, {
|
|
432
817
|
channelId
|
|
433
818
|
}, context) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
819
|
+
options.logger.trace('(Mutation.TestchatMessage) channelId [%s]', channelId);
|
|
820
|
+
try {
|
|
821
|
+
if (!channelId) {
|
|
822
|
+
options.logger.warn('Missing channelId');
|
|
823
|
+
throw new Error('Channel ID is required');
|
|
824
|
+
}
|
|
825
|
+
const testData = {
|
|
439
826
|
channelId,
|
|
440
827
|
orgName: 'upadhyaytarun'
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
828
|
+
};
|
|
829
|
+
options.logger.debug('Publishing test chat message for channel %s', channelId);
|
|
830
|
+
options.pubsub.publish(`CHAT_CREATED.${channelId}`, {
|
|
831
|
+
chatMessageTest: testData
|
|
832
|
+
});
|
|
833
|
+
return testData;
|
|
834
|
+
} catch (error) {
|
|
835
|
+
options.logger.error('Error in TestchatMessage: %o', error);
|
|
836
|
+
throw error;
|
|
837
|
+
}
|
|
447
838
|
}
|
|
448
839
|
},
|
|
449
840
|
Subscription: {
|
|
450
841
|
chatMessageAdded: {
|
|
451
|
-
// More on pubsub below
|
|
452
842
|
subscribe: (_, {
|
|
453
843
|
channelId,
|
|
454
844
|
directTo
|
|
455
845
|
}) => {
|
|
456
|
-
|
|
846
|
+
options.logger.trace('(Subscription.chatMessageAdded) channelId [%s], directTo [%s]', channelId, directTo);
|
|
847
|
+
try {
|
|
848
|
+
if (!channelId) {
|
|
849
|
+
throw new Error('Channel ID is required for subscription');
|
|
850
|
+
}
|
|
851
|
+
return options.pubsub.asyncIterator([`POST_CREATED.${channelId}`]);
|
|
852
|
+
} catch (error) {
|
|
853
|
+
options.logger.error('Error subscribing to chatMessageAdded: %o', error);
|
|
854
|
+
throw error;
|
|
855
|
+
}
|
|
457
856
|
},
|
|
458
|
-
resolve: payload =>
|
|
857
|
+
resolve: payload => {
|
|
858
|
+
options.logger.trace('(Subscription.chatMessageAdded.resolve) payload received');
|
|
859
|
+
return payload;
|
|
860
|
+
}
|
|
459
861
|
},
|
|
460
862
|
chatMessageTest: {
|
|
461
|
-
// More on pubsub below
|
|
462
863
|
subscribe: (_, {
|
|
463
864
|
channelId,
|
|
464
865
|
directTo
|
|
465
866
|
}) => {
|
|
466
|
-
|
|
867
|
+
options.logger.trace('(Subscription.chatMessageTest) channelId [%s], directTo [%s]', channelId, directTo);
|
|
868
|
+
try {
|
|
869
|
+
if (!channelId) {
|
|
870
|
+
throw new Error('Channel ID is required for subscription');
|
|
871
|
+
}
|
|
872
|
+
return options.pubsub.asyncIterator([`CHAT_CREATED.${channelId}`]);
|
|
873
|
+
} catch (error) {
|
|
874
|
+
options.logger.error('Error subscribing to chatMessageTest: %o', error);
|
|
875
|
+
throw error;
|
|
876
|
+
}
|
|
467
877
|
},
|
|
468
|
-
resolve: payload =>
|
|
878
|
+
resolve: payload => {
|
|
879
|
+
options.logger.trace('(Subscription.chatMessageTest.resolve) payload received');
|
|
880
|
+
return payload;
|
|
881
|
+
}
|
|
469
882
|
},
|
|
470
883
|
publicPostAdded: {
|
|
471
884
|
subscribe: (_, {
|
|
472
885
|
channelId
|
|
473
|
-
}) =>
|
|
474
|
-
|
|
886
|
+
}) => {
|
|
887
|
+
options.logger.trace('(Subscription.publicPostAdded) channelId [%s]', channelId);
|
|
888
|
+
try {
|
|
889
|
+
if (!channelId) {
|
|
890
|
+
throw new Error('Channel ID is required for subscription');
|
|
891
|
+
}
|
|
892
|
+
return options.pubsub.asyncIterator([`PUBLIC_POST_CREATED.${channelId}`]);
|
|
893
|
+
} catch (error) {
|
|
894
|
+
options.logger.error('Error subscribing to publicPostAdded: %o', error);
|
|
895
|
+
throw error;
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
resolve: payload => {
|
|
899
|
+
options.logger.trace('(Subscription.publicPostAdded.resolve) payload received');
|
|
900
|
+
return payload;
|
|
901
|
+
}
|
|
475
902
|
}
|
|
476
903
|
}
|
|
477
904
|
});export{postResolvers};//# sourceMappingURL=post.js.map
|