|
1 | 1 | import { POST_ACTION_SUCCEEDED } from '../types';
|
2 | 2 | import { POST_ACTION_CHANNEL } from '../config/channels';
|
| 3 | +import { |
| 4 | + DEFAULT_ACTIONS_AS_ENABLED, |
| 5 | + DEFAULT_GEOLOCATION_ENABLED, |
| 6 | +} from '../config/constants'; |
3 | 7 |
|
4 | 8 | const postAction = async (
|
5 | 9 | {
|
6 |
| - userId, |
| 10 | + userId: actionUserId, |
7 | 11 | appInstanceId,
|
8 | 12 | spaceId,
|
9 | 13 | subSpaceId,
|
10 | 14 | format,
|
11 | 15 | data,
|
12 | 16 | verb,
|
13 |
| - geolocation, |
14 | 17 | visibility,
|
15 | 18 | } = {},
|
| 19 | + user, |
16 | 20 | callback
|
17 | 21 | ) => () => {
|
18 | 22 | try {
|
19 |
| - window.ipcRenderer.send(POST_ACTION_CHANNEL, { |
20 |
| - userId, |
21 |
| - appInstanceId, |
22 |
| - spaceId, |
23 |
| - subSpaceId, |
24 |
| - format, |
25 |
| - data, |
26 |
| - verb, |
| 23 | + const mutableUser = user.toJS(); |
| 24 | + const { |
| 25 | + id, |
| 26 | + settings: { |
| 27 | + actionsEnabled = DEFAULT_ACTIONS_AS_ENABLED, |
| 28 | + geolocationEnabled = DEFAULT_GEOLOCATION_ENABLED, |
| 29 | + }, |
27 | 30 | geolocation,
|
28 |
| - visibility, |
29 |
| - }); |
| 31 | + } = mutableUser; |
30 | 32 |
|
31 |
| - window.ipcRenderer.once( |
32 |
| - `${POST_ACTION_CHANNEL}_${appInstanceId}`, |
33 |
| - async (event, response) => { |
34 |
| - callback({ |
35 |
| - // have to include the appInstanceId to avoid broadcasting |
36 |
| - appInstanceId, |
37 |
| - type: POST_ACTION_SUCCEEDED, |
38 |
| - payload: response, |
39 |
| - }); |
| 33 | + if (actionsEnabled) { |
| 34 | + // get user id |
| 35 | + let userId = actionUserId; |
| 36 | + if (!actionUserId) { |
| 37 | + userId = id; |
40 | 38 | }
|
41 |
| - ); |
| 39 | + |
| 40 | + // add geolocation to action if enabled |
| 41 | + let geolocationLatLong = null; |
| 42 | + if (geolocationEnabled) { |
| 43 | + const { latitude, longitude } = geolocation; |
| 44 | + geolocationLatLong = { ll: [latitude, longitude] }; |
| 45 | + } |
| 46 | + |
| 47 | + window.ipcRenderer.send(POST_ACTION_CHANNEL, { |
| 48 | + userId, |
| 49 | + appInstanceId, |
| 50 | + spaceId, |
| 51 | + subSpaceId, |
| 52 | + format, |
| 53 | + data, |
| 54 | + verb, |
| 55 | + geolocation: geolocationLatLong, |
| 56 | + visibility, |
| 57 | + }); |
| 58 | + |
| 59 | + // if action from app, wait in app channel |
| 60 | + if (appInstanceId) { |
| 61 | + window.ipcRenderer.once( |
| 62 | + `${POST_ACTION_CHANNEL}_${appInstanceId}`, |
| 63 | + async (event, response) => { |
| 64 | + callback({ |
| 65 | + // have to include the appInstanceId to avoid broadcasting |
| 66 | + appInstanceId, |
| 67 | + type: POST_ACTION_SUCCEEDED, |
| 68 | + payload: response, |
| 69 | + }); |
| 70 | + } |
| 71 | + ); |
| 72 | + } |
| 73 | + } |
42 | 74 | } catch (err) {
|
43 | 75 | // do nothing
|
44 | 76 | }
|
|
0 commit comments