@amityco/ts-sdk-react-native 6.30.3-cae094b.0 → 6.30.3
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/.env +26 -26
- package/dist/channelRepository/events/onChannelCreated.d.ts +1 -16
- package/dist/channelRepository/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelDeleted.d.ts +1 -16
- package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelFetched.d.ts +1 -16
- package/dist/channelRepository/events/onChannelFetched.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelJoined.d.ts +1 -16
- package/dist/channelRepository/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelLeft.d.ts +1 -16
- package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberAdded.d.ts +0 -15
- package/dist/channelRepository/events/onChannelMemberAdded.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberBanned.d.ts +1 -16
- package/dist/channelRepository/events/onChannelMemberBanned.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRemoved.d.ts +1 -16
- package/dist/channelRepository/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts +0 -15
- package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts +0 -15
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberUnbanned.d.ts +1 -16
- package/dist/channelRepository/events/onChannelMemberUnbanned.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMuted.d.ts +1 -16
- package/dist/channelRepository/events/onChannelMuted.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelUpdated.d.ts +0 -15
- package/dist/channelRepository/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/index.cjs.js +279 -286
- package/dist/index.esm.js +279 -286
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
- package/src/channelRepository/events/onChannelCreated.ts +26 -22
- package/src/channelRepository/events/onChannelDeleted.ts +32 -28
- package/src/channelRepository/events/onChannelFetched.ts +29 -20
- package/src/channelRepository/events/onChannelJoined.ts +27 -23
- package/src/channelRepository/events/onChannelLeft.ts +39 -34
- package/src/channelRepository/events/onChannelMemberAdded.ts +34 -23
- package/src/channelRepository/events/onChannelMemberBanned.ts +19 -17
- package/src/channelRepository/events/onChannelMemberRemoved.ts +32 -23
- package/src/channelRepository/events/onChannelMemberRoleAdded.ts +32 -26
- package/src/channelRepository/events/onChannelMemberRoleRemoved.ts +30 -26
- package/src/channelRepository/events/onChannelMemberUnbanned.ts +31 -23
- package/src/channelRepository/events/onChannelMuted.ts +26 -22
- package/src/channelRepository/events/onChannelUpdated.ts +32 -29
package/package.json
CHANGED
|
@@ -5,30 +5,34 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
5
5
|
|
|
6
6
|
import { prepareChannelPayload } from '../utils';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
8
|
+
type CallbackFn = (channel: Amity.InternalChannel) => void;
|
|
9
|
+
const callbacks: CallbackFn[] = [];
|
|
10
|
+
let mainDisposer: (() => void) | null = null;
|
|
11
|
+
|
|
12
|
+
const dispose = (cb: CallbackFn) => {
|
|
13
|
+
const index = callbacks.indexOf(cb);
|
|
14
|
+
if (index > -1) {
|
|
15
|
+
callbacks.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
if (callbacks.length === 0) {
|
|
18
|
+
mainDisposer?.();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
23
22
|
export const onChannelCreated = (callback: Amity.Listener<Amity.InternalChannel>) => {
|
|
24
|
-
|
|
23
|
+
if (callbacks.length === 0) {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
|
|
26
|
+
const filter = async (payload: Amity.ChannelPayload) => {
|
|
27
|
+
const data = await prepareChannelPayload(payload);
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callbacks.forEach(cb => cb(data.channels[0]));
|
|
31
|
+
};
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
33
|
+
mainDisposer = createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
callbacks.push(callback);
|
|
37
|
+
return () => dispose(callback);
|
|
34
38
|
};
|
|
@@ -7,37 +7,41 @@ import { prepareChannelPayload } from '../utils/prepareChannelPayload';
|
|
|
7
7
|
import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
|
|
8
8
|
import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
10
|
+
type CallbackFn = (channel: Amity.InternalChannel) => void;
|
|
11
|
+
const callbacks: CallbackFn[] = [];
|
|
12
|
+
let mainDisposer: (() => void) | null = null;
|
|
13
|
+
|
|
14
|
+
const dispose = (cb: CallbackFn) => {
|
|
15
|
+
const index = callbacks.indexOf(cb);
|
|
16
|
+
if (index > -1) {
|
|
17
|
+
callbacks.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
if (callbacks.length === 0) {
|
|
20
|
+
mainDisposer?.();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
25
24
|
export const onChannelDeleted = (callback: Amity.Listener<Amity.InternalChannel>) => {
|
|
26
|
-
|
|
25
|
+
if (callbacks.length === 0) {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
|
|
28
|
+
const filter = async (payload: Amity.ChannelPayload) => {
|
|
29
|
+
const data = await prepareChannelPayload(payload);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
32
|
+
data.channels.forEach(channel => {
|
|
33
|
+
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
34
|
+
deleteChannelUnreadByChannelId(channel.channelId);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
deleteChannelUnreadByChannelId(channel.channelId);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
38
|
+
ingestInCache(data);
|
|
39
|
+
callbacks.forEach(cb => cb(data.channels[0]));
|
|
40
|
+
};
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
42
|
+
mainDisposer = createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
callbacks.push(callback);
|
|
46
|
+
return () => dispose(callback);
|
|
43
47
|
};
|
|
@@ -2,27 +2,36 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
2
2
|
|
|
3
3
|
import { getActiveClient } from '~/client/api/activeClient';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
5
|
+
type CallbackFn = (channel: Amity.InternalChannel[]) => void;
|
|
6
|
+
const callbacks: CallbackFn[] = [];
|
|
7
|
+
let mainDisposer: (() => void) | null = null;
|
|
8
|
+
|
|
9
|
+
const dispose = (cb: CallbackFn) => {
|
|
10
|
+
const index = callbacks.indexOf(cb);
|
|
11
|
+
if (index > -1) {
|
|
12
|
+
callbacks.splice(index, 1);
|
|
13
|
+
}
|
|
14
|
+
if (callbacks.length === 0) {
|
|
15
|
+
mainDisposer?.();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
20
19
|
export const onChannelFetched = (callback: Amity.Listener<Amity.InternalChannel[]>) => {
|
|
21
|
-
|
|
20
|
+
if (callbacks.length === 0) {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
const filter = async (payload: Amity.InternalChannel[]) => {
|
|
24
|
+
callbacks.forEach(cb => cb(payload));
|
|
25
|
+
};
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
mainDisposer = createEventSubscriber(
|
|
28
|
+
client,
|
|
29
|
+
'onChannelFetched',
|
|
30
|
+
'local.channel.fetched',
|
|
31
|
+
filter,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
callbacks.push(callback);
|
|
36
|
+
return () => dispose(callback);
|
|
28
37
|
};
|
|
@@ -5,33 +5,37 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
5
5
|
|
|
6
6
|
import { prepareChannelPayload } from '../utils';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
8
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
9
|
+
const callbacks: CallbackFn[] = [];
|
|
10
|
+
let mainDisposer: (() => void) | null = null;
|
|
11
|
+
|
|
12
|
+
const dispose = (cb: CallbackFn) => {
|
|
13
|
+
const index = callbacks.indexOf(cb);
|
|
14
|
+
if (index > -1) {
|
|
15
|
+
callbacks.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
if (callbacks.length === 0) {
|
|
18
|
+
mainDisposer?.();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
23
22
|
export const onChannelJoined = (
|
|
24
23
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
25
24
|
) => {
|
|
26
|
-
|
|
25
|
+
if (callbacks.length === 0) {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
|
|
28
|
+
const filter = async (payload: Amity.ChannelMembershipPayload) => {
|
|
29
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
30
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
ingestInCache(preparedPayload);
|
|
33
|
+
callbacks.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
34
|
+
};
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
36
|
+
mainDisposer = createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
37
|
+
}
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
callbacks.push(callback);
|
|
40
|
+
return () => dispose(callback);
|
|
37
41
|
};
|
|
@@ -7,48 +7,53 @@ import { prepareChannelPayload } from '../utils';
|
|
|
7
7
|
import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
|
|
8
8
|
import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
10
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
11
|
+
const callbacks: CallbackFn[] = [];
|
|
12
|
+
let mainDisposer: (() => void) | null = null;
|
|
13
|
+
|
|
14
|
+
const dispose = (cb: CallbackFn) => {
|
|
15
|
+
const index = callbacks.indexOf(cb);
|
|
16
|
+
if (index > -1) {
|
|
17
|
+
callbacks.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
if (callbacks.length === 0) {
|
|
20
|
+
mainDisposer?.();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
25
24
|
export const onChannelLeft = (
|
|
26
25
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
27
26
|
) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const filter = async (payload: Amity.ChannelMembershipPayload) => {
|
|
31
|
-
const { userId } = getActiveClient();
|
|
32
|
-
const { channelUsers: leftUsers } = payload;
|
|
27
|
+
if (callbacks.length === 0) {
|
|
28
|
+
const client = getActiveClient();
|
|
33
29
|
|
|
34
|
-
const
|
|
30
|
+
const filter = async (payload: Amity.ChannelMembershipPayload) => {
|
|
31
|
+
const { userId } = getActiveClient();
|
|
32
|
+
const { channelUsers: leftUsers } = payload;
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
isMessagePreviewUpdated: isLeftByMe,
|
|
38
|
-
});
|
|
34
|
+
const isLeftByMe = leftUsers.some(user => user.userId === userId);
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
43
|
-
deleteChannelUnreadByChannelId(channel.channelId);
|
|
36
|
+
const preparedPayload = await prepareChannelPayload(payload, {
|
|
37
|
+
isMessagePreviewUpdated: isLeftByMe,
|
|
44
38
|
});
|
|
45
|
-
}
|
|
46
39
|
|
|
47
|
-
|
|
40
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
|
|
41
|
+
preparedPayload.channels.forEach(channel => {
|
|
42
|
+
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
43
|
+
deleteChannelUnreadByChannelId(channel.channelId);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { channels, channelUsers } = preparedPayload;
|
|
48
|
+
|
|
49
|
+
ingestInCache(preparedPayload);
|
|
50
|
+
callbacks.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
mainDisposer = createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
54
|
+
}
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
callback(channels[0], channelUsers[0]);
|
|
51
|
-
};
|
|
56
|
+
callbacks.push(callback);
|
|
52
57
|
|
|
53
|
-
return
|
|
58
|
+
return () => dispose(callback);
|
|
54
59
|
};
|
|
@@ -4,33 +4,44 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
4
4
|
|
|
5
5
|
import { prepareChannelPayload } from '../utils';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*/
|
|
7
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
8
|
+
const callbacks: CallbackFn[] = [];
|
|
9
|
+
let mainDisposer: (() => void) | null = null;
|
|
10
|
+
|
|
11
|
+
const dispose = (cb: CallbackFn) => {
|
|
12
|
+
const index = callbacks.indexOf(cb);
|
|
13
|
+
if (index > -1) {
|
|
14
|
+
callbacks.splice(index, 1);
|
|
15
|
+
}
|
|
16
|
+
if (callbacks.length === 0) {
|
|
17
|
+
mainDisposer?.();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
22
21
|
export const onChannelMemberAdded = (
|
|
23
22
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
24
23
|
): Amity.Unsubscriber => {
|
|
25
|
-
|
|
24
|
+
if (callbacks.length === 0) {
|
|
25
|
+
const client = getActiveClient();
|
|
26
|
+
|
|
27
|
+
const filter = async (payload: Amity.ChannelMembershipPayload) => {
|
|
28
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
29
|
+
const { channels, channelUsers } = preparedPayload;
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
ingestInCache(preparedPayload);
|
|
32
|
+
callbacks.forEach(cb =>
|
|
33
|
+
cb(channels[0], channelUsers.find(cu => cu.membership === 'member')!),
|
|
34
|
+
);
|
|
35
|
+
};
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
mainDisposer = createEventSubscriber(
|
|
38
|
+
client,
|
|
39
|
+
'onChannelMemberAdded',
|
|
40
|
+
'channel.membersAdded',
|
|
41
|
+
filter,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
callbacks.push(callback);
|
|
46
|
+
return () => dispose(callback);
|
|
36
47
|
};
|
|
@@ -7,21 +7,20 @@ import { prepareChannelPayload } from '../utils';
|
|
|
7
7
|
import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
|
|
8
8
|
import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
10
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
11
|
+
const callbacks: CallbackFn[] = [];
|
|
12
|
+
let mainDisposer: (() => void) | null = null;
|
|
13
|
+
|
|
14
|
+
const dispose = (cb: CallbackFn) => {
|
|
15
|
+
const index = callbacks.indexOf(cb);
|
|
16
|
+
if (index > -1) {
|
|
17
|
+
callbacks.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
if (callbacks.length === 0) {
|
|
20
|
+
mainDisposer?.();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
25
24
|
export const onChannelMemberBanned = (
|
|
26
25
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
27
26
|
) => {
|
|
@@ -47,8 +46,11 @@ export const onChannelMemberBanned = (
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
ingestInCache(preparedPayload);
|
|
50
|
-
|
|
49
|
+
callbacks.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'banned')!));
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
mainDisposer = createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
53
|
+
|
|
54
|
+
callbacks.push(callback);
|
|
55
|
+
return () => dispose(callback);
|
|
54
56
|
};
|
|
@@ -5,33 +5,42 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
5
5
|
|
|
6
6
|
import { prepareChannelPayload } from '../utils';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
8
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
9
|
+
const callbacks: CallbackFn[] = [];
|
|
10
|
+
let mainDisposer: (() => void) | null = null;
|
|
11
|
+
|
|
12
|
+
const dispose = (cb: CallbackFn) => {
|
|
13
|
+
const index = callbacks.indexOf(cb);
|
|
14
|
+
if (index > -1) {
|
|
15
|
+
callbacks.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
if (callbacks.length === 0) {
|
|
18
|
+
mainDisposer?.();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
23
22
|
export const onChannelMemberRemoved = (
|
|
24
23
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
25
24
|
) => {
|
|
26
|
-
|
|
25
|
+
if (callbacks.length === 0) {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
|
|
28
|
+
const filter = async (payload: Amity.ChannelMembershipPayload) => {
|
|
29
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
30
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
ingestInCache(preparedPayload);
|
|
33
|
+
callbacks.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
34
|
+
};
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
mainDisposer = createEventSubscriber(
|
|
37
|
+
client,
|
|
38
|
+
'onChannelMemberRemoved',
|
|
39
|
+
'channel.membersRemoved',
|
|
40
|
+
filter,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
callbacks.push(callback);
|
|
45
|
+
return () => dispose(callback);
|
|
37
46
|
};
|
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
4
|
+
type CallbackFn = (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void;
|
|
5
|
+
const callbacks: CallbackFn[] = [];
|
|
6
|
+
let mainDisposer: (() => void) | null = null;
|
|
7
|
+
|
|
8
|
+
const dispose = (cb: CallbackFn) => {
|
|
9
|
+
const index = callbacks.indexOf(cb);
|
|
10
|
+
if (index > -1) {
|
|
11
|
+
callbacks.splice(index, 1);
|
|
12
|
+
}
|
|
13
|
+
if (callbacks.length === 0) {
|
|
14
|
+
mainDisposer?.();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
19
18
|
export const onChannelMemberRoleAdded = (
|
|
20
19
|
callback: (channel: Amity.InternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
21
20
|
): Amity.Unsubscriber => {
|
|
22
|
-
|
|
21
|
+
if (callbacks.length === 0) {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const filter = async (payload: Amity.ProcessedChannelPayload) => {
|
|
25
|
+
const { channels, channelUsers } = payload;
|
|
26
|
+
callbacks.forEach(cb =>
|
|
27
|
+
cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')!),
|
|
28
|
+
);
|
|
29
|
+
};
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
mainDisposer = createEventSubscriber(
|
|
32
|
+
client,
|
|
33
|
+
'onChannelMemberRoleAdded',
|
|
34
|
+
'local.channel-moderator.role-added',
|
|
35
|
+
filter,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
'onChannelMemberRoleAdded',
|
|
32
|
-
'local.channel-moderator.role-added',
|
|
33
|
-
filter,
|
|
34
|
-
);
|
|
39
|
+
callbacks.push(callback);
|
|
40
|
+
return () => dispose(callback);
|
|
35
41
|
};
|