@amityco/ts-sdk 0.0.1-beta.11 → 0.0.1-beta.12
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 +6 -6
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +2 -2
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/comment/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/comment/events/utils.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/joinCommunity.d.ts.map +1 -1
- package/dist/community/api/leaveCommunity.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +24 -65
- package/dist/index.esm.js +24 -64
- package/dist/index.umd.js +5 -5
- package/dist/post/api/createPost.d.ts.map +1 -1
- package/dist/post/events/onPostReactionAdded.d.ts.map +1 -1
- package/dist/post/events/onPostReactionRemoved.d.ts.map +1 -1
- package/dist/post/events/utils.d.ts.map +1 -1
- package/package.json +1 -3
- package/src/@types/core/events.ts +6 -6
- package/src/@types/core/payload.ts +2 -2
- package/src/channel/events/onChannelCreated.ts +1 -3
- package/src/client/events/onConnectionError.ts +1 -1
- package/src/comment/events/onCommentReactionAdded.ts +0 -7
- package/src/comment/events/onCommentReactionRemoved.ts +0 -7
- package/src/comment/events/utils.ts +3 -10
- package/src/community/api/addCommunityMembers.ts +3 -5
- package/src/community/api/joinCommunity.ts +1 -3
- package/src/community/api/leaveCommunity.ts +1 -3
- package/src/community/api/removeCommunityMembers.ts +1 -3
- package/src/community/events/utils.ts +19 -33
- package/src/post/api/createPost.ts +0 -1
- package/src/post/events/onPostReactionAdded.ts +0 -7
- package/src/post/events/onPostReactionRemoved.ts +0 -7
- package/src/post/events/utils.ts +2 -10
- package/src/report/api/createReport.ts +1 -1
- package/src/report/api/deleteReport.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/createPost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU;;;;;MAIpB,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"createPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/createPost.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU;;;;;MAIpB,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAuBlC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onPostReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/post/events/onPostReactionAdded.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onPostReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/post/events/onPostReactionAdded.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAwBhF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onPostReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/post/events/onPostReactionRemoved.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onPostReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/post/events/onPostReactionRemoved.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,aAAc,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAG,MAAM,YAwBlF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/post/events/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/post/events/utils.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,yBAAyB,UAC7B,MAAM,MAAM,qBAAqB,YAC9B,MAAM,QAAQ,CAAC,MAAM,IAAI,CAAC,uBAyCrC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amityco/ts-sdk",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.12",
|
|
4
4
|
"license": "CC-BY-ND-4.0",
|
|
5
5
|
"author": "amity.co <developers@amity.co> (https://amity.co)",
|
|
6
6
|
"description": "Amity Social Cloud Typescript SDK",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"@rollup/plugin-replace": "^3.0.0",
|
|
37
37
|
"@types/axios": "^0.14.0",
|
|
38
38
|
"@types/debug": "^4.1.5",
|
|
39
|
-
"@types/lodash.ismatch": "^4.4.6",
|
|
40
39
|
"@types/node": "^14.0.11",
|
|
41
40
|
"@types/socket.io-client": "^1.4.34",
|
|
42
41
|
"chalk": "^4.1.2",
|
|
@@ -54,7 +53,6 @@
|
|
|
54
53
|
"axios": "0.21.1",
|
|
55
54
|
"debug": "^4.3.1",
|
|
56
55
|
"js-base64": "^3.6.1",
|
|
57
|
-
"lodash.ismatch": "^4.4.0",
|
|
58
56
|
"mitt": "^3.0.0",
|
|
59
57
|
"mqtt": "^4.2.8",
|
|
60
58
|
"react-native-uuid": "^2.0.1",
|
|
@@ -53,12 +53,12 @@ declare global {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
type MqttCommunityUserMessageEvents = {
|
|
56
|
-
'community.joined': Amity.
|
|
57
|
-
'community.left': Amity.
|
|
58
|
-
'community.userAdded': Amity.
|
|
59
|
-
'community.userRemoved': Amity.
|
|
60
|
-
'community.userBanned': Amity.
|
|
61
|
-
'community.userUnbanned': Amity.
|
|
56
|
+
'community.joined': Amity.CommunityMembershipPayload
|
|
57
|
+
'community.left': Amity.CommunityMembershipPayload
|
|
58
|
+
'community.userAdded': Amity.CommunityMembershipPayload
|
|
59
|
+
'community.userRemoved': Amity.CommunityMembershipPayload
|
|
60
|
+
'community.userBanned': Amity.CommunityMembershipPayload
|
|
61
|
+
'community.userUnbanned': Amity.CommunityMembershipPayload
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
type MqttCommunityMessageEvents = {
|
|
@@ -70,11 +70,11 @@ declare global {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
type CommunityMembershipPayload = {
|
|
73
|
-
communities
|
|
73
|
+
communities: Amity.Community[]
|
|
74
74
|
communityUsers: Amity.Membership<'community'>[]
|
|
75
75
|
categories?: Amity.Category[]
|
|
76
76
|
feeds?: Amity.Feed[]
|
|
77
|
-
users
|
|
77
|
+
users: Amity.User[]
|
|
78
78
|
files?: Amity.File[]
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
import { createEventSubscriber } from '~/core/events'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { ingestInCache } from '~/core/cache'
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* ```js
|
|
@@ -23,7 +22,6 @@ export const onChannelCreated = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
23
22
|
const client = getActiveClient()
|
|
24
23
|
|
|
25
24
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
26
|
-
decoratePayload(payload)
|
|
27
25
|
ingestInCache(payload)
|
|
28
26
|
callback(payload.channels[0])
|
|
29
27
|
}
|
|
@@ -38,7 +38,7 @@ export const onConnectionError = (
|
|
|
38
38
|
`client/onConnectionError(${event})`,
|
|
39
39
|
event,
|
|
40
40
|
(response) => {
|
|
41
|
-
const error =
|
|
41
|
+
const error = response?.code
|
|
42
42
|
? new ASCError(response.message, response.code, Amity.ErrorLevel.FATAL)
|
|
43
43
|
: new ASCConnectionError(event)
|
|
44
44
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
2
|
import { pullFromCache } from '~/cache/api'
|
|
4
3
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
@@ -29,8 +28,6 @@ export const onCommentReactionAdded = (
|
|
|
29
28
|
if (!client.cache) {
|
|
30
29
|
callback(payload.comments[0])
|
|
31
30
|
} else {
|
|
32
|
-
const cached = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])
|
|
33
|
-
|
|
34
31
|
preparePayloadForCache('comment.addReaction', payload)
|
|
35
32
|
const { reactor, ...commentPayload } = payload;
|
|
36
33
|
|
|
@@ -38,10 +35,6 @@ export const onCommentReactionAdded = (
|
|
|
38
35
|
|
|
39
36
|
const comment = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])!
|
|
40
37
|
|
|
41
|
-
if (cached && isMatch(cached.data, comment.data)) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
38
|
callback(comment.data)
|
|
46
39
|
}
|
|
47
40
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
2
|
import { pullFromCache } from '~/cache/api'
|
|
4
3
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
@@ -29,8 +28,6 @@ export const onCommentReactionRemoved = (
|
|
|
29
28
|
if (!client.cache) {
|
|
30
29
|
callback(payload.comments[0])
|
|
31
30
|
} else {
|
|
32
|
-
const cached = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])
|
|
33
|
-
|
|
34
31
|
preparePayloadForCache('comment.removeReaction', payload)
|
|
35
32
|
const { reactor, ...commentPayload } = payload;
|
|
36
33
|
|
|
@@ -38,10 +35,6 @@ export const onCommentReactionRemoved = (
|
|
|
38
35
|
|
|
39
36
|
const comment = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])!
|
|
40
37
|
|
|
41
|
-
if (cached && isMatch(cached.data, comment.data)) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
38
|
callback(comment.data)
|
|
46
39
|
}
|
|
47
40
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
|
-
import { pullFromCache } from '~/cache/api'
|
|
4
|
-
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
2
|
import { createEventSubscriber } from '~/core/events'
|
|
6
|
-
import { queryCache, upsertInCache } from '~/cache/api'
|
|
3
|
+
import { queryCache, upsertInCache, pullFromCache } from '~/cache/api'
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
7
5
|
|
|
8
6
|
export const createCommentEventSubscriber = (
|
|
9
7
|
event: keyof Amity.MqttCommentMessageEvents,
|
|
@@ -13,18 +11,13 @@ export const createCommentEventSubscriber = (
|
|
|
13
11
|
|
|
14
12
|
const filter = (payload: Amity.CommentPayload) => {
|
|
15
13
|
if (!client.cache) {
|
|
14
|
+
// TODO: here we are missing specific properties here!
|
|
16
15
|
callback(payload.comments[0])
|
|
17
16
|
} else {
|
|
18
|
-
const cached = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])
|
|
19
|
-
|
|
20
17
|
ingestInCache(payload)
|
|
21
18
|
|
|
22
19
|
const comment = pullFromCache<Amity.Comment>(['comment', 'get', payload.comments[0].commentId])!
|
|
23
20
|
|
|
24
|
-
if (cached && isMatch(cached.data, comment.data)) {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
21
|
if (['comment.created'].includes(event)) {
|
|
29
22
|
const queries = queryCache(['comment', 'query'])
|
|
30
23
|
// @ts-ignore
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api'
|
|
2
2
|
|
|
3
|
-
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
4
3
|
import { fireEvent } from '~/core/events'
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* ```js
|
|
7
8
|
* import { addCommunityMembers } from '@amityco/ts-sdk'
|
|
@@ -29,12 +30,9 @@ export const addCommunityMembers = async (
|
|
|
29
30
|
{ communityId, userIds }
|
|
30
31
|
)
|
|
31
32
|
|
|
32
|
-
|
|
33
33
|
if (client.cache) ingestInCache(data)
|
|
34
34
|
|
|
35
|
-
fireEvent('community.userAdded',
|
|
36
|
-
communities: data.communities!,
|
|
37
|
-
})
|
|
35
|
+
fireEvent('community.userAdded', data)
|
|
38
36
|
|
|
39
37
|
const { communityUsers } = data
|
|
40
38
|
return !!communityUsers.find(
|
|
@@ -30,9 +30,7 @@ export const joinCommunity = async (
|
|
|
30
30
|
const cachedAt = client.cache && Date.now()
|
|
31
31
|
if (client.cache) ingestInCache(data, { cachedAt })
|
|
32
32
|
|
|
33
|
-
fireEvent('community.joined',
|
|
34
|
-
communities: data.communities!
|
|
35
|
-
})
|
|
33
|
+
fireEvent('community.joined', data)
|
|
36
34
|
|
|
37
35
|
const { communityUsers } = data
|
|
38
36
|
|
|
@@ -30,9 +30,7 @@ export const leaveCommunity = async (
|
|
|
30
30
|
const cachedAt = client.cache && Date.now()
|
|
31
31
|
if (client.cache) ingestInCache(data, { cachedAt })
|
|
32
32
|
|
|
33
|
-
fireEvent('community.left',
|
|
34
|
-
communities: data.communities!,
|
|
35
|
-
})
|
|
33
|
+
fireEvent('community.left', data)
|
|
36
34
|
|
|
37
35
|
const { communityUsers } = data
|
|
38
36
|
|
|
@@ -32,9 +32,7 @@ export const removeCommunityMembers = async (
|
|
|
32
32
|
|
|
33
33
|
if (client.cache) ingestInCache(data)
|
|
34
34
|
|
|
35
|
-
fireEvent('community.userRemoved',
|
|
36
|
-
communities: data.communities!,
|
|
37
|
-
})
|
|
35
|
+
fireEvent('community.userRemoved', data)
|
|
38
36
|
|
|
39
37
|
const { communityUsers } = data
|
|
40
38
|
return !!communityUsers.find(
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
|
-
import { pullFromCache } from '~/cache/api'
|
|
4
2
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
3
|
import { createEventSubscriber } from '~/core/events'
|
|
4
|
+
import { pullFromCache } from '~/cache/api'
|
|
6
5
|
import { getResolver } from '~/core/model'
|
|
7
6
|
|
|
8
7
|
export const createCommunityEventSubscriber = (
|
|
@@ -13,18 +12,13 @@ export const createCommunityEventSubscriber = (
|
|
|
13
12
|
|
|
14
13
|
const filter = (payload: Amity.CommunityPayload) => {
|
|
15
14
|
if (!client.cache) {
|
|
15
|
+
// TODO: here we are missing specific properties here!
|
|
16
16
|
callback(payload.communities[0])
|
|
17
17
|
} else {
|
|
18
|
-
const cached = pullFromCache<Amity.Community>(['community', 'get', payload.communities[0].communityId])
|
|
19
|
-
|
|
20
18
|
ingestInCache(payload)
|
|
21
19
|
|
|
22
20
|
const community = pullFromCache<Amity.Community>(['community', 'get', payload.communities[0].communityId])!
|
|
23
21
|
|
|
24
|
-
if (cached && isMatch(cached.data, community?.data)) {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
22
|
callback(community.data)
|
|
29
23
|
}
|
|
30
24
|
}
|
|
@@ -37,7 +31,7 @@ export const createCommunityEventSubscriber = (
|
|
|
37
31
|
)
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
function hasPermission(member: Amity.Membership<'community'>, payload: Amity.
|
|
34
|
+
function hasPermission(member: Amity.Membership<'community'>, payload: Amity.CommunityMembershipPayload, permission: string) {
|
|
41
35
|
if (member.permissions.some(x => x === permission)) {
|
|
42
36
|
return true;
|
|
43
37
|
}
|
|
@@ -47,10 +41,9 @@ function hasPermission(member: Amity.Membership<'community'>, payload: Amity.Com
|
|
|
47
41
|
.permissions.some(x => x === permission)
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
|
|
51
44
|
function getEventRelatedMember(
|
|
52
45
|
event: keyof Amity.MqttCommunityUserMessageEvents,
|
|
53
|
-
payload: Amity.
|
|
46
|
+
payload: Amity.CommunityMembershipPayload
|
|
54
47
|
) {
|
|
55
48
|
if (event === 'community.joined' || event === 'community.left') {
|
|
56
49
|
return payload.communityUsers![0];
|
|
@@ -80,29 +73,22 @@ export const createCommunityMemberEventSubscriber = (
|
|
|
80
73
|
) => {
|
|
81
74
|
const client = getActiveClient()
|
|
82
75
|
|
|
83
|
-
const filter = (payload: Amity.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
])
|
|
90
|
-
|
|
91
|
-
ingestInCache(payload)
|
|
92
|
-
|
|
93
|
-
const community = pullFromCache<Amity.Community>(['community', 'get', payload.communities[0].communityId])!
|
|
94
|
-
const member = pullFromCache<Amity.Membership<'community'>>([
|
|
95
|
-
'communityUsers',
|
|
96
|
-
'get',
|
|
97
|
-
getResolver('communityUsers')(getEventRelatedMember(event, payload))
|
|
98
|
-
])!
|
|
99
|
-
|
|
100
|
-
if (cachedCommunity && isMatch(cachedCommunity.data, community.data)
|
|
101
|
-
&& cachedMember && isMatch(cachedMember.data, member.data)) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
76
|
+
const filter = (payload: Amity.CommunityMembershipPayload) => {
|
|
77
|
+
if (!client.cache) {
|
|
78
|
+
// TODO: here we are missing specific properties here!
|
|
79
|
+
callback(payload.communities[0], getEventRelatedMember(event, payload))
|
|
80
|
+
} else {
|
|
81
|
+
ingestInCache(payload)
|
|
104
82
|
|
|
105
|
-
|
|
83
|
+
const community = pullFromCache<Amity.Community>(['community', 'get', payload.communities[0].communityId])!
|
|
84
|
+
const member = pullFromCache<Amity.Membership<'community'>>([
|
|
85
|
+
'communityUsers',
|
|
86
|
+
'get',
|
|
87
|
+
getResolver('communityUsers')(getEventRelatedMember(event, payload))
|
|
88
|
+
])!
|
|
89
|
+
|
|
90
|
+
callback(community.data, member.data)
|
|
91
|
+
}
|
|
106
92
|
}
|
|
107
93
|
|
|
108
94
|
return createEventSubscriber(
|
|
@@ -40,7 +40,6 @@ export const createPost = async <T extends Amity.PostContentType | string>(
|
|
|
40
40
|
const cachedAt = client.cache && Date.now()
|
|
41
41
|
if (client.cache) ingestInCache(data, { cachedAt })
|
|
42
42
|
|
|
43
|
-
fireEvent('community.updated', { communities: data.communities! })
|
|
44
43
|
fireEvent('post.created', data)
|
|
45
44
|
|
|
46
45
|
const { posts } = data
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
2
|
import { pullFromCache } from '~/cache/api'
|
|
4
3
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
@@ -27,8 +26,6 @@ export const onPostReactionAdded = (callback: Amity.Listener<Amity.Post>): Amity
|
|
|
27
26
|
if (!client.cache) {
|
|
28
27
|
callback(payload.posts[0])
|
|
29
28
|
} else {
|
|
30
|
-
const cached = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])
|
|
31
|
-
|
|
32
29
|
preparePayloadForCache('post.addReaction', payload)
|
|
33
30
|
const { reactor, ...postPayload } = payload;
|
|
34
31
|
|
|
@@ -36,10 +33,6 @@ export const onPostReactionAdded = (callback: Amity.Listener<Amity.Post>): Amity
|
|
|
36
33
|
|
|
37
34
|
const post = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])!
|
|
38
35
|
|
|
39
|
-
if (cached && isMatch(cached.data, post.data)) {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
callback(post.data)
|
|
44
37
|
}
|
|
45
38
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
2
|
import { pullFromCache } from '~/cache/api'
|
|
4
3
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
@@ -27,8 +26,6 @@ export const onPostReactionRemoved = (callback: Amity.Listener<Amity.Post>): Ami
|
|
|
27
26
|
if (!client.cache) {
|
|
28
27
|
callback(payload.posts[0])
|
|
29
28
|
} else {
|
|
30
|
-
const cached = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])
|
|
31
|
-
|
|
32
29
|
preparePayloadForCache('post.removeReaction', payload)
|
|
33
30
|
const { reactor, ...postPayload } = payload;
|
|
34
31
|
|
|
@@ -36,10 +33,6 @@ export const onPostReactionRemoved = (callback: Amity.Listener<Amity.Post>): Ami
|
|
|
36
33
|
|
|
37
34
|
const post = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])!
|
|
38
35
|
|
|
39
|
-
if (cached && isMatch(cached.data, post.data)) {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
callback(post.data)
|
|
44
37
|
}
|
|
45
38
|
}
|
package/src/post/events/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import isMatch from 'lodash.ismatch'
|
|
2
1
|
import { getActiveClient } from '~/client/api'
|
|
3
|
-
import { pullFromCache } from '~/cache/api'
|
|
4
2
|
import { ingestInCache } from '~/cache/api/ingestInCache'
|
|
5
3
|
import { createEventSubscriber, fireEvent } from '~/core/events'
|
|
6
|
-
import { queryCache, upsertInCache } from '~/cache/api'
|
|
4
|
+
import { queryCache, upsertInCache, pullFromCache } from '~/cache/api'
|
|
7
5
|
|
|
8
6
|
export const createPostEventSubscriber = (
|
|
9
7
|
event: keyof Amity.MqttPostMessageEvents,
|
|
@@ -15,22 +13,16 @@ export const createPostEventSubscriber = (
|
|
|
15
13
|
if (!client.cache) {
|
|
16
14
|
callback(payload.posts[0])
|
|
17
15
|
} else {
|
|
18
|
-
const cached = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])
|
|
19
|
-
|
|
20
16
|
const { communities, ...others } = payload
|
|
21
17
|
|
|
22
18
|
ingestInCache(others as Amity.PostPayload)
|
|
23
19
|
|
|
24
|
-
if (communities?.[0]) {
|
|
20
|
+
if (communities?.[0] && !['post.updated'].includes(event)) {
|
|
25
21
|
fireEvent('community.updated', { communities })
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
const post = pullFromCache<Amity.Post>(['post', 'get', payload.posts[0].postId])!
|
|
29
25
|
|
|
30
|
-
if (cached && isMatch(cached.data, post.data)) {
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
26
|
if (['post.created', 'post.approved', 'post.declined'].includes(event)) {
|
|
35
27
|
let queries = queryCache(['post', 'query'])
|
|
36
28
|
// @ts-ignore
|