* Member remote changeset update record subscriptions * @param remoteChangeset
(remoteChangeset: IRemoteChangeset)
| 217 | * @param remoteChangeset |
| 218 | */ |
| 219 | handleSubscriptions(remoteChangeset: IRemoteChangeset) { |
| 220 | let hasCreatedFieldWithSubscription = false; |
| 221 | let otherCmdTriggerSubscription = false; |
| 222 | |
| 223 | const fieldMap = getFieldMap(this.getState(), this.resourceId); |
| 224 | remoteChangeset.operations.forEach(op => { |
| 225 | // AddRecords |
| 226 | if (op.cmd === CollaCommandName.AddRecords) { |
| 227 | if (fieldMap && Object.values(fieldMap).some(field => field.type === FieldType.CreatedBy && field.property.subscription)) { |
| 228 | hasCreatedFieldWithSubscription = true; |
| 229 | return; |
| 230 | } |
| 231 | } else { |
| 232 | // other command |
| 233 | op.actions.map(action => { |
| 234 | const path = testPath(action.p, ['recordMap', ':recordId', 'data', ':fieldId']); |
| 235 | if (path.pass) { |
| 236 | const field = fieldMap?.[path.fieldId]; |
| 237 | if (field?.type === FieldType.Member && Boolean(field.property.subscription)) { |
| 238 | otherCmdTriggerSubscription = true; |
| 239 | return; |
| 240 | } |
| 241 | } |
| 242 | }); |
| 243 | } |
| 244 | }); |
| 245 | |
| 246 | if (hasCreatedFieldWithSubscription || otherCmdTriggerSubscription) { |
| 247 | this.dispatch(getSubscriptionsAction(this.resourceId)); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * The submitted changeset is accepted by the service |
no test coverage detected