@amityco/ts-sdk 0.0.1-beta.24 → 0.0.1-beta.25
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/dist/@types/core/events.d.ts +5 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +181 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +177 -4
- package/dist/index.umd.js +5 -5
- package/dist/poll/api/closePoll.d.ts.map +1 -1
- package/dist/poll/api/deletePoll.d.ts.map +1 -1
- package/dist/poll/api/votePoll.d.ts.map +1 -1
- package/dist/poll/events/index.d.ts +3 -0
- package/dist/poll/events/index.d.ts.map +1 -0
- package/dist/poll/events/onPollDeleted.d.ts +17 -0
- package/dist/poll/events/onPollDeleted.d.ts.map +1 -0
- package/dist/poll/events/onPollUpdated.d.ts +17 -0
- package/dist/poll/events/onPollUpdated.d.ts.map +1 -0
- package/dist/poll/observers/index.d.ts +2 -0
- package/dist/poll/observers/index.d.ts.map +1 -0
- package/dist/poll/observers/observePoll.d.ts +18 -0
- package/dist/poll/observers/observePoll.d.ts.map +1 -0
- package/dist/post/api/approvePost.d.ts +17 -0
- package/dist/post/api/approvePost.d.ts.map +1 -0
- package/dist/post/api/declinePost.d.ts +17 -0
- package/dist/post/api/declinePost.d.ts.map +1 -0
- package/dist/post/api/index.d.ts +2 -0
- package/dist/post/api/index.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +6 -1
- package/src/core/query/query.ts +1 -1
- package/src/index.ts +2 -0
- package/src/poll/api/closePoll.ts +3 -0
- package/src/poll/api/deletePoll.ts +3 -0
- package/src/poll/api/votePoll.ts +3 -0
- package/src/poll/events/index.ts +2 -0
- package/src/poll/events/onPollDeleted.ts +31 -0
- package/src/poll/events/onPollUpdated.ts +31 -0
- package/src/poll/observers/index.ts +1 -0
- package/src/poll/observers/observePoll.ts +67 -0
- package/src/post/api/approvePost.ts +48 -0
- package/src/post/api/declinePost.ts +48 -0
- package/src/post/api/index.ts +3 -0
- package/src/report/api/createReport.ts +7 -1
- package/src/report/api/deleteReport.ts +7 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/closePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"closePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/closePoll.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAoBlC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deletePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/deletePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deletePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/deletePoll.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,CAiB9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"votePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/votePoll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"votePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/api/votePoll.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,WACX,MAAM,IAAI,CAAC,QAAQ,CAAC,aACjB,MAAM,EAAE,KAClB,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAoBlC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/poll/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onPollDeleted } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onPollDeleted(poll => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Poll} has been deleted
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category Poll Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onPollDeleted: (callback: Amity.Listener<Amity.Poll>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onPollDeleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onPollDeleted.d.ts","sourceRoot":"","sources":["../../../src/poll/events/onPollDeleted.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAU1E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { onPollUpdated } from '@amityco/ts-sdk'
|
|
4
|
+
* const dispose = onPollUpdated(poll => {
|
|
5
|
+
* // ...
|
|
6
|
+
* })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Fired when an {@link Amity.Poll} has been updated
|
|
10
|
+
*
|
|
11
|
+
* @param callback The function to call when the event was fired
|
|
12
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13
|
+
*
|
|
14
|
+
* @category Poll Events
|
|
15
|
+
*/
|
|
16
|
+
export declare const onPollUpdated: (callback: Amity.Listener<Amity.Poll>) => Amity.Unsubscriber;
|
|
17
|
+
//# sourceMappingURL=onPollUpdated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onPollUpdated.d.ts","sourceRoot":"","sources":["../../../src/poll/events/onPollUpdated.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAU1E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/poll/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { observePoll } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* let poll = {}
|
|
6
|
+
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Observe all mutation on a given {@link Amity.Poll}
|
|
10
|
+
*
|
|
11
|
+
* @param pollId the ID of the poll to observe
|
|
12
|
+
* @param callback the function to call when new data are available
|
|
13
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
14
|
+
*
|
|
15
|
+
* @category Poll Observer
|
|
16
|
+
*/
|
|
17
|
+
export declare const observePoll: <Events extends ["onFetch", "onUpdate", "onDelete"]>(pollId: string, callback: Amity.ObjectListener<Amity.Snapshot<Amity.Poll | undefined>, Events>, policy?: Amity.QueryPolicy) => Amity.Unsubscriber;
|
|
18
|
+
//# sourceMappingURL=observePoll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observePoll.d.ts","sourceRoot":"","sources":["../../../src/poll/observers/observePoll.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,+DACd,MAAM,2FAEN,MAAM,WAAW,KACxB,MAAM,YAsCR,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* const { data: post } = await approvePost('postId')
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Approves a {@link Amity.Post}
|
|
9
|
+
*
|
|
10
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
11
|
+
* @return A {@link Amity.Post} that was approved
|
|
12
|
+
*
|
|
13
|
+
* @category Post API
|
|
14
|
+
* @async
|
|
15
|
+
*/
|
|
16
|
+
export declare const approvePost: (postId: Amity.Post['postId']) => Promise<Amity.Cached<Amity.Post>>;
|
|
17
|
+
//# sourceMappingURL=approvePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approvePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/approvePost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAyBlC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* const {data: post} = await declinePost('postId')
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Declines a {@link Amity.Post}
|
|
9
|
+
*
|
|
10
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
11
|
+
* @return A {@link Amity.Post} that was declined
|
|
12
|
+
*
|
|
13
|
+
* @category Post API
|
|
14
|
+
* @async
|
|
15
|
+
*/
|
|
16
|
+
export declare const declinePost: (postId: Amity.Post['postId']) => Promise<Amity.Cached<Amity.Post>>;
|
|
17
|
+
//# sourceMappingURL=declinePost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declinePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/declinePost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,IAAI,CAAC,QAAQ,CAAC,KAC3B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAyBlC,CAAC"}
|
package/dist/post/api/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/post/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/post/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAE7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/createReport.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"createReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/createReport.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,CA0BjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/deleteReport.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAG1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"deleteReport.d.ts","sourceRoot":"","sources":["../../../src/report/api/deleteReport.ts"],"names":[],"mappings":"AAIA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAG1D;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,YAAY,kBACR,MAAM,sBAAsB,eAC9B,MAAM,KAClB,QAAQ,OAAO,CA0BjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -116,6 +116,11 @@ declare global {
|
|
|
116
116
|
MqttUserMessageEvents &
|
|
117
117
|
MqttFollowMessageEvents;
|
|
118
118
|
|
|
119
|
-
type
|
|
119
|
+
type LocalEvents = {
|
|
120
|
+
'poll.updated': Amity.PollPayload;
|
|
121
|
+
'poll.deleted': Amity.PollPayload;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type Events = WsEvents & MqttEvents & MqttMessageEvents & LocalEvents;
|
|
120
125
|
}
|
|
121
126
|
}
|
package/src/core/query/query.ts
CHANGED
|
@@ -216,7 +216,7 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
216
216
|
// @ts-ignore
|
|
217
217
|
const modelKey = local && local.data && identifyModelKey(local.data);
|
|
218
218
|
// @ts-ignore
|
|
219
|
-
optimisticArgs = modelKey ? [
|
|
219
|
+
optimisticArgs = modelKey ? [...args, { [modelKey]: local.data[modelKey] }] : args;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
func(...optimisticArgs)
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
@@ -30,6 +31,8 @@ export const closePoll = async (
|
|
|
30
31
|
const cachedAt = client.cache && Date.now();
|
|
31
32
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
32
33
|
|
|
34
|
+
fireEvent('poll.updated', data);
|
|
35
|
+
|
|
33
36
|
const { polls } = data;
|
|
34
37
|
|
|
35
38
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { upsertInCache } from '~/cache/api';
|
|
@@ -32,5 +33,7 @@ export const deletePoll = async (pollId: Amity.Poll['pollId']): Promise<boolean>
|
|
|
32
33
|
|
|
33
34
|
upsertInCache(['poll', 'get', pollId], deleted);
|
|
34
35
|
|
|
36
|
+
fireEvent('poll.deleted', { polls: [deleted], users: [] });
|
|
37
|
+
|
|
35
38
|
return success;
|
|
36
39
|
};
|
package/src/poll/api/votePoll.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
1
2
|
import { getActiveClient } from '~/client/api';
|
|
2
3
|
|
|
3
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
@@ -34,6 +35,8 @@ export const votePoll = async (
|
|
|
34
35
|
|
|
35
36
|
const { polls } = data;
|
|
36
37
|
|
|
38
|
+
fireEvent('poll.updated', data);
|
|
39
|
+
|
|
37
40
|
return {
|
|
38
41
|
data: polls.find(poll => poll.pollId === pollId)!,
|
|
39
42
|
cachedAt,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onPollDeleted } from '@amityco/ts-sdk'
|
|
9
|
+
* const dispose = onPollDeleted(poll => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when an {@link Amity.Poll} has been deleted
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Poll Events
|
|
20
|
+
*/
|
|
21
|
+
export const onPollDeleted = (callback: Amity.Listener<Amity.Poll>): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const filter = (payload: Amity.PollPayload) => {
|
|
25
|
+
if (client.cache) ingestInCache(payload);
|
|
26
|
+
|
|
27
|
+
callback(payload.polls[0]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onPollUpdated } from '@amityco/ts-sdk'
|
|
9
|
+
* const dispose = onPollUpdated(poll => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when an {@link Amity.Poll} has been updated
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Poll Events
|
|
20
|
+
*/
|
|
21
|
+
export const onPollUpdated = (callback: Amity.Listener<Amity.Poll>): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const filter = (payload: Amity.PollPayload) => {
|
|
25
|
+
if (client.cache) ingestInCache(payload);
|
|
26
|
+
|
|
27
|
+
callback(payload.polls[0]);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './observePoll';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { createQuery, runQuery, queryOptions } from '~/core/query';
|
|
4
|
+
|
|
5
|
+
import { getPoll } from '../api';
|
|
6
|
+
|
|
7
|
+
import { onPollUpdated, onPollDeleted } from '../events';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { observePoll } from '@amityco/ts-sdk'
|
|
12
|
+
*
|
|
13
|
+
* let poll = {}
|
|
14
|
+
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Observe all mutation on a given {@link Amity.Poll}
|
|
18
|
+
*
|
|
19
|
+
* @param pollId the ID of the poll to observe
|
|
20
|
+
* @param callback the function to call when new data are available
|
|
21
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
22
|
+
*
|
|
23
|
+
* @category Poll Observer
|
|
24
|
+
*/
|
|
25
|
+
export const observePoll = <Events extends ['onFetch', 'onUpdate', 'onDelete']>(
|
|
26
|
+
pollId: string,
|
|
27
|
+
callback: Amity.ObjectListener<Amity.Snapshot<Amity.Poll | undefined>, Events>,
|
|
28
|
+
policy: Amity.QueryPolicy = 'cache_then_server',
|
|
29
|
+
): Amity.Unsubscriber => {
|
|
30
|
+
const { log } = getActiveClient();
|
|
31
|
+
|
|
32
|
+
const timestamp = Date.now();
|
|
33
|
+
log(`observePoll(tmpid: ${timestamp}) > listen`);
|
|
34
|
+
|
|
35
|
+
// wrapper function to make sure
|
|
36
|
+
const router = (result: Amity.Snapshot<Amity.Poll | undefined>, action: Events[number]) => {
|
|
37
|
+
if (callback instanceof Function) return callback(result);
|
|
38
|
+
|
|
39
|
+
if (action !== 'onFetch') callback.onEvent?.(action, result);
|
|
40
|
+
|
|
41
|
+
callback[action]?.(result);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const realtimeRouter = (result: Amity.Snapshot<Amity.Poll>, action: Events[number]) => {
|
|
45
|
+
if (result.data?.pollId !== pollId) return;
|
|
46
|
+
|
|
47
|
+
router(result, action);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
51
|
+
|
|
52
|
+
disposers.push(
|
|
53
|
+
onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')),
|
|
54
|
+
onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
runQuery(
|
|
58
|
+
createQuery(getPoll, pollId),
|
|
59
|
+
result => (result.data || result.error) && router(result, 'onFetch'),
|
|
60
|
+
queryOptions(policy),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return () => {
|
|
64
|
+
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
65
|
+
disposers.forEach(fn => fn());
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { fireEvent } from '~/core/events';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
9
|
+
*
|
|
10
|
+
* const { data: post } = await approvePost('postId')
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Approves a {@link Amity.Post}
|
|
14
|
+
*
|
|
15
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
16
|
+
* @return A {@link Amity.Post} that was approved
|
|
17
|
+
*
|
|
18
|
+
* @category Post API
|
|
19
|
+
* @async
|
|
20
|
+
*/
|
|
21
|
+
export const approvePost = async (
|
|
22
|
+
postId: Amity.Post['postId'],
|
|
23
|
+
): Promise<Amity.Cached<Amity.Post>> => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
client.log('post/approvePost', postId);
|
|
26
|
+
|
|
27
|
+
const { data: approved } = await client.http.post<Amity.PostPayload>(
|
|
28
|
+
`/api/v3/posts/${encodeURIComponent(postId)}/approve`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const cachedAt = client.cache && Date.now();
|
|
32
|
+
if (client.cache) ingestInCache(approved, { cachedAt });
|
|
33
|
+
|
|
34
|
+
// fire virtual event for community update
|
|
35
|
+
if (approved.posts[0].targetType === 'community') {
|
|
36
|
+
const community = approved.communities?.[0];
|
|
37
|
+
|
|
38
|
+
// @ts-ignore as communities is optional currently in PostPayload
|
|
39
|
+
fireEvent('community.updated', { communities: [community] });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fireEvent('post.approved', { posts: [approved.posts[0]] });
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
data: approved.posts.find(post => post.postId === postId)!,
|
|
46
|
+
cachedAt,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { fireEvent } from '~/core/events';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
9
|
+
*
|
|
10
|
+
* const {data: post} = await declinePost('postId')
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Declines a {@link Amity.Post}
|
|
14
|
+
*
|
|
15
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
16
|
+
* @return A {@link Amity.Post} that was declined
|
|
17
|
+
*
|
|
18
|
+
* @category Post API
|
|
19
|
+
* @async
|
|
20
|
+
*/
|
|
21
|
+
export const declinePost = async (
|
|
22
|
+
postId: Amity.Post['postId'],
|
|
23
|
+
): Promise<Amity.Cached<Amity.Post>> => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
client.log('post/declinePost', postId);
|
|
26
|
+
|
|
27
|
+
const { data: declined } = await client.http.post<Amity.PostPayload>(
|
|
28
|
+
`/api/v3/posts/${encodeURIComponent(postId)}/decline`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const cachedAt = client.cache && Date.now();
|
|
32
|
+
if (client.cache) ingestInCache(declined, { cachedAt });
|
|
33
|
+
|
|
34
|
+
// fire virtual event
|
|
35
|
+
if (declined.posts[0].targetType === 'community') {
|
|
36
|
+
const community = declined.communities?.[0];
|
|
37
|
+
|
|
38
|
+
// @ts-ignore as communities is optional currently in PostPayload
|
|
39
|
+
fireEvent('community.updated', { communities: [community] });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fireEvent('post.declined', { posts: [declined.posts[0]] });
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
data: declined.posts.find(post => post.postId === postId)!,
|
|
46
|
+
cachedAt,
|
|
47
|
+
};
|
|
48
|
+
};
|
package/src/post/api/index.ts
CHANGED
|
@@ -29,7 +29,13 @@ export const createReport = async (
|
|
|
29
29
|
|
|
30
30
|
const { data } = await client.http.post<
|
|
31
31
|
Amity.PostPayload | Amity.CommentPayload | Amity.MessagePayload | Amity.UserPayload
|
|
32
|
-
>(
|
|
32
|
+
>(
|
|
33
|
+
`/api/${
|
|
34
|
+
referenceType === 'user'
|
|
35
|
+
? `v4/me/flags/${encodeURIComponent(referenceId)}`
|
|
36
|
+
: `v3/${domainName}/${encodeURIComponent(referenceId)}/flag`
|
|
37
|
+
}`,
|
|
38
|
+
);
|
|
33
39
|
|
|
34
40
|
if (client.cache) ingestInCache(data);
|
|
35
41
|
|
|
@@ -29,7 +29,13 @@ export const deleteReport = async (
|
|
|
29
29
|
|
|
30
30
|
const { data } = await client.http.delete<
|
|
31
31
|
Amity.PostPayload | Amity.CommentPayload | Amity.MessagePayload | Amity.UserPayload
|
|
32
|
-
>(
|
|
32
|
+
>(
|
|
33
|
+
`/api/${
|
|
34
|
+
referenceType === 'user'
|
|
35
|
+
? `v4/me/flags/${encodeURIComponent(referenceId)}`
|
|
36
|
+
: `v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`
|
|
37
|
+
}`,
|
|
38
|
+
);
|
|
33
39
|
|
|
34
40
|
if (client.cache) ingestInCache(data);
|
|
35
41
|
|