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