@amityco/ts-sdk 7.11.1-7526ae66.0 → 7.11.1-78c2ad3f.0
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 +48 -10
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +17 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +5 -1
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +3 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +11 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +81 -0
- package/dist/@types/domains/event.d.ts.map +1 -0
- package/dist/@types/domains/feed.d.ts +2 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +7 -2
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +25 -17
- package/dist/@types/domains/room.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channelRepository/api/createChannel.d.ts +1 -0
- package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/eventRepository/api/createEvent.d.ts +16 -0
- package/dist/eventRepository/api/createEvent.d.ts.map +1 -0
- package/dist/eventRepository/api/deleteEvent.d.ts +15 -0
- package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
- package/dist/eventRepository/api/index.d.ts +4 -0
- package/dist/eventRepository/api/index.d.ts.map +1 -0
- package/dist/eventRepository/api/updateEvent.d.ts +17 -0
- package/dist/eventRepository/api/updateEvent.d.ts.map +1 -0
- package/dist/eventRepository/events/enums.d.ts +6 -0
- package/dist/eventRepository/events/enums.d.ts.map +1 -0
- package/dist/eventRepository/events/index.d.ts +7 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
- package/dist/eventRepository/index.d.ts +4 -0
- package/dist/eventRepository/index.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/getEvent.d.ts +32 -0
- package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/index.d.ts +2 -0
- package/dist/eventRepository/internalApi/index.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvent.d.ts +21 -0
- package/dist/eventRepository/observers/getEvent.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/index.d.ts +4 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +2 -0
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -0
- package/dist/eventRepository/utils/index.d.ts +3 -0
- package/dist/eventRepository/utils/index.d.ts.map +1 -0
- package/dist/eventRepository/utils/prepareEventPayload.d.ts +2 -0
- package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +1 -0
- package/dist/index.cjs.js +3858 -2738
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2140 -1023
- package/dist/index.umd.js +3 -3
- package/dist/invitationRepository/api/acceptInvitation.d.ts +16 -0
- package/dist/invitationRepository/api/acceptInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/api/cancelInvitation.d.ts +16 -0
- package/dist/invitationRepository/api/cancelInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/api/getMyInvitation.d.ts +16 -0
- package/dist/invitationRepository/api/getMyInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/api/index.d.ts +3 -0
- package/dist/invitationRepository/api/index.d.ts.map +1 -0
- package/dist/invitationRepository/events/index.d.ts +1 -1
- package/dist/invitationRepository/events/index.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCanceled.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationCanceled.d.ts.map +1 -0
- package/dist/invitationRepository/index.d.ts +1 -0
- package/dist/invitationRepository/index.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/getInvitation.d.ts +1 -1
- package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -1
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts +1 -1
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -1
- package/dist/invitationRepository/observers/index.d.ts +1 -0
- package/dist/invitationRepository/observers/index.d.ts.map +1 -1
- package/dist/invitationRepository/observers/observeInvitations.d.ts +34 -0
- package/dist/invitationRepository/observers/observeInvitations.d.ts.map +1 -0
- package/dist/liveReactionRepository/api/createReaction.d.ts +2 -2
- package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -1
- package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts +2 -2
- package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts.map +1 -1
- package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +1 -1
- package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -1
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +2 -1
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/roomRepository/api/getBroadcasterData.d.ts +16 -0
- package/dist/roomRepository/api/getBroadcasterData.d.ts.map +1 -0
- package/dist/roomRepository/api/index.d.ts +3 -1
- package/dist/roomRepository/api/index.d.ts.map +1 -1
- package/dist/roomRepository/api/leaveRoom.d.ts +16 -0
- package/dist/roomRepository/api/leaveRoom.d.ts.map +1 -0
- package/dist/roomRepository/api/removeParticipant.d.ts +17 -0
- package/dist/roomRepository/api/removeParticipant.d.ts.map +1 -0
- package/dist/roomRepository/api/updateRoom.d.ts +1 -1
- package/dist/roomRepository/api/updateRoom.d.ts.map +1 -1
- package/dist/roomRepository/events/index.d.ts +6 -1
- package/dist/roomRepository/events/index.d.ts.map +1 -1
- package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts +17 -0
- package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomCoHostInviteCanceled.d.ts +17 -0
- package/dist/roomRepository/events/onRoomCoHostInviteCanceled.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomCoHostInviteRejected.d.ts +17 -0
- package/dist/roomRepository/events/onRoomCoHostInviteRejected.d.ts.map +1 -0
- package/dist/roomRepository/events/{onRoomParticipantInviting.d.ts → onRoomCoHostInvited.d.ts} +2 -2
- package/dist/roomRepository/events/onRoomCoHostInvited.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomLeft.d.ts +17 -0
- package/dist/roomRepository/events/onRoomLeft.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts +17 -0
- package/dist/roomRepository/events/onRoomParticipantRemoved.d.ts.map +1 -0
- package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
- package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
- package/dist/roomRepository/internalApi/index.d.ts +1 -0
- package/dist/roomRepository/internalApi/index.d.ts.map +1 -1
- package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
- package/dist/roomRepository/observers/utils.d.ts +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts +2 -0
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +2 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +0 -17
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +0 -1
- package/dist/roomRepository/api/getRoomToken.d.ts +0 -16
- package/dist/roomRepository/api/getRoomToken.d.ts.map +0 -1
- package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -126,7 +126,7 @@ const PostStructureType = Object.freeze({
|
|
|
126
126
|
var InvitationTypeEnum;
|
|
127
127
|
(function (InvitationTypeEnum) {
|
|
128
128
|
InvitationTypeEnum["CommunityMemberInvite"] = "communityMemberInvite";
|
|
129
|
-
InvitationTypeEnum["
|
|
129
|
+
InvitationTypeEnum["LivestreamCohostInvite"] = "livestreamCohostInvite";
|
|
130
130
|
})(InvitationTypeEnum || (InvitationTypeEnum = {}));
|
|
131
131
|
var InvitationStatusEnum;
|
|
132
132
|
(function (InvitationStatusEnum) {
|
|
@@ -140,6 +140,11 @@ var InvitationSortByEnum;
|
|
|
140
140
|
InvitationSortByEnum["FirstCreated"] = "firstCreated";
|
|
141
141
|
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
142
142
|
})(InvitationSortByEnum || (InvitationSortByEnum = {}));
|
|
143
|
+
var InvitationTargetTypeEnum;
|
|
144
|
+
(function (InvitationTargetTypeEnum) {
|
|
145
|
+
InvitationTargetTypeEnum["Community"] = "community";
|
|
146
|
+
InvitationTargetTypeEnum["Room"] = "room";
|
|
147
|
+
})(InvitationTargetTypeEnum || (InvitationTargetTypeEnum = {}));
|
|
143
148
|
|
|
144
149
|
var JoinRequestStatusEnum;
|
|
145
150
|
(function (JoinRequestStatusEnum) {
|
|
@@ -164,6 +169,7 @@ var FeedDataTypeEnum;
|
|
|
164
169
|
FeedDataTypeEnum["LiveStream"] = "liveStream";
|
|
165
170
|
FeedDataTypeEnum["Clip"] = "clip";
|
|
166
171
|
FeedDataTypeEnum["Poll"] = "poll";
|
|
172
|
+
FeedDataTypeEnum["Room"] = "room";
|
|
167
173
|
})(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
|
|
168
174
|
var FeedSortByEnum;
|
|
169
175
|
(function (FeedSortByEnum) {
|
|
@@ -178,6 +184,30 @@ var FeedSourceEnum;
|
|
|
178
184
|
FeedSourceEnum["User"] = "user";
|
|
179
185
|
})(FeedSourceEnum || (FeedSourceEnum = {}));
|
|
180
186
|
|
|
187
|
+
var AmityEventType;
|
|
188
|
+
(function (AmityEventType) {
|
|
189
|
+
AmityEventType["Virtual"] = "virtual";
|
|
190
|
+
AmityEventType["InPerson"] = "in_person";
|
|
191
|
+
})(AmityEventType || (AmityEventType = {}));
|
|
192
|
+
var AmityEventOriginType;
|
|
193
|
+
(function (AmityEventOriginType) {
|
|
194
|
+
AmityEventOriginType["Community"] = "community";
|
|
195
|
+
AmityEventOriginType["User"] = "user";
|
|
196
|
+
})(AmityEventOriginType || (AmityEventOriginType = {}));
|
|
197
|
+
var AmityEventStatus;
|
|
198
|
+
(function (AmityEventStatus) {
|
|
199
|
+
AmityEventStatus["Scheduled"] = "scheduled";
|
|
200
|
+
AmityEventStatus["Live"] = "live";
|
|
201
|
+
AmityEventStatus["Ended"] = "ended";
|
|
202
|
+
AmityEventStatus["Cancelled"] = "cancelled";
|
|
203
|
+
})(AmityEventStatus || (AmityEventStatus = {}));
|
|
204
|
+
var AmityEventResponseStatus;
|
|
205
|
+
(function (AmityEventResponseStatus) {
|
|
206
|
+
AmityEventResponseStatus["Going"] = "going";
|
|
207
|
+
AmityEventResponseStatus["Interested"] = "interested";
|
|
208
|
+
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
209
|
+
})(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
|
|
210
|
+
|
|
181
211
|
function getVersion() {
|
|
182
212
|
try {
|
|
183
213
|
// the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -627,6 +657,8 @@ const idResolvers = {
|
|
|
627
657
|
invitation: ({ _id }) => _id,
|
|
628
658
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
629
659
|
room: ({ roomId }) => roomId,
|
|
660
|
+
event: ({ eventId }) => eventId,
|
|
661
|
+
discussionCommunity: ({ communityId }) => communityId,
|
|
630
662
|
};
|
|
631
663
|
/**
|
|
632
664
|
* Retrieve the id resolver matching a domain name
|
|
@@ -683,6 +715,8 @@ const PAYLOAD2MODEL = {
|
|
|
683
715
|
invitations: 'invitation',
|
|
684
716
|
joinRequests: 'joinRequest',
|
|
685
717
|
rooms: 'room',
|
|
718
|
+
events: 'event',
|
|
719
|
+
discussionCommunities: 'discussionCommunity',
|
|
686
720
|
};
|
|
687
721
|
/** hidden */
|
|
688
722
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -1413,12 +1447,14 @@ const createEventEmitter = () => {
|
|
|
1413
1447
|
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1414
1448
|
MQTT_EVENTS.forEach(event => {
|
|
1415
1449
|
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
|
|
1450
|
+
console.log('global event received => ', event);
|
|
1416
1451
|
emitter.emit(event, params.length === 1 ? params[0] : params);
|
|
1417
1452
|
});
|
|
1418
1453
|
});
|
|
1419
1454
|
// @ts-ignore
|
|
1420
1455
|
mqttClient.on('message', (topic, payload) => {
|
|
1421
1456
|
const message = JSON.parse(payload.toString());
|
|
1457
|
+
console.log('message event received => ', message.eventType, message.data);
|
|
1422
1458
|
emitter.emit(message.eventType, message.data);
|
|
1423
1459
|
});
|
|
1424
1460
|
};
|
|
@@ -1482,6 +1518,37 @@ async function modifyMqttConnection() {
|
|
|
1482
1518
|
}
|
|
1483
1519
|
}
|
|
1484
1520
|
|
|
1521
|
+
const userLinkedObject = (user) => {
|
|
1522
|
+
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
1523
|
+
var _a;
|
|
1524
|
+
if (!user.avatarFileId)
|
|
1525
|
+
return undefined;
|
|
1526
|
+
const avatar = (_a = pullFromCache([
|
|
1527
|
+
'file',
|
|
1528
|
+
'get',
|
|
1529
|
+
`${user.avatarFileId}`,
|
|
1530
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
1531
|
+
return avatar;
|
|
1532
|
+
} });
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
/* begin_public_function
|
|
1536
|
+
id: client.get_current_user
|
|
1537
|
+
*/
|
|
1538
|
+
const getCurrentUser = () => {
|
|
1539
|
+
var _a;
|
|
1540
|
+
const client = getActiveClient();
|
|
1541
|
+
if (!client) {
|
|
1542
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
1543
|
+
}
|
|
1544
|
+
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
1545
|
+
if (!cache) {
|
|
1546
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
1547
|
+
}
|
|
1548
|
+
return userLinkedObject(cache);
|
|
1549
|
+
};
|
|
1550
|
+
/* end_public_function */
|
|
1551
|
+
|
|
1485
1552
|
var SubscriptionLevels;
|
|
1486
1553
|
(function (SubscriptionLevels) {
|
|
1487
1554
|
SubscriptionLevels["COMMUNITY"] = "community";
|
|
@@ -1587,6 +1654,14 @@ const getLiveStreamTopic = () => {
|
|
|
1587
1654
|
const getLiveReactionTopic = (post) => {
|
|
1588
1655
|
return `${post.path}/liveReaction`;
|
|
1589
1656
|
};
|
|
1657
|
+
const getRoomWatcherTopic = (room) => {
|
|
1658
|
+
const user = getCurrentUser();
|
|
1659
|
+
return `${getNetworkId(user)}/room/${room._id}`;
|
|
1660
|
+
};
|
|
1661
|
+
const getRoomStreamerTopic = (room) => {
|
|
1662
|
+
const user = getCurrentUser();
|
|
1663
|
+
return `${getNetworkId(user)}/room/${room.roomId}/streamer`;
|
|
1664
|
+
};
|
|
1590
1665
|
function subscribeTopic(topic, callback) {
|
|
1591
1666
|
const { mqtt } = getActiveClient();
|
|
1592
1667
|
if (!mqtt)
|
|
@@ -21013,20 +21088,6 @@ const getChannelMessagePreview = (channelId) => {
|
|
|
21013
21088
|
return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
21014
21089
|
};
|
|
21015
21090
|
|
|
21016
|
-
const userLinkedObject = (user) => {
|
|
21017
|
-
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
21018
|
-
var _a;
|
|
21019
|
-
if (!user.avatarFileId)
|
|
21020
|
-
return undefined;
|
|
21021
|
-
const avatar = (_a = pullFromCache([
|
|
21022
|
-
'file',
|
|
21023
|
-
'get',
|
|
21024
|
-
`${user.avatarFileId}`,
|
|
21025
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21026
|
-
return avatar;
|
|
21027
|
-
} });
|
|
21028
|
-
};
|
|
21029
|
-
|
|
21030
21091
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
21031
21092
|
var _a;
|
|
21032
21093
|
const messagePreview = channel.messagePreviewId
|
|
@@ -24542,11 +24603,11 @@ var objectResolverEngineOnLoginHandler = () => {
|
|
|
24542
24603
|
* @category Live Reaction API
|
|
24543
24604
|
* @async
|
|
24544
24605
|
*/
|
|
24545
|
-
const createLiveReaction = async ({ reactions,
|
|
24606
|
+
const createLiveReaction = async ({ reactions, roomId, }) => {
|
|
24546
24607
|
const client = getActiveClient();
|
|
24547
24608
|
client.log('live_reaction/addReaction', reactions);
|
|
24548
24609
|
const { data } = await client.http.post(`/api/v1/reactions/live`, {
|
|
24549
|
-
|
|
24610
|
+
roomId,
|
|
24550
24611
|
reactions,
|
|
24551
24612
|
});
|
|
24552
24613
|
return data;
|
|
@@ -24604,19 +24665,19 @@ class LiveReactionSyncEngine {
|
|
|
24604
24665
|
// Clear buffer
|
|
24605
24666
|
this.clearBuffer();
|
|
24606
24667
|
const payloads = reactions.reduce((prev, curr) => {
|
|
24607
|
-
const {
|
|
24608
|
-
if (!prev[
|
|
24668
|
+
const { roomId } = curr, rest = __rest(curr, ["roomId"]);
|
|
24669
|
+
if (!prev[roomId]) {
|
|
24609
24670
|
// eslint-disable-next-line no-param-reassign
|
|
24610
|
-
prev[
|
|
24671
|
+
prev[roomId] = [rest];
|
|
24611
24672
|
}
|
|
24612
24673
|
else
|
|
24613
|
-
prev[
|
|
24674
|
+
prev[roomId].push(rest);
|
|
24614
24675
|
return prev;
|
|
24615
24676
|
}, {});
|
|
24616
24677
|
// Call server api `POST /api/v1/reactions/live` to sync live reactions
|
|
24617
|
-
Object.entries(payloads).forEach(([
|
|
24678
|
+
Object.entries(payloads).forEach(([roomId, reactions]) => {
|
|
24618
24679
|
createLiveReaction({
|
|
24619
|
-
|
|
24680
|
+
roomId,
|
|
24620
24681
|
reactions,
|
|
24621
24682
|
});
|
|
24622
24683
|
});
|
|
@@ -25109,23 +25170,6 @@ const loginAsVisitor = async (params) => {
|
|
|
25109
25170
|
};
|
|
25110
25171
|
/* end_public_function */
|
|
25111
25172
|
|
|
25112
|
-
/* begin_public_function
|
|
25113
|
-
id: client.get_current_user
|
|
25114
|
-
*/
|
|
25115
|
-
const getCurrentUser = () => {
|
|
25116
|
-
var _a;
|
|
25117
|
-
const client = getActiveClient();
|
|
25118
|
-
if (!client) {
|
|
25119
|
-
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25120
|
-
}
|
|
25121
|
-
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25122
|
-
if (!cache) {
|
|
25123
|
-
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
25124
|
-
}
|
|
25125
|
-
return userLinkedObject(cache);
|
|
25126
|
-
};
|
|
25127
|
-
/* end_public_function */
|
|
25128
|
-
|
|
25129
25173
|
/* begin_public_function
|
|
25130
25174
|
id: client.renew_access_token
|
|
25131
25175
|
*/
|
|
@@ -26555,7 +26599,7 @@ const getUserUnread = (callback) => {
|
|
|
26555
26599
|
};
|
|
26556
26600
|
};
|
|
26557
26601
|
|
|
26558
|
-
var index$
|
|
26602
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
26559
26603
|
__proto__: null,
|
|
26560
26604
|
getActiveClient: getActiveClient,
|
|
26561
26605
|
getActiveUser: getActiveUser,
|
|
@@ -27774,7 +27818,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27774
27818
|
};
|
|
27775
27819
|
/* end_public_function */
|
|
27776
27820
|
|
|
27777
|
-
var index$
|
|
27821
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
27778
27822
|
__proto__: null,
|
|
27779
27823
|
blockUser: blockUser,
|
|
27780
27824
|
unBlockUser: unBlockUser,
|
|
@@ -28127,7 +28171,7 @@ getChannel$1.locally = (channelId) => {
|
|
|
28127
28171
|
* @category Stream API
|
|
28128
28172
|
* @async
|
|
28129
28173
|
*/
|
|
28130
|
-
const getLiveChat = async (stream) => {
|
|
28174
|
+
const getLiveChat$1 = async (stream) => {
|
|
28131
28175
|
var _a;
|
|
28132
28176
|
const client = getActiveClient();
|
|
28133
28177
|
client.log('stream/getLiveChat', stream.streamId);
|
|
@@ -28194,7 +28238,7 @@ const streamLinkedObject = (stream) => {
|
|
|
28194
28238
|
return streamLinkedObject(streamCache);
|
|
28195
28239
|
})
|
|
28196
28240
|
.filter(isNonNullable);
|
|
28197
|
-
}, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
|
|
28241
|
+
}, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
|
|
28198
28242
|
return stream.watcherUrl;
|
|
28199
28243
|
} });
|
|
28200
28244
|
};
|
|
@@ -28309,320 +28353,877 @@ function isAmityRoomPost(post) {
|
|
|
28309
28353
|
post.dataType === 'room');
|
|
28310
28354
|
}
|
|
28311
28355
|
|
|
28312
|
-
|
|
28313
|
-
|
|
28314
|
-
|
|
28315
|
-
|
|
28316
|
-
|
|
28317
|
-
|
|
28318
|
-
|
|
28319
|
-
|
|
28320
|
-
|
|
28321
|
-
|
|
28322
|
-
|
|
28323
|
-
|
|
28324
|
-
|
|
28325
|
-
|
|
28326
|
-
|
|
28327
|
-
|
|
28328
|
-
|
|
28329
|
-
|
|
28330
|
-
|
|
28331
|
-
|
|
28332
|
-
|
|
28333
|
-
|
|
28334
|
-
|
|
28335
|
-
|
|
28336
|
-
|
|
28337
|
-
|
|
28338
|
-
|
|
28339
|
-
|
|
28340
|
-
|
|
28341
|
-
|
|
28342
|
-
|
|
28343
|
-
|
|
28344
|
-
|
|
28345
|
-
|
|
28346
|
-
|
|
28347
|
-
|
|
28348
|
-
|
|
28349
|
-
|
|
28350
|
-
|
|
28351
|
-
|
|
28352
|
-
}
|
|
28353
|
-
|
|
28354
|
-
|
|
28355
|
-
|
|
28356
|
-
|
|
28357
|
-
: undefined;
|
|
28358
|
-
},
|
|
28359
|
-
getVideoThumbnailInfo() {
|
|
28360
|
-
var _a, _b;
|
|
28361
|
-
return isAmityVideoPost(post)
|
|
28362
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28363
|
-
: undefined;
|
|
28364
|
-
},
|
|
28365
|
-
getFileInfo() {
|
|
28366
|
-
var _a, _b;
|
|
28367
|
-
return isAmityFilePost(post)
|
|
28368
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28369
|
-
: undefined;
|
|
28370
|
-
},
|
|
28371
|
-
getLivestreamInfo() {
|
|
28372
|
-
var _a, _b;
|
|
28373
|
-
if (!isAmityLivestreamPost(post))
|
|
28374
|
-
return;
|
|
28375
|
-
const cache = (_b = pullFromCache([
|
|
28376
|
-
'stream',
|
|
28377
|
-
'get',
|
|
28378
|
-
(_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
|
|
28379
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28380
|
-
if (!cache)
|
|
28381
|
-
return;
|
|
28382
|
-
return streamLinkedObject(cache);
|
|
28383
|
-
},
|
|
28384
|
-
getPollInfo() {
|
|
28385
|
-
var _a, _b;
|
|
28386
|
-
if (!isAmityPollPost(post))
|
|
28387
|
-
return;
|
|
28388
|
-
const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28389
|
-
if (!cache)
|
|
28390
|
-
return;
|
|
28391
|
-
return cache;
|
|
28392
|
-
},
|
|
28393
|
-
getClipInfo() {
|
|
28394
|
-
var _a, _b;
|
|
28395
|
-
return isAmityClipPost(post)
|
|
28396
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28397
|
-
: undefined;
|
|
28398
|
-
},
|
|
28399
|
-
getAudioInfo() {
|
|
28400
|
-
var _a, _b;
|
|
28401
|
-
return isAmityAudioPost(post)
|
|
28402
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28403
|
-
: undefined;
|
|
28404
|
-
},
|
|
28405
|
-
getRoomInfo() {
|
|
28406
|
-
var _a, _b;
|
|
28407
|
-
if (!isAmityRoomPost(post))
|
|
28408
|
-
return;
|
|
28409
|
-
return (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28410
|
-
},
|
|
28411
|
-
});
|
|
28356
|
+
/**
|
|
28357
|
+
* ```js
|
|
28358
|
+
* import { RoomRepository } from '@amityco/ts-sdk'
|
|
28359
|
+
* const stream = await getStream('foobar')
|
|
28360
|
+
* ```
|
|
28361
|
+
*
|
|
28362
|
+
* Fetches a {@link Amity.Channel} object linked with a current stream
|
|
28363
|
+
*
|
|
28364
|
+
* @param stream {@link Amity.Stream} that has linked live channel
|
|
28365
|
+
* @returns the associated {@link Amity.Channel<'live'>} object
|
|
28366
|
+
*
|
|
28367
|
+
* @category Stream API
|
|
28368
|
+
* @async
|
|
28369
|
+
*/
|
|
28370
|
+
const getLiveChat = async (room) => {
|
|
28371
|
+
var _a;
|
|
28372
|
+
const client = getActiveClient();
|
|
28373
|
+
client.log('room/getLiveChat', room.roomId);
|
|
28374
|
+
if (room.liveChannelId) {
|
|
28375
|
+
const channel = (_a = pullFromCache([
|
|
28376
|
+
'channel',
|
|
28377
|
+
'get',
|
|
28378
|
+
room.liveChannelId,
|
|
28379
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28380
|
+
if (channel)
|
|
28381
|
+
return channelLinkedObject(constructChannelObject(channel));
|
|
28382
|
+
const { data } = await getChannel$1(room.liveChannelId);
|
|
28383
|
+
return channelLinkedObject(constructChannelObject(data));
|
|
28384
|
+
}
|
|
28385
|
+
// No Channel ID
|
|
28386
|
+
// streamer: create a new live channel
|
|
28387
|
+
if (room.createdBy === client.userId) {
|
|
28388
|
+
const { data: channel } = await createChannel({
|
|
28389
|
+
type: 'live',
|
|
28390
|
+
postId: room.referenceId,
|
|
28391
|
+
roomId: room.roomId,
|
|
28392
|
+
});
|
|
28393
|
+
// Update channelId to stream object in cache
|
|
28394
|
+
mergeInCache(['room', 'get', room.roomId], {
|
|
28395
|
+
liveChannelId: channel.channelId,
|
|
28396
|
+
});
|
|
28397
|
+
return channel;
|
|
28398
|
+
}
|
|
28399
|
+
// watcher: return undefined
|
|
28400
|
+
return undefined;
|
|
28412
28401
|
};
|
|
28413
28402
|
|
|
28414
|
-
|
|
28415
|
-
|
|
28416
|
-
if (referenceType === 'message')
|
|
28417
|
-
// @ts-ignore: refactor later
|
|
28418
|
-
fireEvent('local.message.updated', { messages: [model] });
|
|
28419
|
-
else if (referenceType === 'post')
|
|
28420
|
-
// @ts-ignore: refactor later
|
|
28421
|
-
fireEvent('post.updated', { posts: [model] });
|
|
28422
|
-
else if (referenceType === 'comment')
|
|
28423
|
-
// @ts-ignore: refactor later
|
|
28424
|
-
fireEvent('comment.updated', { comments: [model] });
|
|
28425
|
-
else if (referenceType === 'story')
|
|
28426
|
-
// Need to provide all data same StoryPayload from BE
|
|
28427
|
-
fireEvent('story.updated', {
|
|
28428
|
-
categories: [],
|
|
28429
|
-
comments: [],
|
|
28430
|
-
communities: [],
|
|
28431
|
-
communityUsers: [],
|
|
28432
|
-
files: [],
|
|
28433
|
-
users: [],
|
|
28434
|
-
stories: [model],
|
|
28435
|
-
});
|
|
28403
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
28404
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
28436
28405
|
};
|
|
28437
28406
|
|
|
28438
|
-
const
|
|
28439
|
-
|
|
28440
|
-
const client = getActiveClient();
|
|
28441
|
-
client.log('reaction/createReaction', {
|
|
28442
|
-
referenceId,
|
|
28443
|
-
referenceType,
|
|
28444
|
-
reactionName,
|
|
28445
|
-
});
|
|
28446
|
-
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
28447
|
-
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
28448
|
-
const { data } = await client.http.post('/api/v2/reactions', {
|
|
28449
|
-
referenceId,
|
|
28450
|
-
referenceType,
|
|
28451
|
-
reactionName,
|
|
28452
|
-
referenceVersion,
|
|
28453
|
-
});
|
|
28454
|
-
if (client.cache) {
|
|
28455
|
-
const model = pullFromCache([
|
|
28456
|
-
referenceType,
|
|
28457
|
-
'get',
|
|
28458
|
-
referenceId,
|
|
28459
|
-
]);
|
|
28460
|
-
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
28461
|
-
return true;
|
|
28462
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
|
|
28463
|
-
if (referenceType === 'comment') {
|
|
28464
|
-
fireEvent('local.comment.addReaction', {
|
|
28465
|
-
comment: updatedModel,
|
|
28466
|
-
reactor: {
|
|
28467
|
-
userId: client.userId,
|
|
28468
|
-
reactionName,
|
|
28469
|
-
reactionId: data.addedId,
|
|
28470
|
-
},
|
|
28471
|
-
});
|
|
28472
|
-
return true;
|
|
28473
|
-
}
|
|
28474
|
-
if (referenceType === 'post') {
|
|
28475
|
-
fireEvent('local.post.addReaction', {
|
|
28476
|
-
post: updatedModel,
|
|
28477
|
-
reactor: {
|
|
28478
|
-
userId: client.userId,
|
|
28479
|
-
reactionName,
|
|
28480
|
-
reactionId: data.addedId,
|
|
28481
|
-
},
|
|
28482
|
-
});
|
|
28483
|
-
return true;
|
|
28484
|
-
}
|
|
28485
|
-
if (referenceType === 'story') {
|
|
28486
|
-
fireEvent('local.story.reactionAdded', {
|
|
28487
|
-
story: updatedModel,
|
|
28488
|
-
reactor: {
|
|
28489
|
-
userId: client.userId,
|
|
28490
|
-
reactionName,
|
|
28491
|
-
reactionId: data.addedId,
|
|
28492
|
-
},
|
|
28493
|
-
});
|
|
28494
|
-
return true;
|
|
28495
|
-
}
|
|
28496
|
-
}
|
|
28497
|
-
return true;
|
|
28407
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
28408
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
28498
28409
|
};
|
|
28499
|
-
|
|
28500
|
-
|
|
28410
|
+
|
|
28411
|
+
/* begin_public_function
|
|
28412
|
+
id: invitation.createInvitations
|
|
28413
|
+
*/
|
|
28414
|
+
/**
|
|
28415
|
+
* ```js
|
|
28416
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
28417
|
+
* const created = await createInvitations({
|
|
28418
|
+
* type: string,
|
|
28419
|
+
* targetType: string,
|
|
28420
|
+
* targetId: string,
|
|
28421
|
+
* userIds: string[]
|
|
28422
|
+
* }))
|
|
28423
|
+
* ```
|
|
28424
|
+
*
|
|
28425
|
+
* Creates an {@link Amity.Invitation}
|
|
28426
|
+
*
|
|
28427
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
28428
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
28429
|
+
*
|
|
28430
|
+
* @category Invitation API
|
|
28431
|
+
* @async
|
|
28432
|
+
*/
|
|
28433
|
+
const createInvitations = async (bundle) => {
|
|
28501
28434
|
const client = getActiveClient();
|
|
28502
|
-
client.log('
|
|
28503
|
-
|
|
28504
|
-
|
|
28505
|
-
|
|
28506
|
-
|
|
28507
|
-
|
|
28508
|
-
|
|
28509
|
-
|
|
28510
|
-
|
|
28511
|
-
|
|
28512
|
-
|
|
28513
|
-
]);
|
|
28514
|
-
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
28515
|
-
return;
|
|
28516
|
-
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
28517
|
-
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
28518
|
-
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
28519
|
-
});
|
|
28520
|
-
dispatchReactable(referenceType, reaction);
|
|
28521
|
-
return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
|
|
28435
|
+
client.log('invitation/createInvitations', bundle);
|
|
28436
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
28437
|
+
const data = prepareInvitationPayload(payload);
|
|
28438
|
+
const cachedAt = client.cache && Date.now();
|
|
28439
|
+
if (client.cache)
|
|
28440
|
+
ingestInCache(data, { cachedAt });
|
|
28441
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
28442
|
+
return {
|
|
28443
|
+
data: data.invitations,
|
|
28444
|
+
cachedAt,
|
|
28445
|
+
};
|
|
28522
28446
|
};
|
|
28447
|
+
/* end_public_function */
|
|
28523
28448
|
|
|
28524
|
-
|
|
28525
|
-
|
|
28449
|
+
/* begin_public_function
|
|
28450
|
+
id: invitation.accept
|
|
28451
|
+
*/
|
|
28452
|
+
/**
|
|
28453
|
+
* ```js
|
|
28454
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
28455
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
28456
|
+
* ```
|
|
28457
|
+
*
|
|
28458
|
+
* Accepts a {@link Amity.Invitation} object
|
|
28459
|
+
*
|
|
28460
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
28461
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
28462
|
+
*
|
|
28463
|
+
* @category Invitation API
|
|
28464
|
+
* @async
|
|
28465
|
+
*/
|
|
28466
|
+
const acceptInvitation$1 = async (invitationId) => {
|
|
28467
|
+
var _a;
|
|
28526
28468
|
const client = getActiveClient();
|
|
28527
|
-
client.log('
|
|
28528
|
-
|
|
28529
|
-
|
|
28530
|
-
|
|
28531
|
-
|
|
28532
|
-
|
|
28533
|
-
|
|
28534
|
-
|
|
28535
|
-
|
|
28536
|
-
|
|
28537
|
-
referenceType,
|
|
28538
|
-
reactionName,
|
|
28539
|
-
referenceVersion,
|
|
28540
|
-
},
|
|
28541
|
-
});
|
|
28542
|
-
if (client.cache) {
|
|
28543
|
-
const model = pullFromCache([
|
|
28544
|
-
referenceType,
|
|
28545
|
-
'get',
|
|
28546
|
-
referenceId,
|
|
28547
|
-
]);
|
|
28548
|
-
if (!model)
|
|
28549
|
-
return true;
|
|
28550
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
|
|
28551
|
-
if (referenceType === 'comment') {
|
|
28552
|
-
fireEvent('local.comment.removeReaction', {
|
|
28553
|
-
comment: updatedModel,
|
|
28554
|
-
reactor: {
|
|
28555
|
-
reactionId: data.removedId,
|
|
28556
|
-
reactionName,
|
|
28557
|
-
userId: client.userId,
|
|
28558
|
-
},
|
|
28559
|
-
});
|
|
28560
|
-
return true;
|
|
28561
|
-
}
|
|
28562
|
-
if (referenceType === 'post') {
|
|
28563
|
-
fireEvent('local.post.removeReaction', {
|
|
28564
|
-
post: updatedModel,
|
|
28565
|
-
reactor: {
|
|
28566
|
-
reactionId: data.removedId,
|
|
28567
|
-
reactionName,
|
|
28568
|
-
userId: client.userId,
|
|
28569
|
-
},
|
|
28570
|
-
});
|
|
28571
|
-
return true;
|
|
28572
|
-
}
|
|
28573
|
-
if (referenceType === 'story') {
|
|
28574
|
-
fireEvent('local.story.reactionAdded', {
|
|
28575
|
-
story: updatedModel,
|
|
28576
|
-
reactor: {
|
|
28577
|
-
userId: client.userId,
|
|
28578
|
-
reactionName,
|
|
28579
|
-
reactionId: data.removedId,
|
|
28580
|
-
},
|
|
28581
|
-
});
|
|
28582
|
-
return true;
|
|
28583
|
-
}
|
|
28469
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
28470
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
28471
|
+
const invitation = (_a = pullFromCache([
|
|
28472
|
+
'invitation',
|
|
28473
|
+
'get',
|
|
28474
|
+
invitationId,
|
|
28475
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28476
|
+
if (invitation) {
|
|
28477
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
28478
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
28584
28479
|
}
|
|
28585
|
-
return
|
|
28586
|
-
};
|
|
28587
|
-
|
|
28588
|
-
const addReactionToMessage = (reactionName, message) => {
|
|
28589
|
-
const isMessageV3 = message.publicId !== message.messageId;
|
|
28590
|
-
return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
28480
|
+
return data.success;
|
|
28591
28481
|
};
|
|
28482
|
+
/* end_public_function */
|
|
28592
28483
|
|
|
28593
|
-
|
|
28594
|
-
|
|
28595
|
-
|
|
28596
|
-
|
|
28597
|
-
|
|
28598
|
-
|
|
28599
|
-
|
|
28600
|
-
|
|
28601
|
-
|
|
28484
|
+
/* begin_public_function
|
|
28485
|
+
id: invitation.reject
|
|
28486
|
+
*/
|
|
28487
|
+
/**
|
|
28488
|
+
* ```js
|
|
28489
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
28490
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
28491
|
+
* ```
|
|
28492
|
+
*
|
|
28493
|
+
* Rejects a {@link Amity.Invitation} object
|
|
28494
|
+
*
|
|
28495
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
28496
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
28497
|
+
*
|
|
28498
|
+
* @category Invitation API
|
|
28499
|
+
* @async
|
|
28500
|
+
*/
|
|
28501
|
+
const rejectInvitation = async (invitationId) => {
|
|
28502
|
+
var _a;
|
|
28503
|
+
const client = getActiveClient();
|
|
28504
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
28505
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
28506
|
+
const invitation = (_a = pullFromCache([
|
|
28507
|
+
'invitation',
|
|
28602
28508
|
'get',
|
|
28603
|
-
|
|
28604
|
-
])) === null ||
|
|
28509
|
+
invitationId,
|
|
28510
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28511
|
+
if (invitation) {
|
|
28512
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
28513
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
28514
|
+
}
|
|
28515
|
+
return data.success;
|
|
28605
28516
|
};
|
|
28606
|
-
|
|
28607
|
-
var _a;
|
|
28608
|
-
// Look in the marker param first
|
|
28609
|
-
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
28610
|
-
// If the marker param is not set, look in the cache
|
|
28611
|
-
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
28612
|
-
}; // and if not found in cache use default value `0`
|
|
28517
|
+
/* end_public_function */
|
|
28613
28518
|
|
|
28614
|
-
|
|
28615
|
-
|
|
28616
|
-
|
|
28617
|
-
|
|
28519
|
+
var InvitationActionsEnum;
|
|
28520
|
+
(function (InvitationActionsEnum) {
|
|
28521
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
28522
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
28523
|
+
InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
|
|
28524
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
28618
28525
|
|
|
28619
|
-
const
|
|
28620
|
-
|
|
28621
|
-
|
|
28622
|
-
|
|
28526
|
+
const invitationLinkedObject = (invitation) => {
|
|
28527
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
28528
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
28529
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
28530
|
+
return userLinkedObject(cacheData.data);
|
|
28531
|
+
return undefined;
|
|
28623
28532
|
},
|
|
28624
|
-
get
|
|
28625
|
-
|
|
28533
|
+
get createdBy() {
|
|
28534
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
28535
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
28536
|
+
return userLinkedObject(cacheData.data);
|
|
28537
|
+
return undefined;
|
|
28538
|
+
},
|
|
28539
|
+
get target() {
|
|
28540
|
+
if (invitation.targetType === 'community') {
|
|
28541
|
+
const cacheData = pullFromCache([
|
|
28542
|
+
'community',
|
|
28543
|
+
'get',
|
|
28544
|
+
invitation.targetId,
|
|
28545
|
+
]);
|
|
28546
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
28547
|
+
return cacheData.data;
|
|
28548
|
+
return undefined;
|
|
28549
|
+
}
|
|
28550
|
+
return undefined;
|
|
28551
|
+
}, accept: async () => {
|
|
28552
|
+
await acceptInvitation$1(invitation._id);
|
|
28553
|
+
}, reject: async () => {
|
|
28554
|
+
await rejectInvitation(invitation._id);
|
|
28555
|
+
} });
|
|
28556
|
+
};
|
|
28557
|
+
|
|
28558
|
+
class InvitationsPaginationController extends PaginationController {
|
|
28559
|
+
async getRequest(queryParams, token) {
|
|
28560
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
28561
|
+
const options = token ? { token } : { limit };
|
|
28562
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
28563
|
+
return data;
|
|
28564
|
+
}
|
|
28565
|
+
}
|
|
28566
|
+
|
|
28567
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
28568
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
28569
|
+
super(query, cacheKey);
|
|
28570
|
+
this.notifyChange = notifyChange;
|
|
28571
|
+
this.preparePayload = preparePayload;
|
|
28572
|
+
}
|
|
28573
|
+
async saveToMainDB(response) {
|
|
28574
|
+
const processedPayload = await this.preparePayload(response);
|
|
28575
|
+
const client = getActiveClient();
|
|
28576
|
+
const cachedAt = client.cache && Date.now();
|
|
28577
|
+
if (client.cache) {
|
|
28578
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
28579
|
+
}
|
|
28580
|
+
}
|
|
28581
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
28582
|
+
var _a, _b;
|
|
28583
|
+
if (refresh) {
|
|
28584
|
+
pushToCache(this.cacheKey, {
|
|
28585
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
28586
|
+
});
|
|
28587
|
+
}
|
|
28588
|
+
else {
|
|
28589
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28590
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28591
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
28592
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
28593
|
+
] }));
|
|
28594
|
+
}
|
|
28595
|
+
}
|
|
28596
|
+
reactor(action) {
|
|
28597
|
+
return (invitations) => {
|
|
28598
|
+
var _a;
|
|
28599
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28600
|
+
if (!collection)
|
|
28601
|
+
return;
|
|
28602
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
28603
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
28604
|
+
if (!isExist)
|
|
28605
|
+
return;
|
|
28606
|
+
}
|
|
28607
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
28608
|
+
collection.data = [
|
|
28609
|
+
...new Set([
|
|
28610
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
28611
|
+
...collection.data,
|
|
28612
|
+
]),
|
|
28613
|
+
];
|
|
28614
|
+
}
|
|
28615
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
28616
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
28617
|
+
}
|
|
28618
|
+
pushToCache(this.cacheKey, collection);
|
|
28619
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28620
|
+
};
|
|
28621
|
+
}
|
|
28622
|
+
subscribeRTE(createSubscriber) {
|
|
28623
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28624
|
+
}
|
|
28625
|
+
}
|
|
28626
|
+
|
|
28627
|
+
/**
|
|
28628
|
+
* ```js
|
|
28629
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
28630
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
28631
|
+
* // ...
|
|
28632
|
+
* })
|
|
28633
|
+
* ```
|
|
28634
|
+
*
|
|
28635
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
28636
|
+
*
|
|
28637
|
+
* @param callback The function to call when the event was fired
|
|
28638
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28639
|
+
*
|
|
28640
|
+
* @category Invitation Events
|
|
28641
|
+
*/
|
|
28642
|
+
const onLocalInvitationCreated = (callback) => {
|
|
28643
|
+
const client = getActiveClient();
|
|
28644
|
+
const disposers = [
|
|
28645
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
28646
|
+
];
|
|
28647
|
+
return () => {
|
|
28648
|
+
disposers.forEach(fn => fn());
|
|
28649
|
+
};
|
|
28650
|
+
};
|
|
28651
|
+
|
|
28652
|
+
/**
|
|
28653
|
+
* ```js
|
|
28654
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
28655
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
28656
|
+
* // ...
|
|
28657
|
+
* })
|
|
28658
|
+
* ```
|
|
28659
|
+
*
|
|
28660
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
28661
|
+
*
|
|
28662
|
+
* @param callback The function to call when the event was fired
|
|
28663
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28664
|
+
*
|
|
28665
|
+
* @category Invitation Events
|
|
28666
|
+
*/
|
|
28667
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
28668
|
+
const client = getActiveClient();
|
|
28669
|
+
const disposers = [
|
|
28670
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
28671
|
+
];
|
|
28672
|
+
return () => {
|
|
28673
|
+
disposers.forEach(fn => fn());
|
|
28674
|
+
};
|
|
28675
|
+
};
|
|
28676
|
+
|
|
28677
|
+
/**
|
|
28678
|
+
* ```js
|
|
28679
|
+
* import { onLocalInvitationCanceled } from '@amityco/ts-sdk'
|
|
28680
|
+
* const dispose = onLocalInvitationCanceled(data => {
|
|
28681
|
+
* // ...
|
|
28682
|
+
* })
|
|
28683
|
+
* ```
|
|
28684
|
+
*
|
|
28685
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
28686
|
+
*
|
|
28687
|
+
* @param callback The function to call when the event was fired
|
|
28688
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28689
|
+
*
|
|
28690
|
+
* @category Invitation Events
|
|
28691
|
+
*/
|
|
28692
|
+
const onLocalInvitationCanceled = (callback) => {
|
|
28693
|
+
const client = getActiveClient();
|
|
28694
|
+
const disposers = [
|
|
28695
|
+
createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
|
|
28696
|
+
];
|
|
28697
|
+
return () => {
|
|
28698
|
+
disposers.forEach(fn => fn());
|
|
28699
|
+
};
|
|
28700
|
+
};
|
|
28701
|
+
|
|
28702
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
28703
|
+
constructor(query, callback) {
|
|
28704
|
+
const queryStreamId = hash(query);
|
|
28705
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
28706
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
28707
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
28708
|
+
this.query = query;
|
|
28709
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
28710
|
+
this.callback = callback.bind(this);
|
|
28711
|
+
this.loadPage({ initial: true });
|
|
28712
|
+
}
|
|
28713
|
+
setup() {
|
|
28714
|
+
var _a;
|
|
28715
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28716
|
+
if (!collection) {
|
|
28717
|
+
pushToCache(this.cacheKey, {
|
|
28718
|
+
data: [],
|
|
28719
|
+
params: this.query,
|
|
28720
|
+
});
|
|
28721
|
+
}
|
|
28722
|
+
}
|
|
28723
|
+
async persistModel(queryPayload) {
|
|
28724
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
28725
|
+
}
|
|
28726
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28727
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28728
|
+
}
|
|
28729
|
+
startSubscription() {
|
|
28730
|
+
return this.queryStreamController.subscribeRTE([
|
|
28731
|
+
{
|
|
28732
|
+
fn: onLocalInvitationCreated,
|
|
28733
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
28734
|
+
},
|
|
28735
|
+
{
|
|
28736
|
+
fn: onLocalInvitationUpdated,
|
|
28737
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
28738
|
+
},
|
|
28739
|
+
{
|
|
28740
|
+
fn: onLocalInvitationCanceled,
|
|
28741
|
+
action: InvitationActionsEnum.OnLocalInvitationCanceled,
|
|
28742
|
+
},
|
|
28743
|
+
]);
|
|
28744
|
+
}
|
|
28745
|
+
notifyChange({ origin, loading, error }) {
|
|
28746
|
+
var _a, _b;
|
|
28747
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28748
|
+
if (!collection)
|
|
28749
|
+
return;
|
|
28750
|
+
const data = this.applyFilter((_b = collection.data
|
|
28751
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
28752
|
+
.filter(isNonNullable)
|
|
28753
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
28754
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28755
|
+
return;
|
|
28756
|
+
this.callback({
|
|
28757
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28758
|
+
data,
|
|
28759
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28760
|
+
loading,
|
|
28761
|
+
error,
|
|
28762
|
+
});
|
|
28763
|
+
}
|
|
28764
|
+
applyFilter(data) {
|
|
28765
|
+
let invitations = data;
|
|
28766
|
+
if (this.query.targetId) {
|
|
28767
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
28768
|
+
}
|
|
28769
|
+
if (this.query.statuses) {
|
|
28770
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
28771
|
+
}
|
|
28772
|
+
if (this.query.targetType) {
|
|
28773
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
28774
|
+
}
|
|
28775
|
+
if (this.query.type) {
|
|
28776
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
28777
|
+
}
|
|
28778
|
+
const sortFn = (() => {
|
|
28779
|
+
switch (this.query.sortBy) {
|
|
28780
|
+
case 'firstCreated':
|
|
28781
|
+
return sortByFirstCreated;
|
|
28782
|
+
case 'lastCreated':
|
|
28783
|
+
return sortByLastCreated;
|
|
28784
|
+
default:
|
|
28785
|
+
return sortByLastCreated;
|
|
28786
|
+
}
|
|
28787
|
+
})();
|
|
28788
|
+
invitations = invitations.sort(sortFn);
|
|
28789
|
+
return invitations;
|
|
28790
|
+
}
|
|
28791
|
+
}
|
|
28792
|
+
|
|
28793
|
+
/**
|
|
28794
|
+
* Get invitations
|
|
28795
|
+
*
|
|
28796
|
+
* @param params the query parameters
|
|
28797
|
+
* @param callback the callback to be called when the invitations are updated
|
|
28798
|
+
* @returns invitations
|
|
28799
|
+
*
|
|
28800
|
+
* @category Invitation Live Collection
|
|
28801
|
+
*
|
|
28802
|
+
*/
|
|
28803
|
+
const getInvitations = (params, callback, config) => {
|
|
28804
|
+
const { log, cache } = getActiveClient();
|
|
28805
|
+
if (!cache) {
|
|
28806
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28807
|
+
}
|
|
28808
|
+
const timestamp = Date.now();
|
|
28809
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
28810
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
28811
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
28812
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
28813
|
+
disposers.push(() => {
|
|
28814
|
+
dropFromCache(cacheKey);
|
|
28815
|
+
});
|
|
28816
|
+
return () => {
|
|
28817
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
28818
|
+
disposers.forEach(fn => fn());
|
|
28819
|
+
};
|
|
28820
|
+
};
|
|
28821
|
+
|
|
28822
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
28823
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
28824
|
+
};
|
|
28825
|
+
|
|
28826
|
+
/* begin_public_function
|
|
28827
|
+
id: invitation.get
|
|
28828
|
+
*/
|
|
28829
|
+
/**
|
|
28830
|
+
* ```js
|
|
28831
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
28832
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
28833
|
+
* ```
|
|
28834
|
+
*
|
|
28835
|
+
* Get a {@link Amity.Invitation} object
|
|
28836
|
+
*
|
|
28837
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
28838
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
28839
|
+
* @returns A {@link Amity.Invitation} object
|
|
28840
|
+
*
|
|
28841
|
+
* @category Invitation API
|
|
28842
|
+
* @async
|
|
28843
|
+
*/
|
|
28844
|
+
const getInvitation = async (params) => {
|
|
28845
|
+
const client = getActiveClient();
|
|
28846
|
+
client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
|
|
28847
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
|
|
28848
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
28849
|
+
const cachedAt = client.cache && Date.now();
|
|
28850
|
+
if (client.cache)
|
|
28851
|
+
ingestInCache(data, { cachedAt });
|
|
28852
|
+
return {
|
|
28853
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
28854
|
+
cachedAt,
|
|
28855
|
+
};
|
|
28856
|
+
};
|
|
28857
|
+
/* end_public_function */
|
|
28858
|
+
|
|
28859
|
+
const roomLinkedObject = (room) => {
|
|
28860
|
+
return Object.assign(Object.assign({}, room), { get moderation() {
|
|
28861
|
+
var _a;
|
|
28862
|
+
return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28863
|
+
},
|
|
28864
|
+
get post() {
|
|
28865
|
+
var _a;
|
|
28866
|
+
if (room.referenceType !== 'post')
|
|
28867
|
+
return;
|
|
28868
|
+
return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28869
|
+
},
|
|
28870
|
+
get community() {
|
|
28871
|
+
var _a;
|
|
28872
|
+
if (room.targetType !== 'community')
|
|
28873
|
+
return;
|
|
28874
|
+
return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28875
|
+
},
|
|
28876
|
+
get user() {
|
|
28877
|
+
var _a;
|
|
28878
|
+
const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28879
|
+
return user ? userLinkedObject(user) : user;
|
|
28880
|
+
},
|
|
28881
|
+
get childRooms() {
|
|
28882
|
+
if (!room.childRoomIds || room.childRoomIds.length === 0)
|
|
28883
|
+
return [];
|
|
28884
|
+
return room.childRoomIds
|
|
28885
|
+
.map(id => {
|
|
28886
|
+
var _a;
|
|
28887
|
+
const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28888
|
+
if (!roomCache)
|
|
28889
|
+
return undefined;
|
|
28890
|
+
return roomLinkedObject(roomCache);
|
|
28891
|
+
})
|
|
28892
|
+
.filter(isNonNullable);
|
|
28893
|
+
}, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
|
|
28894
|
+
var _a;
|
|
28895
|
+
const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28896
|
+
return user ? userLinkedObject(user) : user;
|
|
28897
|
+
} }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
|
|
28898
|
+
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
28899
|
+
targetType: 'room',
|
|
28900
|
+
targetId: room.roomId,
|
|
28901
|
+
userIds: [userId],
|
|
28902
|
+
}), getInvitations: (params, callback) => getInvitations(Object.assign(Object.assign({}, params), { targetId: room.roomId, targetType: 'room', type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */ }), callback), getMyInvitation: async () => {
|
|
28903
|
+
const { data } = await getInvitation({
|
|
28904
|
+
targetId: room.roomId,
|
|
28905
|
+
targetType: 'room',
|
|
28906
|
+
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
28907
|
+
});
|
|
28908
|
+
return data;
|
|
28909
|
+
} });
|
|
28910
|
+
};
|
|
28911
|
+
|
|
28912
|
+
const postLinkedObject = (post) => {
|
|
28913
|
+
return shallowClone(post, {
|
|
28914
|
+
childrenPosts: post.children
|
|
28915
|
+
.map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
28916
|
+
.filter(isNonNullable)
|
|
28917
|
+
.map(postLinkedObject),
|
|
28918
|
+
analytics: {
|
|
28919
|
+
markAsViewed: () => {
|
|
28920
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
28921
|
+
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
28922
|
+
},
|
|
28923
|
+
},
|
|
28924
|
+
get latestComments() {
|
|
28925
|
+
if (!post.comments)
|
|
28926
|
+
return [];
|
|
28927
|
+
return (post.comments
|
|
28928
|
+
.map(commentId => {
|
|
28929
|
+
var _a;
|
|
28930
|
+
const commentCached = (_a = pullFromCache([
|
|
28931
|
+
'comment',
|
|
28932
|
+
'get',
|
|
28933
|
+
commentId,
|
|
28934
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28935
|
+
if (!commentCached)
|
|
28936
|
+
return null;
|
|
28937
|
+
return commentLinkedObject(commentCached);
|
|
28938
|
+
})
|
|
28939
|
+
.filter(Boolean) || []);
|
|
28940
|
+
},
|
|
28941
|
+
get creator() {
|
|
28942
|
+
const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
|
|
28943
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
28944
|
+
return;
|
|
28945
|
+
return userLinkedObject(cacheData.data);
|
|
28946
|
+
},
|
|
28947
|
+
getImageInfo() {
|
|
28948
|
+
var _a, _b;
|
|
28949
|
+
return isAmityImagePost(post)
|
|
28950
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28951
|
+
: undefined;
|
|
28952
|
+
},
|
|
28953
|
+
getVideoInfo() {
|
|
28954
|
+
var _a, _b, _c;
|
|
28955
|
+
return isAmityVideoPost(post)
|
|
28956
|
+
? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
|
|
28957
|
+
: undefined;
|
|
28958
|
+
},
|
|
28959
|
+
getVideoThumbnailInfo() {
|
|
28960
|
+
var _a, _b;
|
|
28961
|
+
return isAmityVideoPost(post)
|
|
28962
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28963
|
+
: undefined;
|
|
28964
|
+
},
|
|
28965
|
+
getFileInfo() {
|
|
28966
|
+
var _a, _b;
|
|
28967
|
+
return isAmityFilePost(post)
|
|
28968
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28969
|
+
: undefined;
|
|
28970
|
+
},
|
|
28971
|
+
getLivestreamInfo() {
|
|
28972
|
+
var _a, _b;
|
|
28973
|
+
if (!isAmityLivestreamPost(post))
|
|
28974
|
+
return;
|
|
28975
|
+
const cache = (_b = pullFromCache([
|
|
28976
|
+
'stream',
|
|
28977
|
+
'get',
|
|
28978
|
+
(_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
|
|
28979
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28980
|
+
if (!cache)
|
|
28981
|
+
return;
|
|
28982
|
+
return streamLinkedObject(cache);
|
|
28983
|
+
},
|
|
28984
|
+
getPollInfo() {
|
|
28985
|
+
var _a, _b;
|
|
28986
|
+
if (!isAmityPollPost(post))
|
|
28987
|
+
return;
|
|
28988
|
+
const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28989
|
+
if (!cache)
|
|
28990
|
+
return;
|
|
28991
|
+
return cache;
|
|
28992
|
+
},
|
|
28993
|
+
getClipInfo() {
|
|
28994
|
+
var _a, _b;
|
|
28995
|
+
return isAmityClipPost(post)
|
|
28996
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28997
|
+
: undefined;
|
|
28998
|
+
},
|
|
28999
|
+
getAudioInfo() {
|
|
29000
|
+
var _a, _b;
|
|
29001
|
+
return isAmityAudioPost(post)
|
|
29002
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29003
|
+
: undefined;
|
|
29004
|
+
},
|
|
29005
|
+
getRoomInfo() {
|
|
29006
|
+
var _a, _b;
|
|
29007
|
+
if (!isAmityRoomPost(post))
|
|
29008
|
+
return;
|
|
29009
|
+
const room = (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29010
|
+
return room ? roomLinkedObject(room) : undefined;
|
|
29011
|
+
},
|
|
29012
|
+
});
|
|
29013
|
+
};
|
|
29014
|
+
|
|
29015
|
+
/** @hidden */
|
|
29016
|
+
const dispatchReactable = (referenceType, model) => {
|
|
29017
|
+
if (referenceType === 'message')
|
|
29018
|
+
// @ts-ignore: refactor later
|
|
29019
|
+
fireEvent('local.message.updated', { messages: [model] });
|
|
29020
|
+
else if (referenceType === 'post')
|
|
29021
|
+
// @ts-ignore: refactor later
|
|
29022
|
+
fireEvent('post.updated', { posts: [model] });
|
|
29023
|
+
else if (referenceType === 'comment')
|
|
29024
|
+
// @ts-ignore: refactor later
|
|
29025
|
+
fireEvent('comment.updated', { comments: [model] });
|
|
29026
|
+
else if (referenceType === 'story')
|
|
29027
|
+
// Need to provide all data same StoryPayload from BE
|
|
29028
|
+
fireEvent('story.updated', {
|
|
29029
|
+
categories: [],
|
|
29030
|
+
comments: [],
|
|
29031
|
+
communities: [],
|
|
29032
|
+
communityUsers: [],
|
|
29033
|
+
files: [],
|
|
29034
|
+
users: [],
|
|
29035
|
+
stories: [model],
|
|
29036
|
+
});
|
|
29037
|
+
};
|
|
29038
|
+
|
|
29039
|
+
const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29040
|
+
var _a, _b, _c;
|
|
29041
|
+
const client = getActiveClient();
|
|
29042
|
+
client.log('reaction/createReaction', {
|
|
29043
|
+
referenceId,
|
|
29044
|
+
referenceType,
|
|
29045
|
+
reactionName,
|
|
29046
|
+
});
|
|
29047
|
+
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29048
|
+
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29049
|
+
const { data } = await client.http.post('/api/v2/reactions', {
|
|
29050
|
+
referenceId,
|
|
29051
|
+
referenceType,
|
|
29052
|
+
reactionName,
|
|
29053
|
+
referenceVersion,
|
|
29054
|
+
});
|
|
29055
|
+
if (client.cache) {
|
|
29056
|
+
const model = pullFromCache([
|
|
29057
|
+
referenceType,
|
|
29058
|
+
'get',
|
|
29059
|
+
referenceId,
|
|
29060
|
+
]);
|
|
29061
|
+
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29062
|
+
return true;
|
|
29063
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
|
|
29064
|
+
if (referenceType === 'comment') {
|
|
29065
|
+
fireEvent('local.comment.addReaction', {
|
|
29066
|
+
comment: updatedModel,
|
|
29067
|
+
reactor: {
|
|
29068
|
+
userId: client.userId,
|
|
29069
|
+
reactionName,
|
|
29070
|
+
reactionId: data.addedId,
|
|
29071
|
+
},
|
|
29072
|
+
});
|
|
29073
|
+
return true;
|
|
29074
|
+
}
|
|
29075
|
+
if (referenceType === 'post') {
|
|
29076
|
+
fireEvent('local.post.addReaction', {
|
|
29077
|
+
post: updatedModel,
|
|
29078
|
+
reactor: {
|
|
29079
|
+
userId: client.userId,
|
|
29080
|
+
reactionName,
|
|
29081
|
+
reactionId: data.addedId,
|
|
29082
|
+
},
|
|
29083
|
+
});
|
|
29084
|
+
return true;
|
|
29085
|
+
}
|
|
29086
|
+
if (referenceType === 'story') {
|
|
29087
|
+
fireEvent('local.story.reactionAdded', {
|
|
29088
|
+
story: updatedModel,
|
|
29089
|
+
reactor: {
|
|
29090
|
+
userId: client.userId,
|
|
29091
|
+
reactionName,
|
|
29092
|
+
reactionId: data.addedId,
|
|
29093
|
+
},
|
|
29094
|
+
});
|
|
29095
|
+
return true;
|
|
29096
|
+
}
|
|
29097
|
+
}
|
|
29098
|
+
return true;
|
|
29099
|
+
};
|
|
29100
|
+
addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
|
|
29101
|
+
var _a, _b, _c, _d, _e;
|
|
29102
|
+
const client = getActiveClient();
|
|
29103
|
+
client.log('reaction/createReaction.optimistically', {
|
|
29104
|
+
referenceId,
|
|
29105
|
+
referenceType,
|
|
29106
|
+
reactionName,
|
|
29107
|
+
});
|
|
29108
|
+
if (!client.cache)
|
|
29109
|
+
return;
|
|
29110
|
+
const model = pullFromCache([
|
|
29111
|
+
referenceType,
|
|
29112
|
+
'get',
|
|
29113
|
+
referenceId,
|
|
29114
|
+
]);
|
|
29115
|
+
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29116
|
+
return;
|
|
29117
|
+
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
29118
|
+
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
29119
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
29120
|
+
});
|
|
29121
|
+
dispatchReactable(referenceType, reaction);
|
|
29122
|
+
return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
|
|
29123
|
+
};
|
|
29124
|
+
|
|
29125
|
+
const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29126
|
+
var _a, _b;
|
|
29127
|
+
const client = getActiveClient();
|
|
29128
|
+
client.log('reaction/removeReaction', {
|
|
29129
|
+
referenceId,
|
|
29130
|
+
referenceType,
|
|
29131
|
+
reactionName,
|
|
29132
|
+
});
|
|
29133
|
+
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29134
|
+
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29135
|
+
const { data } = await client.http.delete(`/api/v2/reactions`, {
|
|
29136
|
+
data: {
|
|
29137
|
+
referenceId,
|
|
29138
|
+
referenceType,
|
|
29139
|
+
reactionName,
|
|
29140
|
+
referenceVersion,
|
|
29141
|
+
},
|
|
29142
|
+
});
|
|
29143
|
+
if (client.cache) {
|
|
29144
|
+
const model = pullFromCache([
|
|
29145
|
+
referenceType,
|
|
29146
|
+
'get',
|
|
29147
|
+
referenceId,
|
|
29148
|
+
]);
|
|
29149
|
+
if (!model)
|
|
29150
|
+
return true;
|
|
29151
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
|
|
29152
|
+
if (referenceType === 'comment') {
|
|
29153
|
+
fireEvent('local.comment.removeReaction', {
|
|
29154
|
+
comment: updatedModel,
|
|
29155
|
+
reactor: {
|
|
29156
|
+
reactionId: data.removedId,
|
|
29157
|
+
reactionName,
|
|
29158
|
+
userId: client.userId,
|
|
29159
|
+
},
|
|
29160
|
+
});
|
|
29161
|
+
return true;
|
|
29162
|
+
}
|
|
29163
|
+
if (referenceType === 'post') {
|
|
29164
|
+
fireEvent('local.post.removeReaction', {
|
|
29165
|
+
post: updatedModel,
|
|
29166
|
+
reactor: {
|
|
29167
|
+
reactionId: data.removedId,
|
|
29168
|
+
reactionName,
|
|
29169
|
+
userId: client.userId,
|
|
29170
|
+
},
|
|
29171
|
+
});
|
|
29172
|
+
return true;
|
|
29173
|
+
}
|
|
29174
|
+
if (referenceType === 'story') {
|
|
29175
|
+
fireEvent('local.story.reactionAdded', {
|
|
29176
|
+
story: updatedModel,
|
|
29177
|
+
reactor: {
|
|
29178
|
+
userId: client.userId,
|
|
29179
|
+
reactionName,
|
|
29180
|
+
reactionId: data.removedId,
|
|
29181
|
+
},
|
|
29182
|
+
});
|
|
29183
|
+
return true;
|
|
29184
|
+
}
|
|
29185
|
+
}
|
|
29186
|
+
return true;
|
|
29187
|
+
};
|
|
29188
|
+
|
|
29189
|
+
const addReactionToMessage = (reactionName, message) => {
|
|
29190
|
+
const isMessageV3 = message.publicId !== message.messageId;
|
|
29191
|
+
return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29192
|
+
};
|
|
29193
|
+
|
|
29194
|
+
const getCachedMarker = (message) => {
|
|
29195
|
+
var _a, _b;
|
|
29196
|
+
const key = {
|
|
29197
|
+
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
29198
|
+
feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
|
|
29199
|
+
contentId: message.messageId,
|
|
29200
|
+
};
|
|
29201
|
+
return (_b = pullFromCache([
|
|
29202
|
+
'messageMarker',
|
|
29203
|
+
'get',
|
|
29204
|
+
getResolver('messageMarker')(key),
|
|
29205
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29206
|
+
};
|
|
29207
|
+
const getMessageReadCount = (message, marker) => {
|
|
29208
|
+
var _a;
|
|
29209
|
+
// Look in the marker param first
|
|
29210
|
+
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
29211
|
+
// If the marker param is not set, look in the cache
|
|
29212
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
29213
|
+
}; // and if not found in cache use default value `0`
|
|
29214
|
+
|
|
29215
|
+
const removeReactionToMessage = (reactionName, message) => {
|
|
29216
|
+
const isMessageV3 = message.publicId !== message.messageId;
|
|
29217
|
+
return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29218
|
+
};
|
|
29219
|
+
|
|
29220
|
+
const messageLinkedObject = (message) => {
|
|
29221
|
+
const rest = __rest(message, ["creatorPrivateId"]);
|
|
29222
|
+
return Object.assign(Object.assign({}, rest), { get readCount() {
|
|
29223
|
+
return getMessageReadCount(message).readCount;
|
|
29224
|
+
},
|
|
29225
|
+
get deliveredCount() {
|
|
29226
|
+
return getMessageReadCount(message).deliveredCount;
|
|
28626
29227
|
},
|
|
28627
29228
|
get creator() {
|
|
28628
29229
|
var _a;
|
|
@@ -28868,618 +29469,175 @@ const cancelJoinRequest = async (joinRequest) => {
|
|
|
28868
29469
|
const joinRequestCache = (_a = pullFromCache([
|
|
28869
29470
|
'joinRequest',
|
|
28870
29471
|
'get',
|
|
28871
|
-
joinRequest.joinRequestId,
|
|
28872
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28873
|
-
if (joinRequestCache) {
|
|
28874
|
-
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
28875
|
-
status: "cancelled" /* JoinRequestStatusEnum.Cancelled */,
|
|
28876
|
-
});
|
|
28877
|
-
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
28878
|
-
}
|
|
28879
|
-
return data.success;
|
|
28880
|
-
};
|
|
28881
|
-
/* end_public_function */
|
|
28882
|
-
|
|
28883
|
-
/* begin_public_function
|
|
28884
|
-
id: joinRequest.reject
|
|
28885
|
-
*/
|
|
28886
|
-
/**
|
|
28887
|
-
* ```js
|
|
28888
|
-
* import { joinRequest } from '@amityco/ts-sdk'
|
|
28889
|
-
* const isRejected = await joinRequest.reject()
|
|
28890
|
-
* ```
|
|
28891
|
-
*
|
|
28892
|
-
* Rejects a {@link Amity.JoinRequest} object
|
|
28893
|
-
*
|
|
28894
|
-
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
28895
|
-
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
28896
|
-
*
|
|
28897
|
-
* @category Join Request API
|
|
28898
|
-
* @async
|
|
28899
|
-
*/
|
|
28900
|
-
const rejectJoinRequest = async (joinRequest) => {
|
|
28901
|
-
var _a;
|
|
28902
|
-
const client = getActiveClient();
|
|
28903
|
-
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
28904
|
-
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
|
|
28905
|
-
userId: joinRequest.requestorInternalId,
|
|
28906
|
-
});
|
|
28907
|
-
const joinRequestCache = (_a = pullFromCache([
|
|
28908
|
-
'joinRequest',
|
|
28909
|
-
'get',
|
|
28910
|
-
joinRequest.joinRequestId,
|
|
28911
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28912
|
-
if (joinRequestCache) {
|
|
28913
|
-
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
28914
|
-
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
28915
|
-
});
|
|
28916
|
-
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
28917
|
-
}
|
|
28918
|
-
return data.success;
|
|
28919
|
-
};
|
|
28920
|
-
/* end_public_function */
|
|
28921
|
-
|
|
28922
|
-
const joinRequestLinkedObject = (joinRequest) => {
|
|
28923
|
-
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
28924
|
-
var _a;
|
|
28925
|
-
const user = (_a = pullFromCache([
|
|
28926
|
-
'user',
|
|
28927
|
-
'get',
|
|
28928
|
-
joinRequest.requestorPublicId,
|
|
28929
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28930
|
-
if (!user)
|
|
28931
|
-
return undefined;
|
|
28932
|
-
return userLinkedObject(user);
|
|
28933
|
-
}, cancel: async () => {
|
|
28934
|
-
await cancelJoinRequest(joinRequest);
|
|
28935
|
-
}, approve: async () => {
|
|
28936
|
-
await approveJoinRequest(joinRequest);
|
|
28937
|
-
}, reject: async () => {
|
|
28938
|
-
await rejectJoinRequest(joinRequest);
|
|
28939
|
-
} });
|
|
28940
|
-
};
|
|
28941
|
-
|
|
28942
|
-
/* begin_public_function
|
|
28943
|
-
id: community.getMyJoinRequest
|
|
28944
|
-
*/
|
|
28945
|
-
/**
|
|
28946
|
-
* ```js
|
|
28947
|
-
* import { community } from '@amityco/ts-sdk'
|
|
28948
|
-
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
28949
|
-
* ```
|
|
28950
|
-
*
|
|
28951
|
-
* Joins a {@link Amity.Community} object
|
|
28952
|
-
*
|
|
28953
|
-
* @param communityId the {@link Amity.Community} to join
|
|
28954
|
-
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
28955
|
-
*
|
|
28956
|
-
* @category Community API
|
|
28957
|
-
* @async
|
|
28958
|
-
*/
|
|
28959
|
-
const getMyJoinRequest = async (communityId) => {
|
|
28960
|
-
const client = getActiveClient();
|
|
28961
|
-
client.log('community/myJoinRequest', communityId);
|
|
28962
|
-
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
28963
|
-
const data = prepareCommunityJoinRequestPayload(payload);
|
|
28964
|
-
const cachedAt = client.cache && Date.now();
|
|
28965
|
-
if (client.cache)
|
|
28966
|
-
ingestInCache(data, { cachedAt });
|
|
28967
|
-
return {
|
|
28968
|
-
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
28969
|
-
cachedAt,
|
|
28970
|
-
};
|
|
28971
|
-
};
|
|
28972
|
-
/* end_public_function */
|
|
28973
|
-
|
|
28974
|
-
/* begin_public_function
|
|
28975
|
-
id: community.join
|
|
28976
|
-
*/
|
|
28977
|
-
/**
|
|
28978
|
-
* ```js
|
|
28979
|
-
* import { community } from '@amityco/ts-sdk'
|
|
28980
|
-
* const isJoined = await community.join('foobar')
|
|
28981
|
-
* ```
|
|
28982
|
-
*
|
|
28983
|
-
* Joins a {@link Amity.Community} object
|
|
28984
|
-
*
|
|
28985
|
-
* @param communityId the {@link Amity.Community} to join
|
|
28986
|
-
* @returns A status join result
|
|
28987
|
-
*
|
|
28988
|
-
* @category Community API
|
|
28989
|
-
* @async
|
|
28990
|
-
*/
|
|
28991
|
-
const joinRequest = async (communityId) => {
|
|
28992
|
-
var _a;
|
|
28993
|
-
const client = getActiveClient();
|
|
28994
|
-
client.log('community/joinRequest', communityId);
|
|
28995
|
-
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
28996
|
-
const data = prepareCommunityJoinRequestPayload(payload);
|
|
28997
|
-
const cachedAt = client.cache && Date.now();
|
|
28998
|
-
if (client.cache)
|
|
28999
|
-
ingestInCache(data, { cachedAt });
|
|
29000
|
-
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
29001
|
-
? "success" /* JoinResultStatusEnum.Success */
|
|
29002
|
-
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
29003
|
-
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
29004
|
-
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29005
|
-
if (community) {
|
|
29006
|
-
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
29007
|
-
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
29008
|
-
}
|
|
29009
|
-
}
|
|
29010
|
-
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
29011
|
-
return status === "success" /* JoinResultStatusEnum.Success */
|
|
29012
|
-
? { status }
|
|
29013
|
-
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
29014
|
-
};
|
|
29015
|
-
/* end_public_function */
|
|
29016
|
-
|
|
29017
|
-
/**
|
|
29018
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
29019
|
-
* TODO: check if querybyIds is supported
|
|
29020
|
-
*/
|
|
29021
|
-
class JoinRequestsPaginationController extends PaginationController {
|
|
29022
|
-
async getRequest(queryParams, token) {
|
|
29023
|
-
const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
29024
|
-
const options = token ? { token } : { limit };
|
|
29025
|
-
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
29026
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
29027
|
-
});
|
|
29028
|
-
return queryResponse;
|
|
29029
|
-
}
|
|
29030
|
-
}
|
|
29031
|
-
|
|
29032
|
-
var EnumJoinRequestAction$1;
|
|
29033
|
-
(function (EnumJoinRequestAction) {
|
|
29034
|
-
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
29035
|
-
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
29036
|
-
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
29037
|
-
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
29038
|
-
|
|
29039
|
-
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
29040
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
29041
|
-
super(query, cacheKey);
|
|
29042
|
-
this.notifyChange = notifyChange;
|
|
29043
|
-
this.preparePayload = preparePayload;
|
|
29044
|
-
}
|
|
29045
|
-
async saveToMainDB(response) {
|
|
29046
|
-
const processedPayload = await this.preparePayload(response);
|
|
29047
|
-
const client = getActiveClient();
|
|
29048
|
-
const cachedAt = client.cache && Date.now();
|
|
29049
|
-
if (client.cache) {
|
|
29050
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
29051
|
-
}
|
|
29052
|
-
}
|
|
29053
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
29054
|
-
var _a, _b;
|
|
29055
|
-
if (refresh) {
|
|
29056
|
-
pushToCache(this.cacheKey, {
|
|
29057
|
-
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
29058
|
-
});
|
|
29059
|
-
}
|
|
29060
|
-
else {
|
|
29061
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29062
|
-
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
29063
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
29064
|
-
...new Set([
|
|
29065
|
-
...joinRequests,
|
|
29066
|
-
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
29067
|
-
]),
|
|
29068
|
-
] }));
|
|
29069
|
-
}
|
|
29070
|
-
}
|
|
29071
|
-
reactor(action) {
|
|
29072
|
-
return (joinRequest) => {
|
|
29073
|
-
var _a;
|
|
29074
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29075
|
-
if (!collection)
|
|
29076
|
-
return;
|
|
29077
|
-
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
29078
|
-
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
29079
|
-
if (!isExist)
|
|
29080
|
-
return;
|
|
29081
|
-
}
|
|
29082
|
-
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
29083
|
-
collection.data = [
|
|
29084
|
-
...new Set([
|
|
29085
|
-
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
29086
|
-
...collection.data,
|
|
29087
|
-
]),
|
|
29088
|
-
];
|
|
29089
|
-
}
|
|
29090
|
-
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
29091
|
-
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
29092
|
-
}
|
|
29093
|
-
pushToCache(this.cacheKey, collection);
|
|
29094
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
29095
|
-
};
|
|
29096
|
-
}
|
|
29097
|
-
subscribeRTE(createSubscriber) {
|
|
29098
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
29099
|
-
}
|
|
29100
|
-
}
|
|
29101
|
-
|
|
29102
|
-
/**
|
|
29103
|
-
* ```js
|
|
29104
|
-
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
29105
|
-
* const dispose = onJoinRequestCreated(data => {
|
|
29106
|
-
* // ...
|
|
29107
|
-
* })
|
|
29108
|
-
* ```
|
|
29109
|
-
*
|
|
29110
|
-
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29111
|
-
*
|
|
29112
|
-
* @param callback The function to call when the event was fired
|
|
29113
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29114
|
-
*
|
|
29115
|
-
* @category JoinRequest Events
|
|
29116
|
-
*/
|
|
29117
|
-
const onJoinRequestCreated = (callback) => {
|
|
29118
|
-
const client = getActiveClient();
|
|
29119
|
-
const disposers = [
|
|
29120
|
-
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
29121
|
-
];
|
|
29122
|
-
return () => {
|
|
29123
|
-
disposers.forEach(fn => fn());
|
|
29124
|
-
};
|
|
29125
|
-
};
|
|
29126
|
-
|
|
29127
|
-
/**
|
|
29128
|
-
* ```js
|
|
29129
|
-
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
29130
|
-
* const dispose = onJoinRequestUpdated(data => {
|
|
29131
|
-
* // ...
|
|
29132
|
-
* })
|
|
29133
|
-
* ```
|
|
29134
|
-
*
|
|
29135
|
-
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29136
|
-
*
|
|
29137
|
-
* @param callback The function to call when the event was fired
|
|
29138
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29139
|
-
*
|
|
29140
|
-
* @category JoinRequest Events
|
|
29141
|
-
*/
|
|
29142
|
-
const onJoinRequestUpdated = (callback) => {
|
|
29143
|
-
const client = getActiveClient();
|
|
29144
|
-
const disposers = [
|
|
29145
|
-
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
29146
|
-
];
|
|
29147
|
-
return () => {
|
|
29148
|
-
disposers.forEach(fn => fn());
|
|
29149
|
-
};
|
|
29150
|
-
};
|
|
29151
|
-
|
|
29152
|
-
/**
|
|
29153
|
-
* ```js
|
|
29154
|
-
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
29155
|
-
* const dispose = onJoinRequestDeleted(data => {
|
|
29156
|
-
* // ...
|
|
29157
|
-
* })
|
|
29158
|
-
* ```
|
|
29159
|
-
*
|
|
29160
|
-
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29161
|
-
*
|
|
29162
|
-
* @param callback The function to call when the event was fired
|
|
29163
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29164
|
-
*
|
|
29165
|
-
* @category JoinRequest Events
|
|
29166
|
-
*/
|
|
29167
|
-
const onJoinRequestDeleted = (callback) => {
|
|
29168
|
-
const client = getActiveClient();
|
|
29169
|
-
const disposers = [
|
|
29170
|
-
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
29171
|
-
];
|
|
29172
|
-
return () => {
|
|
29173
|
-
disposers.forEach(fn => fn());
|
|
29174
|
-
};
|
|
29175
|
-
};
|
|
29176
|
-
|
|
29177
|
-
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
29178
|
-
constructor(query, callback) {
|
|
29179
|
-
const queryStreamId = hash(query);
|
|
29180
|
-
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
29181
|
-
const paginationController = new JoinRequestsPaginationController(query);
|
|
29182
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
29183
|
-
this.query = query;
|
|
29184
|
-
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
29185
|
-
this.callback = callback.bind(this);
|
|
29186
|
-
this.loadPage({ initial: true });
|
|
29187
|
-
}
|
|
29188
|
-
setup() {
|
|
29189
|
-
var _a;
|
|
29190
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29191
|
-
if (!collection) {
|
|
29192
|
-
pushToCache(this.cacheKey, {
|
|
29193
|
-
data: [],
|
|
29194
|
-
params: this.query,
|
|
29195
|
-
});
|
|
29196
|
-
}
|
|
29197
|
-
}
|
|
29198
|
-
async persistModel(queryPayload) {
|
|
29199
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
29200
|
-
}
|
|
29201
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
29202
|
-
const joinRequestResponse = response;
|
|
29203
|
-
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
29204
|
-
}
|
|
29205
|
-
startSubscription() {
|
|
29206
|
-
return this.queryStreamController.subscribeRTE([
|
|
29207
|
-
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
29208
|
-
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
29209
|
-
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
29210
|
-
]);
|
|
29211
|
-
}
|
|
29212
|
-
notifyChange({ origin, loading, error }) {
|
|
29213
|
-
var _a;
|
|
29214
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29215
|
-
if (!collection)
|
|
29216
|
-
return;
|
|
29217
|
-
const data = this.applyFilter(collection.data
|
|
29218
|
-
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
29219
|
-
.filter(isNonNullable)
|
|
29220
|
-
.map(({ data }) => data)
|
|
29221
|
-
.map(joinRequestLinkedObject));
|
|
29222
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
29223
|
-
return;
|
|
29224
|
-
this.callback({
|
|
29225
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
29226
|
-
data,
|
|
29227
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
29228
|
-
loading,
|
|
29229
|
-
error,
|
|
29230
|
-
});
|
|
29231
|
-
}
|
|
29232
|
-
applyFilter(data) {
|
|
29233
|
-
let joinRequest = data;
|
|
29234
|
-
if (this.query.status) {
|
|
29235
|
-
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
29236
|
-
}
|
|
29237
|
-
const sortFn = (() => {
|
|
29238
|
-
switch (this.query.sortBy) {
|
|
29239
|
-
case 'firstCreated':
|
|
29240
|
-
return sortByFirstCreated;
|
|
29241
|
-
case 'lastCreated':
|
|
29242
|
-
return sortByLastCreated;
|
|
29243
|
-
default:
|
|
29244
|
-
return sortByLastCreated;
|
|
29245
|
-
}
|
|
29246
|
-
})();
|
|
29247
|
-
joinRequest = joinRequest.sort(sortFn);
|
|
29248
|
-
return joinRequest;
|
|
29249
|
-
}
|
|
29250
|
-
}
|
|
29251
|
-
|
|
29252
|
-
/**
|
|
29253
|
-
* Get Join Requests
|
|
29254
|
-
*
|
|
29255
|
-
* @param params the query parameters
|
|
29256
|
-
* @param callback the callback to be called when the join request are updated
|
|
29257
|
-
* @returns joinRequests
|
|
29258
|
-
*
|
|
29259
|
-
* @category joinRequest Live Collection
|
|
29260
|
-
*
|
|
29261
|
-
*/
|
|
29262
|
-
const getJoinRequests = (params, callback, config) => {
|
|
29263
|
-
const { log, cache } = getActiveClient();
|
|
29264
|
-
if (!cache) {
|
|
29265
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
29266
|
-
}
|
|
29267
|
-
const timestamp = Date.now();
|
|
29268
|
-
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
29269
|
-
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
29270
|
-
const disposers = joinRequestLiveCollection.startSubscription();
|
|
29271
|
-
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
29272
|
-
disposers.push(() => {
|
|
29273
|
-
dropFromCache(cacheKey);
|
|
29274
|
-
});
|
|
29275
|
-
return () => {
|
|
29276
|
-
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
29277
|
-
disposers.forEach(fn => fn());
|
|
29278
|
-
};
|
|
29279
|
-
};
|
|
29280
|
-
|
|
29281
|
-
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
29282
|
-
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
29283
|
-
};
|
|
29284
|
-
|
|
29285
|
-
const prepareInvitationPayload = (rawPayload) => {
|
|
29286
|
-
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
29287
|
-
};
|
|
29288
|
-
|
|
29289
|
-
/* begin_public_function
|
|
29290
|
-
id: invitation.createInvitations
|
|
29291
|
-
*/
|
|
29292
|
-
/**
|
|
29293
|
-
* ```js
|
|
29294
|
-
* import { createInvitations } from '@amityco/ts-sdk'
|
|
29295
|
-
* const created = await createInvitations({
|
|
29296
|
-
* type: string,
|
|
29297
|
-
* targetType: string,
|
|
29298
|
-
* targetId: string,
|
|
29299
|
-
* userIds: string[]
|
|
29300
|
-
* }))
|
|
29301
|
-
* ```
|
|
29302
|
-
*
|
|
29303
|
-
* Creates an {@link Amity.Invitation}
|
|
29304
|
-
*
|
|
29305
|
-
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
29306
|
-
* @returns The newly created {@link Amity.Invitation}
|
|
29307
|
-
*
|
|
29308
|
-
* @category Invitation API
|
|
29309
|
-
* @async
|
|
29310
|
-
*/
|
|
29311
|
-
const createInvitations = async (bundle) => {
|
|
29312
|
-
const client = getActiveClient();
|
|
29313
|
-
client.log('invitation/createInvitations', bundle);
|
|
29314
|
-
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
29315
|
-
const data = prepareInvitationPayload(payload);
|
|
29316
|
-
const cachedAt = client.cache && Date.now();
|
|
29317
|
-
if (client.cache)
|
|
29318
|
-
ingestInCache(data, { cachedAt });
|
|
29319
|
-
fireEvent('local.invitation.created', data.invitations);
|
|
29320
|
-
return {
|
|
29321
|
-
data: data.invitations,
|
|
29322
|
-
cachedAt,
|
|
29323
|
-
};
|
|
29324
|
-
};
|
|
29325
|
-
/* end_public_function */
|
|
29326
|
-
|
|
29327
|
-
/* begin_public_function
|
|
29328
|
-
id: invitation.accept
|
|
29329
|
-
*/
|
|
29330
|
-
/**
|
|
29331
|
-
* ```js
|
|
29332
|
-
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
29333
|
-
* const isAccepted = await acceptInvitation(invitationId)
|
|
29334
|
-
* ```
|
|
29335
|
-
*
|
|
29336
|
-
* Accepts a {@link Amity.Invitation} object
|
|
29337
|
-
*
|
|
29338
|
-
* @param invitationId the {@link Amity.Invitation} to accept
|
|
29339
|
-
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
29340
|
-
*
|
|
29341
|
-
* @category Invitation API
|
|
29342
|
-
* @async
|
|
29343
|
-
*/
|
|
29344
|
-
const acceptInvitation = async (invitationId) => {
|
|
29345
|
-
var _a;
|
|
29346
|
-
const client = getActiveClient();
|
|
29347
|
-
client.log('invitation/acceptInvitation', invitationId);
|
|
29348
|
-
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
29349
|
-
const invitation = (_a = pullFromCache([
|
|
29350
|
-
'invitation',
|
|
29351
|
-
'get',
|
|
29352
|
-
invitationId,
|
|
29472
|
+
joinRequest.joinRequestId,
|
|
29353
29473
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29354
|
-
if (
|
|
29355
|
-
upsertInCache(['
|
|
29356
|
-
|
|
29474
|
+
if (joinRequestCache) {
|
|
29475
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
29476
|
+
status: "cancelled" /* JoinRequestStatusEnum.Cancelled */,
|
|
29477
|
+
});
|
|
29478
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
29357
29479
|
}
|
|
29358
29480
|
return data.success;
|
|
29359
29481
|
};
|
|
29360
29482
|
/* end_public_function */
|
|
29361
29483
|
|
|
29362
29484
|
/* begin_public_function
|
|
29363
|
-
id:
|
|
29485
|
+
id: joinRequest.reject
|
|
29364
29486
|
*/
|
|
29365
29487
|
/**
|
|
29366
29488
|
* ```js
|
|
29367
|
-
* import {
|
|
29368
|
-
* const isRejected = await
|
|
29489
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
29490
|
+
* const isRejected = await joinRequest.reject()
|
|
29369
29491
|
* ```
|
|
29370
29492
|
*
|
|
29371
|
-
* Rejects a {@link Amity.
|
|
29493
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
29372
29494
|
*
|
|
29373
|
-
* @param
|
|
29374
|
-
* @returns A success boolean if the {@link Amity.
|
|
29495
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
29496
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
29375
29497
|
*
|
|
29376
|
-
* @category
|
|
29498
|
+
* @category Join Request API
|
|
29377
29499
|
* @async
|
|
29378
29500
|
*/
|
|
29379
|
-
const
|
|
29501
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
29380
29502
|
var _a;
|
|
29381
29503
|
const client = getActiveClient();
|
|
29382
|
-
client.log('
|
|
29383
|
-
const { data } = await client.http.post(`/api/
|
|
29384
|
-
|
|
29385
|
-
|
|
29504
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
29505
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
|
|
29506
|
+
userId: joinRequest.requestorInternalId,
|
|
29507
|
+
});
|
|
29508
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
29509
|
+
'joinRequest',
|
|
29386
29510
|
'get',
|
|
29387
|
-
|
|
29511
|
+
joinRequest.joinRequestId,
|
|
29388
29512
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29389
|
-
if (
|
|
29390
|
-
upsertInCache(['
|
|
29391
|
-
|
|
29513
|
+
if (joinRequestCache) {
|
|
29514
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
29515
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
29516
|
+
});
|
|
29517
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
29392
29518
|
}
|
|
29393
29519
|
return data.success;
|
|
29394
29520
|
};
|
|
29395
29521
|
/* end_public_function */
|
|
29396
29522
|
|
|
29397
|
-
const
|
|
29398
|
-
return Object.assign(Object.assign({},
|
|
29399
|
-
|
|
29400
|
-
|
|
29401
|
-
|
|
29402
|
-
|
|
29403
|
-
|
|
29404
|
-
|
|
29405
|
-
|
|
29406
|
-
return undefined;
|
|
29407
|
-
},
|
|
29408
|
-
get createdBy() {
|
|
29409
|
-
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
29410
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
29411
|
-
return userLinkedObject(cacheData.data);
|
|
29412
|
-
return undefined;
|
|
29413
|
-
},
|
|
29414
|
-
get target() {
|
|
29415
|
-
if (invitation.targetType === 'community') {
|
|
29416
|
-
const cacheData = pullFromCache([
|
|
29417
|
-
'community',
|
|
29418
|
-
'get',
|
|
29419
|
-
invitation.targetId,
|
|
29420
|
-
]);
|
|
29421
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
29422
|
-
return cacheData.data;
|
|
29523
|
+
const joinRequestLinkedObject = (joinRequest) => {
|
|
29524
|
+
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
29525
|
+
var _a;
|
|
29526
|
+
const user = (_a = pullFromCache([
|
|
29527
|
+
'user',
|
|
29528
|
+
'get',
|
|
29529
|
+
joinRequest.requestorPublicId,
|
|
29530
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29531
|
+
if (!user)
|
|
29423
29532
|
return undefined;
|
|
29424
|
-
|
|
29425
|
-
|
|
29426
|
-
|
|
29427
|
-
|
|
29533
|
+
return userLinkedObject(user);
|
|
29534
|
+
}, cancel: async () => {
|
|
29535
|
+
await cancelJoinRequest(joinRequest);
|
|
29536
|
+
}, approve: async () => {
|
|
29537
|
+
await approveJoinRequest(joinRequest);
|
|
29428
29538
|
}, reject: async () => {
|
|
29429
|
-
await
|
|
29539
|
+
await rejectJoinRequest(joinRequest);
|
|
29430
29540
|
} });
|
|
29431
29541
|
};
|
|
29432
29542
|
|
|
29433
29543
|
/* begin_public_function
|
|
29434
|
-
id:
|
|
29544
|
+
id: community.getMyJoinRequest
|
|
29435
29545
|
*/
|
|
29436
29546
|
/**
|
|
29437
29547
|
* ```js
|
|
29438
|
-
* import {
|
|
29439
|
-
* const
|
|
29548
|
+
* import { community } from '@amityco/ts-sdk'
|
|
29549
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
29440
29550
|
* ```
|
|
29441
29551
|
*
|
|
29442
|
-
*
|
|
29552
|
+
* Joins a {@link Amity.Community} object
|
|
29443
29553
|
*
|
|
29444
|
-
* @param
|
|
29445
|
-
* @
|
|
29446
|
-
* @returns A {@link Amity.Invitation} object
|
|
29554
|
+
* @param communityId the {@link Amity.Community} to join
|
|
29555
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
29447
29556
|
*
|
|
29448
|
-
* @category
|
|
29557
|
+
* @category Community API
|
|
29449
29558
|
* @async
|
|
29450
29559
|
*/
|
|
29451
|
-
const
|
|
29560
|
+
const getMyJoinRequest = async (communityId) => {
|
|
29452
29561
|
const client = getActiveClient();
|
|
29453
|
-
client.log('
|
|
29454
|
-
const { data: payload } = await client.http.get(`/api/
|
|
29455
|
-
const data =
|
|
29562
|
+
client.log('community/myJoinRequest', communityId);
|
|
29563
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
29564
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
29456
29565
|
const cachedAt = client.cache && Date.now();
|
|
29457
29566
|
if (client.cache)
|
|
29458
29567
|
ingestInCache(data, { cachedAt });
|
|
29459
29568
|
return {
|
|
29460
|
-
data: data.
|
|
29569
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
29461
29570
|
cachedAt,
|
|
29462
29571
|
};
|
|
29463
29572
|
};
|
|
29464
29573
|
/* end_public_function */
|
|
29465
29574
|
|
|
29466
|
-
|
|
29467
|
-
|
|
29468
|
-
|
|
29469
|
-
|
|
29470
|
-
|
|
29471
|
-
|
|
29575
|
+
/* begin_public_function
|
|
29576
|
+
id: community.join
|
|
29577
|
+
*/
|
|
29578
|
+
/**
|
|
29579
|
+
* ```js
|
|
29580
|
+
* import { community } from '@amityco/ts-sdk'
|
|
29581
|
+
* const isJoined = await community.join('foobar')
|
|
29582
|
+
* ```
|
|
29583
|
+
*
|
|
29584
|
+
* Joins a {@link Amity.Community} object
|
|
29585
|
+
*
|
|
29586
|
+
* @param communityId the {@link Amity.Community} to join
|
|
29587
|
+
* @returns A status join result
|
|
29588
|
+
*
|
|
29589
|
+
* @category Community API
|
|
29590
|
+
* @async
|
|
29591
|
+
*/
|
|
29592
|
+
const joinRequest = async (communityId) => {
|
|
29593
|
+
var _a;
|
|
29594
|
+
const client = getActiveClient();
|
|
29595
|
+
client.log('community/joinRequest', communityId);
|
|
29596
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
29597
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
29598
|
+
const cachedAt = client.cache && Date.now();
|
|
29599
|
+
if (client.cache)
|
|
29600
|
+
ingestInCache(data, { cachedAt });
|
|
29601
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
29602
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
29603
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
29604
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
29605
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29606
|
+
if (community) {
|
|
29607
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
29608
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
29609
|
+
}
|
|
29610
|
+
}
|
|
29611
|
+
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
29612
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
29613
|
+
? { status }
|
|
29614
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
29615
|
+
};
|
|
29616
|
+
/* end_public_function */
|
|
29472
29617
|
|
|
29473
|
-
|
|
29618
|
+
/**
|
|
29619
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
29620
|
+
* TODO: check if querybyIds is supported
|
|
29621
|
+
*/
|
|
29622
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
29474
29623
|
async getRequest(queryParams, token) {
|
|
29475
|
-
const { limit =
|
|
29624
|
+
const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
29476
29625
|
const options = token ? { token } : { limit };
|
|
29477
|
-
const { data } = await this.http.get(
|
|
29478
|
-
|
|
29626
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
29627
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
29628
|
+
});
|
|
29629
|
+
return queryResponse;
|
|
29479
29630
|
}
|
|
29480
29631
|
}
|
|
29481
29632
|
|
|
29482
|
-
|
|
29633
|
+
var EnumJoinRequestAction$1;
|
|
29634
|
+
(function (EnumJoinRequestAction) {
|
|
29635
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
29636
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
29637
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
29638
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
29639
|
+
|
|
29640
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
29483
29641
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
29484
29642
|
super(query, cacheKey);
|
|
29485
29643
|
this.notifyChange = notifyChange;
|
|
@@ -29497,38 +29655,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
29497
29655
|
var _a, _b;
|
|
29498
29656
|
if (refresh) {
|
|
29499
29657
|
pushToCache(this.cacheKey, {
|
|
29500
|
-
data: response.
|
|
29658
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
29501
29659
|
});
|
|
29502
29660
|
}
|
|
29503
29661
|
else {
|
|
29504
29662
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29505
|
-
const
|
|
29663
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
29506
29664
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
29507
|
-
...new Set([
|
|
29665
|
+
...new Set([
|
|
29666
|
+
...joinRequests,
|
|
29667
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
29668
|
+
]),
|
|
29508
29669
|
] }));
|
|
29509
29670
|
}
|
|
29510
29671
|
}
|
|
29511
29672
|
reactor(action) {
|
|
29512
|
-
return (
|
|
29673
|
+
return (joinRequest) => {
|
|
29513
29674
|
var _a;
|
|
29514
29675
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29515
29676
|
if (!collection)
|
|
29516
29677
|
return;
|
|
29517
|
-
if (action ===
|
|
29518
|
-
const isExist = collection.data.find(id => id ===
|
|
29678
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
29679
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
29519
29680
|
if (!isExist)
|
|
29520
29681
|
return;
|
|
29521
29682
|
}
|
|
29522
|
-
if (action ===
|
|
29683
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
29523
29684
|
collection.data = [
|
|
29524
29685
|
...new Set([
|
|
29525
|
-
...
|
|
29686
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
29526
29687
|
...collection.data,
|
|
29527
29688
|
]),
|
|
29528
29689
|
];
|
|
29529
29690
|
}
|
|
29530
|
-
if (action ===
|
|
29531
|
-
collection.data = collection.data.filter(id => id !==
|
|
29691
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
29692
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
29532
29693
|
}
|
|
29533
29694
|
pushToCache(this.cacheKey, collection);
|
|
29534
29695
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -29541,23 +29702,23 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
29541
29702
|
|
|
29542
29703
|
/**
|
|
29543
29704
|
* ```js
|
|
29544
|
-
* import {
|
|
29545
|
-
* const dispose =
|
|
29705
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
29706
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
29546
29707
|
* // ...
|
|
29547
29708
|
* })
|
|
29548
29709
|
* ```
|
|
29549
29710
|
*
|
|
29550
|
-
* Fired when an {@link Amity.
|
|
29711
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29551
29712
|
*
|
|
29552
29713
|
* @param callback The function to call when the event was fired
|
|
29553
29714
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29554
29715
|
*
|
|
29555
|
-
* @category
|
|
29716
|
+
* @category JoinRequest Events
|
|
29556
29717
|
*/
|
|
29557
|
-
const
|
|
29718
|
+
const onJoinRequestCreated = (callback) => {
|
|
29558
29719
|
const client = getActiveClient();
|
|
29559
29720
|
const disposers = [
|
|
29560
|
-
createEventSubscriber(client, '
|
|
29721
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
29561
29722
|
];
|
|
29562
29723
|
return () => {
|
|
29563
29724
|
disposers.forEach(fn => fn());
|
|
@@ -29566,23 +29727,23 @@ const onLocalInvitationCreated = (callback) => {
|
|
|
29566
29727
|
|
|
29567
29728
|
/**
|
|
29568
29729
|
* ```js
|
|
29569
|
-
* import {
|
|
29570
|
-
* const dispose =
|
|
29730
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
29731
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
29571
29732
|
* // ...
|
|
29572
29733
|
* })
|
|
29573
29734
|
* ```
|
|
29574
29735
|
*
|
|
29575
|
-
* Fired when an {@link Amity.
|
|
29736
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29576
29737
|
*
|
|
29577
29738
|
* @param callback The function to call when the event was fired
|
|
29578
29739
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29579
29740
|
*
|
|
29580
|
-
* @category
|
|
29741
|
+
* @category JoinRequest Events
|
|
29581
29742
|
*/
|
|
29582
|
-
const
|
|
29743
|
+
const onJoinRequestUpdated = (callback) => {
|
|
29583
29744
|
const client = getActiveClient();
|
|
29584
29745
|
const disposers = [
|
|
29585
|
-
createEventSubscriber(client, '
|
|
29746
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
29586
29747
|
];
|
|
29587
29748
|
return () => {
|
|
29588
29749
|
disposers.forEach(fn => fn());
|
|
@@ -29591,37 +29752,37 @@ const onLocalInvitationUpdated = (callback) => {
|
|
|
29591
29752
|
|
|
29592
29753
|
/**
|
|
29593
29754
|
* ```js
|
|
29594
|
-
* import {
|
|
29595
|
-
* const dispose =
|
|
29755
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
29756
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
29596
29757
|
* // ...
|
|
29597
29758
|
* })
|
|
29598
29759
|
* ```
|
|
29599
29760
|
*
|
|
29600
|
-
* Fired when an {@link Amity.
|
|
29761
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
29601
29762
|
*
|
|
29602
29763
|
* @param callback The function to call when the event was fired
|
|
29603
29764
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29604
29765
|
*
|
|
29605
|
-
* @category
|
|
29766
|
+
* @category JoinRequest Events
|
|
29606
29767
|
*/
|
|
29607
|
-
const
|
|
29768
|
+
const onJoinRequestDeleted = (callback) => {
|
|
29608
29769
|
const client = getActiveClient();
|
|
29609
29770
|
const disposers = [
|
|
29610
|
-
createEventSubscriber(client, '
|
|
29771
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
29611
29772
|
];
|
|
29612
29773
|
return () => {
|
|
29613
29774
|
disposers.forEach(fn => fn());
|
|
29614
29775
|
};
|
|
29615
29776
|
};
|
|
29616
29777
|
|
|
29617
|
-
class
|
|
29778
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
29618
29779
|
constructor(query, callback) {
|
|
29619
29780
|
const queryStreamId = hash(query);
|
|
29620
|
-
const cacheKey = ['
|
|
29621
|
-
const paginationController = new
|
|
29781
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
29782
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
29622
29783
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
29623
29784
|
this.query = query;
|
|
29624
|
-
this.queryStreamController = new
|
|
29785
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
29625
29786
|
this.callback = callback.bind(this);
|
|
29626
29787
|
this.loadPage({ initial: true });
|
|
29627
29788
|
}
|
|
@@ -29639,33 +29800,26 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
|
29639
29800
|
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
29640
29801
|
}
|
|
29641
29802
|
persistQueryStream({ response, direction, refresh, }) {
|
|
29642
|
-
|
|
29803
|
+
const joinRequestResponse = response;
|
|
29804
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
29643
29805
|
}
|
|
29644
29806
|
startSubscription() {
|
|
29645
29807
|
return this.queryStreamController.subscribeRTE([
|
|
29646
|
-
{
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
},
|
|
29650
|
-
{
|
|
29651
|
-
fn: onLocalInvitationUpdated,
|
|
29652
|
-
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
29653
|
-
},
|
|
29654
|
-
{
|
|
29655
|
-
fn: onLocalInvitationDeleted,
|
|
29656
|
-
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
29657
|
-
},
|
|
29808
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
29809
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
29810
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
29658
29811
|
]);
|
|
29659
29812
|
}
|
|
29660
29813
|
notifyChange({ origin, loading, error }) {
|
|
29661
|
-
var _a
|
|
29814
|
+
var _a;
|
|
29662
29815
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29663
29816
|
if (!collection)
|
|
29664
29817
|
return;
|
|
29665
|
-
const data = this.applyFilter(
|
|
29666
|
-
.map(id => pullFromCache(['
|
|
29818
|
+
const data = this.applyFilter(collection.data
|
|
29819
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
29667
29820
|
.filter(isNonNullable)
|
|
29668
|
-
.map(({ data }) =>
|
|
29821
|
+
.map(({ data }) => data)
|
|
29822
|
+
.map(joinRequestLinkedObject));
|
|
29669
29823
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
29670
29824
|
return;
|
|
29671
29825
|
this.callback({
|
|
@@ -29677,18 +29831,9 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
|
29677
29831
|
});
|
|
29678
29832
|
}
|
|
29679
29833
|
applyFilter(data) {
|
|
29680
|
-
let
|
|
29681
|
-
if (this.query.
|
|
29682
|
-
|
|
29683
|
-
}
|
|
29684
|
-
if (this.query.statuses) {
|
|
29685
|
-
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
29686
|
-
}
|
|
29687
|
-
if (this.query.targetType) {
|
|
29688
|
-
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
29689
|
-
}
|
|
29690
|
-
if (this.query.type) {
|
|
29691
|
-
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
29834
|
+
let joinRequest = data;
|
|
29835
|
+
if (this.query.status) {
|
|
29836
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
29692
29837
|
}
|
|
29693
29838
|
const sortFn = (() => {
|
|
29694
29839
|
switch (this.query.sortBy) {
|
|
@@ -29700,36 +29845,36 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
|
29700
29845
|
return sortByLastCreated;
|
|
29701
29846
|
}
|
|
29702
29847
|
})();
|
|
29703
|
-
|
|
29704
|
-
return
|
|
29848
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
29849
|
+
return joinRequest;
|
|
29705
29850
|
}
|
|
29706
29851
|
}
|
|
29707
29852
|
|
|
29708
29853
|
/**
|
|
29709
|
-
* Get
|
|
29854
|
+
* Get Join Requests
|
|
29710
29855
|
*
|
|
29711
29856
|
* @param params the query parameters
|
|
29712
|
-
* @param callback the callback to be called when the
|
|
29713
|
-
* @returns
|
|
29857
|
+
* @param callback the callback to be called when the join request are updated
|
|
29858
|
+
* @returns joinRequests
|
|
29714
29859
|
*
|
|
29715
|
-
* @category
|
|
29860
|
+
* @category joinRequest Live Collection
|
|
29716
29861
|
*
|
|
29717
29862
|
*/
|
|
29718
|
-
const
|
|
29863
|
+
const getJoinRequests = (params, callback, config) => {
|
|
29719
29864
|
const { log, cache } = getActiveClient();
|
|
29720
29865
|
if (!cache) {
|
|
29721
29866
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
29722
29867
|
}
|
|
29723
29868
|
const timestamp = Date.now();
|
|
29724
|
-
log(`
|
|
29725
|
-
const
|
|
29726
|
-
const disposers =
|
|
29727
|
-
const cacheKey =
|
|
29869
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
29870
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
29871
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
29872
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
29728
29873
|
disposers.push(() => {
|
|
29729
29874
|
dropFromCache(cacheKey);
|
|
29730
29875
|
});
|
|
29731
29876
|
return () => {
|
|
29732
|
-
log(`
|
|
29877
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
29733
29878
|
disposers.forEach(fn => fn());
|
|
29734
29879
|
};
|
|
29735
29880
|
};
|
|
@@ -29755,7 +29900,10 @@ const communityLinkedObject = (community) => {
|
|
|
29755
29900
|
}, getMemberInvitations: (params, callback) => {
|
|
29756
29901
|
return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
|
|
29757
29902
|
}, getInvitation: async () => {
|
|
29758
|
-
const { data } = await getInvitation(
|
|
29903
|
+
const { data } = await getInvitation({
|
|
29904
|
+
targetType: 'community',
|
|
29905
|
+
targetId: community.communityId,
|
|
29906
|
+
});
|
|
29759
29907
|
return data;
|
|
29760
29908
|
}, join: async () => joinRequest(community.communityId), getJoinRequests: (params, callback) => {
|
|
29761
29909
|
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
@@ -29765,6 +29913,51 @@ const communityLinkedObject = (community) => {
|
|
|
29765
29913
|
} });
|
|
29766
29914
|
};
|
|
29767
29915
|
|
|
29916
|
+
const eventLinkedObject = (event) => {
|
|
29917
|
+
return Object.assign(Object.assign({}, event), { get creator() {
|
|
29918
|
+
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
29919
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29920
|
+
return;
|
|
29921
|
+
return userLinkedObject(cacheData.data);
|
|
29922
|
+
},
|
|
29923
|
+
get discussionCommunity() {
|
|
29924
|
+
if (!event.discussionCommunityId)
|
|
29925
|
+
return;
|
|
29926
|
+
const cacheData = pullFromCache([
|
|
29927
|
+
'discussionCommunity',
|
|
29928
|
+
'get',
|
|
29929
|
+
event.discussionCommunityId,
|
|
29930
|
+
]);
|
|
29931
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29932
|
+
return;
|
|
29933
|
+
return communityLinkedObject(cacheData.data);
|
|
29934
|
+
},
|
|
29935
|
+
get targetCommunity() {
|
|
29936
|
+
if (!event.originId)
|
|
29937
|
+
return;
|
|
29938
|
+
const cacheData = pullFromCache(['community', 'get', event.originId]);
|
|
29939
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29940
|
+
return;
|
|
29941
|
+
return communityLinkedObject(cacheData.data);
|
|
29942
|
+
},
|
|
29943
|
+
get coverImage() {
|
|
29944
|
+
if (!event.coverImageFileId)
|
|
29945
|
+
return;
|
|
29946
|
+
const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
|
|
29947
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29948
|
+
return;
|
|
29949
|
+
return cacheData.data;
|
|
29950
|
+
},
|
|
29951
|
+
get liveStream() {
|
|
29952
|
+
if (!event.livestreamId)
|
|
29953
|
+
return;
|
|
29954
|
+
const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
|
|
29955
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29956
|
+
return;
|
|
29957
|
+
return cacheData.data;
|
|
29958
|
+
} });
|
|
29959
|
+
};
|
|
29960
|
+
|
|
29768
29961
|
const LinkedObject = {
|
|
29769
29962
|
ad: adLinkedObject,
|
|
29770
29963
|
comment: commentLinkedObject,
|
|
@@ -29783,6 +29976,8 @@ const LinkedObject = {
|
|
|
29783
29976
|
invitation: invitationLinkedObject,
|
|
29784
29977
|
joinRequest: joinRequestLinkedObject,
|
|
29785
29978
|
channelMember: channelMemberLinkedObject,
|
|
29979
|
+
room: roomLinkedObject,
|
|
29980
|
+
event: eventLinkedObject,
|
|
29786
29981
|
};
|
|
29787
29982
|
|
|
29788
29983
|
/* begin_public_function
|
|
@@ -30773,9 +30968,9 @@ var AmityUserSearchMatchType;
|
|
|
30773
30968
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
30774
30969
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
30775
30970
|
|
|
30776
|
-
var index$
|
|
30971
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
30777
30972
|
__proto__: null,
|
|
30778
|
-
Relationship: index$
|
|
30973
|
+
Relationship: index$p,
|
|
30779
30974
|
getUserByIds: getUserByIds,
|
|
30780
30975
|
updateUser: updateUser,
|
|
30781
30976
|
flagUser: flagUser,
|
|
@@ -31178,7 +31373,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
31178
31373
|
};
|
|
31179
31374
|
/* end_public_function */
|
|
31180
31375
|
|
|
31181
|
-
var index$
|
|
31376
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
31182
31377
|
__proto__: null,
|
|
31183
31378
|
getFile: getFile,
|
|
31184
31379
|
uploadFile: uploadFile,
|
|
@@ -32990,7 +33185,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
32990
33185
|
};
|
|
32991
33186
|
/* end_public_function */
|
|
32992
33187
|
|
|
32993
|
-
var index$
|
|
33188
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
32994
33189
|
__proto__: null,
|
|
32995
33190
|
addReaction: addReaction,
|
|
32996
33191
|
removeReaction: removeReaction,
|
|
@@ -34762,7 +34957,7 @@ const getMessages = (params, callback, config) => {
|
|
|
34762
34957
|
};
|
|
34763
34958
|
/* end_public_function */
|
|
34764
34959
|
|
|
34765
|
-
var index$
|
|
34960
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
34766
34961
|
__proto__: null,
|
|
34767
34962
|
createMessage: createMessage,
|
|
34768
34963
|
updateMessage: updateMessage,
|
|
@@ -35288,7 +35483,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
35288
35483
|
};
|
|
35289
35484
|
/* end_public_function */
|
|
35290
35485
|
|
|
35291
|
-
var index$
|
|
35486
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
35292
35487
|
__proto__: null,
|
|
35293
35488
|
getSubChannelByIds: getSubChannels$1,
|
|
35294
35489
|
createSubChannel: createSubChannel,
|
|
@@ -36615,7 +36810,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
36615
36810
|
};
|
|
36616
36811
|
/* end_public_function */
|
|
36617
36812
|
|
|
36618
|
-
var index$
|
|
36813
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
36619
36814
|
__proto__: null,
|
|
36620
36815
|
addMembers: addMembers$1,
|
|
36621
36816
|
removeMembers: removeMembers$1,
|
|
@@ -36818,7 +37013,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
36818
37013
|
};
|
|
36819
37014
|
/* end_public_function */
|
|
36820
37015
|
|
|
36821
|
-
var index$
|
|
37016
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
36822
37017
|
__proto__: null,
|
|
36823
37018
|
addRole: addRole,
|
|
36824
37019
|
removeRole: removeRole,
|
|
@@ -36828,10 +37023,10 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
36828
37023
|
unmuteMembers: unmuteMembers
|
|
36829
37024
|
});
|
|
36830
37025
|
|
|
36831
|
-
var index$
|
|
37026
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
36832
37027
|
__proto__: null,
|
|
36833
|
-
Membership: index$
|
|
36834
|
-
Moderation: index$
|
|
37028
|
+
Membership: index$j,
|
|
37029
|
+
Moderation: index$i,
|
|
36835
37030
|
getChannelByIds: getChannelByIds$1,
|
|
36836
37031
|
createChannel: createChannel,
|
|
36837
37032
|
updateChannel: updateChannel,
|
|
@@ -38234,7 +38429,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
38234
38429
|
};
|
|
38235
38430
|
/* end_public_function */
|
|
38236
38431
|
|
|
38237
|
-
var index$
|
|
38432
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
38238
38433
|
__proto__: null,
|
|
38239
38434
|
addMembers: addMembers,
|
|
38240
38435
|
removeMembers: removeMembers,
|
|
@@ -39485,7 +39680,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
39485
39680
|
};
|
|
39486
39681
|
/* end_public_function */
|
|
39487
39682
|
|
|
39488
|
-
var index$
|
|
39683
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
39489
39684
|
__proto__: null,
|
|
39490
39685
|
addRoles: addRoles,
|
|
39491
39686
|
removeRoles: removeRoles,
|
|
@@ -39493,10 +39688,10 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
39493
39688
|
unbanMembers: unbanMembers
|
|
39494
39689
|
});
|
|
39495
39690
|
|
|
39496
|
-
var index$
|
|
39691
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
39497
39692
|
__proto__: null,
|
|
39498
|
-
Moderation: index$
|
|
39499
|
-
Membership: index$
|
|
39693
|
+
Moderation: index$f,
|
|
39694
|
+
Membership: index$g,
|
|
39500
39695
|
getCommunityByIds: getCommunities$1,
|
|
39501
39696
|
createCommunity: createCommunity,
|
|
39502
39697
|
updateCommunity: updateCommunity,
|
|
@@ -39730,7 +39925,7 @@ const getCategories = (params, callback, config) => {
|
|
|
39730
39925
|
};
|
|
39731
39926
|
/* end_public_function */
|
|
39732
39927
|
|
|
39733
|
-
var index$
|
|
39928
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
39734
39929
|
__proto__: null,
|
|
39735
39930
|
getCategory: getCategory,
|
|
39736
39931
|
getCategories: getCategories
|
|
@@ -40789,7 +40984,7 @@ const getComments = (params, callback, config) => {
|
|
|
40789
40984
|
};
|
|
40790
40985
|
/* end_public_function */
|
|
40791
40986
|
|
|
40792
|
-
var index$
|
|
40987
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
40793
40988
|
__proto__: null,
|
|
40794
40989
|
getCommentByIds: getCommentByIds,
|
|
40795
40990
|
createComment: createComment,
|
|
@@ -41460,7 +41655,7 @@ const getUserFeed = (params, callback, config) => {
|
|
|
41460
41655
|
};
|
|
41461
41656
|
/* end_public_function */
|
|
41462
41657
|
|
|
41463
|
-
var index$
|
|
41658
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
41464
41659
|
__proto__: null,
|
|
41465
41660
|
queryGlobalFeed: queryGlobalFeed,
|
|
41466
41661
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -43141,7 +43336,7 @@ const searchPostsByHashtag = (params, callback, config) => {
|
|
|
43141
43336
|
};
|
|
43142
43337
|
/* end_public_function */
|
|
43143
43338
|
|
|
43144
|
-
var index$
|
|
43339
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
43145
43340
|
__proto__: null,
|
|
43146
43341
|
getPostByIds: getPostByIds,
|
|
43147
43342
|
createPost: createPost,
|
|
@@ -43749,7 +43944,7 @@ const getStreams = (params, callback, config) => {
|
|
|
43749
43944
|
};
|
|
43750
43945
|
};
|
|
43751
43946
|
|
|
43752
|
-
var index$
|
|
43947
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
43753
43948
|
__proto__: null,
|
|
43754
43949
|
createStream: createStream,
|
|
43755
43950
|
updateStream: updateStream,
|
|
@@ -43795,7 +43990,7 @@ const createRoom = async (bundle) => {
|
|
|
43795
43990
|
ingestInCache(data, { cachedAt });
|
|
43796
43991
|
const { rooms } = data;
|
|
43797
43992
|
return {
|
|
43798
|
-
data: rooms[0],
|
|
43993
|
+
data: roomLinkedObject(rooms[0]),
|
|
43799
43994
|
cachedAt,
|
|
43800
43995
|
};
|
|
43801
43996
|
};
|
|
@@ -43829,7 +44024,7 @@ const updateRoom = async (roomId, bundle) => {
|
|
|
43829
44024
|
ingestInCache(data, { cachedAt });
|
|
43830
44025
|
const { rooms } = data;
|
|
43831
44026
|
return {
|
|
43832
|
-
data: rooms[0],
|
|
44027
|
+
data: roomLinkedObject(rooms[0]),
|
|
43833
44028
|
cachedAt,
|
|
43834
44029
|
};
|
|
43835
44030
|
};
|
|
@@ -43894,25 +44089,25 @@ const stopRoom = async (roomId) => {
|
|
|
43894
44089
|
/* end_public_function */
|
|
43895
44090
|
|
|
43896
44091
|
/* begin_public_function
|
|
43897
|
-
id: room.
|
|
44092
|
+
id: room.getBroadcasterData
|
|
43898
44093
|
*/
|
|
43899
44094
|
/**
|
|
43900
44095
|
* ```js
|
|
43901
|
-
* import {
|
|
43902
|
-
* const token = await
|
|
44096
|
+
* import { getBroadcasterData } from '@amityco/ts-sdk'
|
|
44097
|
+
* const token = await getBroadcasterData('roomId')
|
|
43903
44098
|
* ```
|
|
43904
44099
|
*
|
|
43905
|
-
* Gets
|
|
44100
|
+
* Gets broadcaster data for a room
|
|
43906
44101
|
*
|
|
43907
44102
|
* @param roomId The ID of the room to get token for
|
|
43908
|
-
* @returns The room
|
|
44103
|
+
* @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
|
|
43909
44104
|
*
|
|
43910
44105
|
* @category Room API
|
|
43911
44106
|
* @async
|
|
43912
44107
|
*/
|
|
43913
|
-
const
|
|
44108
|
+
const getBroadcasterData = async (roomId) => {
|
|
43914
44109
|
const client = getActiveClient();
|
|
43915
|
-
client.log('room/
|
|
44110
|
+
client.log('room/getBroadcasterData', { roomId });
|
|
43916
44111
|
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
|
|
43917
44112
|
return data;
|
|
43918
44113
|
};
|
|
@@ -43943,6 +44138,64 @@ const getRecordedUrl = async (roomId) => {
|
|
|
43943
44138
|
};
|
|
43944
44139
|
/* end_public_function */
|
|
43945
44140
|
|
|
44141
|
+
/* begin_public_function
|
|
44142
|
+
id: room.removeParticipant
|
|
44143
|
+
*/
|
|
44144
|
+
/**
|
|
44145
|
+
* ```js
|
|
44146
|
+
* import { removeParticipant } from '@amityco/ts-sdk'
|
|
44147
|
+
* const result = await removeParticipant('roomId', 'participantUserId')
|
|
44148
|
+
* ```
|
|
44149
|
+
*
|
|
44150
|
+
* Removes a participant from an {@link Amity.Room}
|
|
44151
|
+
*
|
|
44152
|
+
* @param roomId The ID of the room to remove participant from
|
|
44153
|
+
* @param participantUserId The ID of the user to remove as participant
|
|
44154
|
+
* @returns Promise that resolves when the participant is removed
|
|
44155
|
+
*
|
|
44156
|
+
* @category Room API
|
|
44157
|
+
* @async
|
|
44158
|
+
*/
|
|
44159
|
+
const removeParticipant = async (roomId, participantUserId) => {
|
|
44160
|
+
const client = getActiveClient();
|
|
44161
|
+
client.log('room/removeParticipant', { roomId, participantUserId });
|
|
44162
|
+
await client.http.delete(`/api/v1/rooms/${roomId}/participants`, {
|
|
44163
|
+
data: { participantUserId },
|
|
44164
|
+
});
|
|
44165
|
+
fireEvent('local.room.participantRemoved', {
|
|
44166
|
+
rooms: [{ _id: roomId }],
|
|
44167
|
+
users: [{ _id: participantUserId }],
|
|
44168
|
+
});
|
|
44169
|
+
};
|
|
44170
|
+
/* end_public_function */
|
|
44171
|
+
|
|
44172
|
+
/* begin_public_function
|
|
44173
|
+
id: room.leave
|
|
44174
|
+
*/
|
|
44175
|
+
/**
|
|
44176
|
+
* ```js
|
|
44177
|
+
* import { leaveRoom } from '@amityco/ts-sdk'
|
|
44178
|
+
* const result = await leaveRoom('roomId')
|
|
44179
|
+
* ```
|
|
44180
|
+
*
|
|
44181
|
+
* Leaves an {@link Amity.Room}
|
|
44182
|
+
*
|
|
44183
|
+
* @param roomId The ID of the room to leave
|
|
44184
|
+
* @returns Promise that resolves when the user has left the room
|
|
44185
|
+
*
|
|
44186
|
+
* @category Room API
|
|
44187
|
+
* @async
|
|
44188
|
+
*/
|
|
44189
|
+
const leaveRoom = async (roomId) => {
|
|
44190
|
+
const client = getActiveClient();
|
|
44191
|
+
client.log('room/leaveRoom', { roomId });
|
|
44192
|
+
await client.http.post(`/api/v1/rooms/${roomId}/leave`);
|
|
44193
|
+
fireEvent('local.room.left', {
|
|
44194
|
+
rooms: [{ _id: roomId }],
|
|
44195
|
+
});
|
|
44196
|
+
};
|
|
44197
|
+
/* end_public_function */
|
|
44198
|
+
|
|
43946
44199
|
/**
|
|
43947
44200
|
* ```js
|
|
43948
44201
|
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
@@ -44054,13 +44307,89 @@ const onRoomRecordedAvailable = (callback) => {
|
|
|
44054
44307
|
*
|
|
44055
44308
|
* @category Room Events
|
|
44056
44309
|
*/
|
|
44057
|
-
const
|
|
44310
|
+
const onRoomCoHostInvited = (callback) => {
|
|
44058
44311
|
const client = getActiveClient();
|
|
44059
44312
|
const filter = (payload) => {
|
|
44060
|
-
|
|
44061
|
-
|
|
44313
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44314
|
+
ingestInCache(data);
|
|
44315
|
+
callback(data.invitations);
|
|
44316
|
+
};
|
|
44317
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
|
|
44318
|
+
};
|
|
44319
|
+
|
|
44320
|
+
/**
|
|
44321
|
+
* ```js
|
|
44322
|
+
* import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
|
|
44323
|
+
* const dispose = onRoomCoHostInviteAccepted(room => {
|
|
44324
|
+
* // ...
|
|
44325
|
+
* })
|
|
44326
|
+
* ```
|
|
44327
|
+
*
|
|
44328
|
+
* Fired when a co-host invitation is accepted for a {@link Amity.Room}
|
|
44329
|
+
*
|
|
44330
|
+
* @param callback The function to call when the event was fired
|
|
44331
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44332
|
+
*
|
|
44333
|
+
* @category Room Events
|
|
44334
|
+
*/
|
|
44335
|
+
const onRoomCoHostInviteAccepted = (callback) => {
|
|
44336
|
+
const client = getActiveClient();
|
|
44337
|
+
const filter = (payload) => {
|
|
44338
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44339
|
+
ingestInCache(data);
|
|
44340
|
+
callback(data.invitations);
|
|
44341
|
+
};
|
|
44342
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCoHostInviteAccept', filter);
|
|
44343
|
+
};
|
|
44344
|
+
|
|
44345
|
+
/**
|
|
44346
|
+
* ```js
|
|
44347
|
+
* import { onRoomCoHostInviteRejected } from '@amityco/ts-sdk'
|
|
44348
|
+
* const dispose = onRoomCoHostInviteRejected(room => {
|
|
44349
|
+
* // ...
|
|
44350
|
+
* })
|
|
44351
|
+
* ```
|
|
44352
|
+
*
|
|
44353
|
+
* Fired when a co-host invitation is rejected for a {@link Amity.Room}
|
|
44354
|
+
*
|
|
44355
|
+
* @param callback The function to call when the event was fired
|
|
44356
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44357
|
+
*
|
|
44358
|
+
* @category Room Events
|
|
44359
|
+
*/
|
|
44360
|
+
const onRoomCoHostInviteRejected = (callback) => {
|
|
44361
|
+
const client = getActiveClient();
|
|
44362
|
+
const filter = (payload) => {
|
|
44363
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44364
|
+
ingestInCache(data);
|
|
44365
|
+
callback(data.invitations);
|
|
44366
|
+
};
|
|
44367
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteRejected', 'room.didCoHostInviteReject', filter);
|
|
44368
|
+
};
|
|
44369
|
+
|
|
44370
|
+
/**
|
|
44371
|
+
* ```js
|
|
44372
|
+
* import { onRoomCoHostInviteCanceled } from '@amityco/ts-sdk'
|
|
44373
|
+
* const dispose = onRoomCoHostInviteCanceled(room => {
|
|
44374
|
+
* // ...
|
|
44375
|
+
* })
|
|
44376
|
+
* ```
|
|
44377
|
+
*
|
|
44378
|
+
* Fired when a co-host invitation is canceled for a {@link Amity.Room}
|
|
44379
|
+
*
|
|
44380
|
+
* @param callback The function to call when the event was fired
|
|
44381
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44382
|
+
*
|
|
44383
|
+
* @category Room Events
|
|
44384
|
+
*/
|
|
44385
|
+
const onRoomCoHostInviteCanceled = (callback) => {
|
|
44386
|
+
const client = getActiveClient();
|
|
44387
|
+
const filter = (payload) => {
|
|
44388
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44389
|
+
ingestInCache(data);
|
|
44390
|
+
callback(data.invitations);
|
|
44062
44391
|
};
|
|
44063
|
-
return createEventSubscriber(client, 'room/
|
|
44392
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCoHostInviteCancel', filter);
|
|
44064
44393
|
};
|
|
44065
44394
|
|
|
44066
44395
|
/**
|
|
@@ -44207,6 +44536,54 @@ const onRoomStopped = (callback) => {
|
|
|
44207
44536
|
return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
|
|
44208
44537
|
};
|
|
44209
44538
|
|
|
44539
|
+
/**
|
|
44540
|
+
* ```js
|
|
44541
|
+
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
44542
|
+
* const dispose = onRoomParticipantRemoved(room => {
|
|
44543
|
+
* // ...
|
|
44544
|
+
* })
|
|
44545
|
+
* ```
|
|
44546
|
+
*
|
|
44547
|
+
* Fired when a participant has been removed from a {@link Amity.Room} locally
|
|
44548
|
+
*
|
|
44549
|
+
* @param callback The function to call when the event was fired
|
|
44550
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44551
|
+
*
|
|
44552
|
+
* @category Room Events
|
|
44553
|
+
*/
|
|
44554
|
+
const onRoomParticipantRemoved = (callback) => {
|
|
44555
|
+
const client = getActiveClient();
|
|
44556
|
+
const filter = (payload) => {
|
|
44557
|
+
ingestInCache(payload);
|
|
44558
|
+
callback(payload.rooms[0]);
|
|
44559
|
+
};
|
|
44560
|
+
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
|
|
44561
|
+
};
|
|
44562
|
+
|
|
44563
|
+
/**
|
|
44564
|
+
* ```js
|
|
44565
|
+
* import { onRoomLeft } from '@amityco/ts-sdk'
|
|
44566
|
+
* const dispose = onRoomLeft(room => {
|
|
44567
|
+
* // ...
|
|
44568
|
+
* })
|
|
44569
|
+
* ```
|
|
44570
|
+
*
|
|
44571
|
+
* Fired when a user has left a {@link Amity.Room} locally
|
|
44572
|
+
*
|
|
44573
|
+
* @param callback The function to call when the event was fired
|
|
44574
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44575
|
+
*
|
|
44576
|
+
* @category Room Events
|
|
44577
|
+
*/
|
|
44578
|
+
const onRoomLeft = (callback) => {
|
|
44579
|
+
const client = getActiveClient();
|
|
44580
|
+
const filter = (payload) => {
|
|
44581
|
+
ingestInCache(payload);
|
|
44582
|
+
callback(payload.rooms[0]);
|
|
44583
|
+
};
|
|
44584
|
+
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
44585
|
+
};
|
|
44586
|
+
|
|
44210
44587
|
const getRoomById = async (roomId) => {
|
|
44211
44588
|
const client = getActiveClient();
|
|
44212
44589
|
client.log('room/getRoomById', roomId);
|
|
@@ -44254,7 +44631,13 @@ const getRoom = (roomId, callback) => {
|
|
|
44254
44631
|
onRoomStartBroadcasting,
|
|
44255
44632
|
onRoomWaitingReconnect,
|
|
44256
44633
|
onRoomRecordedAvailable,
|
|
44257
|
-
]
|
|
44634
|
+
], {
|
|
44635
|
+
callbackDataSelector: (data) => {
|
|
44636
|
+
if (!data)
|
|
44637
|
+
return data;
|
|
44638
|
+
return LinkedObject.room(data);
|
|
44639
|
+
},
|
|
44640
|
+
});
|
|
44258
44641
|
};
|
|
44259
44642
|
|
|
44260
44643
|
class RoomPaginationController extends PaginationController {
|
|
@@ -44467,25 +44850,32 @@ const getRooms = (params, callback, config) => {
|
|
|
44467
44850
|
};
|
|
44468
44851
|
/* end_public_function */
|
|
44469
44852
|
|
|
44470
|
-
var index$
|
|
44853
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
44471
44854
|
__proto__: null,
|
|
44472
44855
|
createRoom: createRoom,
|
|
44473
44856
|
updateRoom: updateRoom,
|
|
44474
44857
|
deleteRoom: deleteRoom,
|
|
44475
44858
|
stopRoom: stopRoom,
|
|
44476
|
-
|
|
44859
|
+
getBroadcasterData: getBroadcasterData,
|
|
44477
44860
|
getRecordedUrl: getRecordedUrl,
|
|
44861
|
+
removeParticipant: removeParticipant,
|
|
44862
|
+
leaveRoom: leaveRoom,
|
|
44478
44863
|
onRoomStartBroadcasting: onRoomStartBroadcasting,
|
|
44479
44864
|
onRoomWaitingReconnect: onRoomWaitingReconnect,
|
|
44480
44865
|
onRoomEndBroadcasting: onRoomEndBroadcasting,
|
|
44481
44866
|
onRoomRecordedAvailable: onRoomRecordedAvailable,
|
|
44482
|
-
|
|
44867
|
+
onRoomCoHostInvited: onRoomCoHostInvited,
|
|
44868
|
+
onRoomCoHostInviteAccepted: onRoomCoHostInviteAccepted,
|
|
44869
|
+
onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
|
|
44870
|
+
onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
|
|
44483
44871
|
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
44484
44872
|
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
44485
44873
|
onRoomCreated: onRoomCreated,
|
|
44486
44874
|
onRoomUpdated: onRoomUpdated,
|
|
44487
44875
|
onRoomDeleted: onRoomDeleted,
|
|
44488
44876
|
onRoomStopped: onRoomStopped,
|
|
44877
|
+
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
44878
|
+
onRoomLeft: onRoomLeft,
|
|
44489
44879
|
getRoom: getRoom,
|
|
44490
44880
|
getRooms: getRooms
|
|
44491
44881
|
});
|
|
@@ -44790,7 +45180,7 @@ const getPoll = (pollId, callback) => {
|
|
|
44790
45180
|
};
|
|
44791
45181
|
/* end_public_function */
|
|
44792
45182
|
|
|
44793
|
-
var index$
|
|
45183
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
44794
45184
|
__proto__: null,
|
|
44795
45185
|
createPoll: createPoll,
|
|
44796
45186
|
closePoll: closePoll,
|
|
@@ -45173,7 +45563,7 @@ const getPlayer = async (parameters) => {
|
|
|
45173
45563
|
return video;
|
|
45174
45564
|
};
|
|
45175
45565
|
|
|
45176
|
-
var index$
|
|
45566
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
45177
45567
|
__proto__: null,
|
|
45178
45568
|
getPlayer: getPlayer
|
|
45179
45569
|
});
|
|
@@ -46346,7 +46736,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
46346
46736
|
};
|
|
46347
46737
|
};
|
|
46348
46738
|
|
|
46349
|
-
var index$
|
|
46739
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
46350
46740
|
__proto__: null,
|
|
46351
46741
|
createImageStory: createImageStory,
|
|
46352
46742
|
createVideoStory: createVideoStory,
|
|
@@ -46383,7 +46773,7 @@ const getNetworkAds = async () => {
|
|
|
46383
46773
|
};
|
|
46384
46774
|
};
|
|
46385
46775
|
|
|
46386
|
-
var index$
|
|
46776
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
46387
46777
|
__proto__: null,
|
|
46388
46778
|
getNetworkAds: getNetworkAds
|
|
46389
46779
|
});
|
|
@@ -46774,7 +47164,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
46774
47164
|
};
|
|
46775
47165
|
/* end_public_function */
|
|
46776
47166
|
|
|
46777
|
-
var index$
|
|
47167
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
46778
47168
|
__proto__: null,
|
|
46779
47169
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
46780
47170
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -46783,6 +47173,62 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
46783
47173
|
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
46784
47174
|
});
|
|
46785
47175
|
|
|
47176
|
+
/* begin_public_function
|
|
47177
|
+
id: invitation.reject
|
|
47178
|
+
*/
|
|
47179
|
+
/**
|
|
47180
|
+
* ```js
|
|
47181
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
47182
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
47183
|
+
* ```
|
|
47184
|
+
*
|
|
47185
|
+
* Rejects a {@link Amity.Invitation} object
|
|
47186
|
+
*
|
|
47187
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
47188
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
47189
|
+
*
|
|
47190
|
+
* @category Invitation API
|
|
47191
|
+
* @async
|
|
47192
|
+
*/
|
|
47193
|
+
const cancelInvitation = async (invitationId) => {
|
|
47194
|
+
var _a;
|
|
47195
|
+
const client = getActiveClient();
|
|
47196
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
47197
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
47198
|
+
const invitation = (_a = pullFromCache([
|
|
47199
|
+
'invitation',
|
|
47200
|
+
'get',
|
|
47201
|
+
invitationId,
|
|
47202
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
47203
|
+
pushToTombstone('invitation', invitationId);
|
|
47204
|
+
if (invitation)
|
|
47205
|
+
fireEvent('local.invitation.canceled', [invitation]);
|
|
47206
|
+
return data.success;
|
|
47207
|
+
};
|
|
47208
|
+
/* end_public_function */
|
|
47209
|
+
|
|
47210
|
+
/* begin_public_function
|
|
47211
|
+
id: invitation.accept
|
|
47212
|
+
*/
|
|
47213
|
+
/**
|
|
47214
|
+
* ```js
|
|
47215
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
47216
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
47217
|
+
* ```
|
|
47218
|
+
*
|
|
47219
|
+
* Accepts a {@link Amity.Invitation} object
|
|
47220
|
+
*
|
|
47221
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
47222
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
47223
|
+
*
|
|
47224
|
+
* @category Invitation API
|
|
47225
|
+
* @async
|
|
47226
|
+
*/
|
|
47227
|
+
const acceptInvitation = async (invitationId) => {
|
|
47228
|
+
return acceptInvitation$1(invitationId);
|
|
47229
|
+
};
|
|
47230
|
+
/* end_public_function */
|
|
47231
|
+
|
|
46786
47232
|
class MyInvitationsPaginationController extends PaginationController {
|
|
46787
47233
|
async getRequest(queryParams, token) {
|
|
46788
47234
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -46893,8 +47339,8 @@ class MyInvitationsLiveCollectionController extends LiveCollectionController {
|
|
|
46893
47339
|
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
46894
47340
|
},
|
|
46895
47341
|
{
|
|
46896
|
-
fn:
|
|
46897
|
-
action: InvitationActionsEnum.
|
|
47342
|
+
fn: onLocalInvitationCanceled,
|
|
47343
|
+
action: InvitationActionsEnum.OnLocalInvitationCanceled,
|
|
46898
47344
|
},
|
|
46899
47345
|
]);
|
|
46900
47346
|
}
|
|
@@ -46975,12 +47421,75 @@ const getMyCommunityInvitations = (params, callback, config) => {
|
|
|
46975
47421
|
};
|
|
46976
47422
|
};
|
|
46977
47423
|
|
|
46978
|
-
|
|
47424
|
+
/**
|
|
47425
|
+
*
|
|
47426
|
+
* ```js
|
|
47427
|
+
* import { observeInvitations } from '@amityco/ts-sdk';
|
|
47428
|
+
*
|
|
47429
|
+
* // For room invitations
|
|
47430
|
+
* const unsubscribe = observeInvitations(
|
|
47431
|
+
* { targetId: 'room123', targetType: 'room' },
|
|
47432
|
+
* response => {
|
|
47433
|
+
* console.log('Room invitation event:', response.room, response.users, response.eventType)
|
|
47434
|
+
* }
|
|
47435
|
+
* );
|
|
47436
|
+
*
|
|
47437
|
+
* // For community invitations (when implemented)
|
|
47438
|
+
* const unsubscribe2 = observeInvitations(
|
|
47439
|
+
* { targetId: 'community456', targetType: 'community' },
|
|
47440
|
+
* response => {
|
|
47441
|
+
* console.log('Community invitation event:', response.community, response.users, response.eventType)
|
|
47442
|
+
* }
|
|
47443
|
+
* );
|
|
47444
|
+
* ```
|
|
47445
|
+
*
|
|
47446
|
+
* Observe invitations events including invited, accepted, rejected, and canceled
|
|
47447
|
+
*
|
|
47448
|
+
* @param params The target ID and type to observe invitations for
|
|
47449
|
+
* @param callback The function to call when new invitation events are available
|
|
47450
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
|
|
47451
|
+
*
|
|
47452
|
+
* @category Invitation Observable
|
|
47453
|
+
*/
|
|
47454
|
+
const observeInvitations = (params, callback) => {
|
|
47455
|
+
const { _id: userId } = getCurrentUser();
|
|
47456
|
+
if (!userId)
|
|
47457
|
+
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
47458
|
+
const { log } = getActiveClient();
|
|
47459
|
+
const { targetId, targetType } = params;
|
|
47460
|
+
const timestamp = Date.now();
|
|
47461
|
+
log(`observeInvitations(tmpid: ${timestamp}) > listen for ${targetType}: ${targetId}`);
|
|
47462
|
+
const disposers = [];
|
|
47463
|
+
const dispatcher = (data) => {
|
|
47464
|
+
callback(data.map(LinkedObject.invitation));
|
|
47465
|
+
};
|
|
47466
|
+
const realtimeRouter = (data) => {
|
|
47467
|
+
const invitations = data.filter(({ targetId, targetType }) => targetId === params.targetId && targetType === params.targetType);
|
|
47468
|
+
dispatcher(invitations);
|
|
47469
|
+
};
|
|
47470
|
+
// Only subscribe to room co-host events for now (since that's what we have implemented)
|
|
47471
|
+
if (targetType === 'room') {
|
|
47472
|
+
// Create custom event subscribers that receive the full payload
|
|
47473
|
+
disposers.push(onRoomCoHostInvited(realtimeRouter));
|
|
47474
|
+
disposers.push(onRoomCoHostInviteAccepted(realtimeRouter));
|
|
47475
|
+
disposers.push(onRoomCoHostInviteRejected(realtimeRouter));
|
|
47476
|
+
disposers.push(onRoomCoHostInviteCanceled(realtimeRouter));
|
|
47477
|
+
}
|
|
47478
|
+
return () => {
|
|
47479
|
+
log(`observeInvitations(tmpid: ${timestamp}) > dispose for ${targetType}: ${targetId}`);
|
|
47480
|
+
disposers.forEach(fn => fn());
|
|
47481
|
+
};
|
|
47482
|
+
};
|
|
47483
|
+
|
|
47484
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
46979
47485
|
__proto__: null,
|
|
47486
|
+
cancelInvitation: cancelInvitation,
|
|
47487
|
+
acceptInvitation: acceptInvitation,
|
|
46980
47488
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
46981
47489
|
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
46982
|
-
|
|
46983
|
-
getMyCommunityInvitations: getMyCommunityInvitations
|
|
47490
|
+
onLocalInvitationCanceled: onLocalInvitationCanceled,
|
|
47491
|
+
getMyCommunityInvitations: getMyCommunityInvitations,
|
|
47492
|
+
observeInvitations: observeInvitations
|
|
46984
47493
|
});
|
|
46985
47494
|
|
|
46986
47495
|
// TODO: confirm id
|
|
@@ -47008,7 +47517,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
47008
47517
|
* @category Live Reaction API
|
|
47009
47518
|
* @async
|
|
47010
47519
|
*/
|
|
47011
|
-
const createReaction = async ({ referenceId, referenceType, reactionName,
|
|
47520
|
+
const createReaction = async ({ referenceId, referenceType, reactionName, roomId, }) => {
|
|
47012
47521
|
const client = getActiveClient();
|
|
47013
47522
|
client.log('live_reaction/createReaction', {
|
|
47014
47523
|
referenceId,
|
|
@@ -47020,7 +47529,7 @@ const createReaction = async ({ referenceId, referenceType, reactionName, stream
|
|
|
47020
47529
|
reactionName,
|
|
47021
47530
|
referencePublicId: referenceId,
|
|
47022
47531
|
referenceType,
|
|
47023
|
-
|
|
47532
|
+
roomId,
|
|
47024
47533
|
occurredAt: new Date().toISOString(),
|
|
47025
47534
|
};
|
|
47026
47535
|
reactionSynceEngine.createLiveReaction(reaction);
|
|
@@ -47116,11 +47625,619 @@ const getReactions = (postId, callback) => {
|
|
|
47116
47625
|
};
|
|
47117
47626
|
};
|
|
47118
47627
|
|
|
47119
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
47628
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
47120
47629
|
__proto__: null,
|
|
47121
47630
|
createReaction: createReaction,
|
|
47122
47631
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
47123
47632
|
getReactions: getReactions
|
|
47124
47633
|
});
|
|
47125
47634
|
|
|
47126
|
-
|
|
47635
|
+
const prepareEventPayload = (rawPayload) => {
|
|
47636
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
47637
|
+
};
|
|
47638
|
+
|
|
47639
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
47640
|
+
const client = getActiveClient();
|
|
47641
|
+
const filter = (payload) => {
|
|
47642
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
47643
|
+
if (!client.cache) {
|
|
47644
|
+
callback(unpackedPayload.events[0]);
|
|
47645
|
+
}
|
|
47646
|
+
else {
|
|
47647
|
+
ingestInCache(unpackedPayload);
|
|
47648
|
+
const event = pullFromCache([
|
|
47649
|
+
'event',
|
|
47650
|
+
'get',
|
|
47651
|
+
unpackedPayload.events[0].eventId,
|
|
47652
|
+
]);
|
|
47653
|
+
callback(event.data);
|
|
47654
|
+
}
|
|
47655
|
+
};
|
|
47656
|
+
return createEventSubscriber(client, event, event, filter);
|
|
47657
|
+
};
|
|
47658
|
+
|
|
47659
|
+
/* begin_public_function
|
|
47660
|
+
id: event.create
|
|
47661
|
+
*/
|
|
47662
|
+
/**
|
|
47663
|
+
* ```js
|
|
47664
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47665
|
+
* const response = await EventRepository.createEvent(bundle)
|
|
47666
|
+
* ```
|
|
47667
|
+
*
|
|
47668
|
+
* Creates an {@link Amity.Event}
|
|
47669
|
+
*
|
|
47670
|
+
* @param bundle The data necessary to create a new {@link Amity.Event}
|
|
47671
|
+
* @returns The newly created {@link Amity.Event}
|
|
47672
|
+
*
|
|
47673
|
+
* @category Event API
|
|
47674
|
+
* @async
|
|
47675
|
+
*/
|
|
47676
|
+
const createEvent = async (bundle) => {
|
|
47677
|
+
const client = getActiveClient();
|
|
47678
|
+
client.log('event/createEvent', bundle);
|
|
47679
|
+
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
47680
|
+
fireEvent('local.event.created', payload);
|
|
47681
|
+
const preparedPayload = prepareEventPayload(payload);
|
|
47682
|
+
const cachedAt = client.cache && Date.now();
|
|
47683
|
+
if (client.cache)
|
|
47684
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
47685
|
+
return {
|
|
47686
|
+
data: eventLinkedObject(preparedPayload.events[0]),
|
|
47687
|
+
cachedAt,
|
|
47688
|
+
};
|
|
47689
|
+
};
|
|
47690
|
+
/* end_public_function */
|
|
47691
|
+
|
|
47692
|
+
/* begin_public_function
|
|
47693
|
+
id: event.update
|
|
47694
|
+
*/
|
|
47695
|
+
/**
|
|
47696
|
+
* ```js
|
|
47697
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47698
|
+
* const response = await EventRepository.updateEvent(eventId, bundle)
|
|
47699
|
+
* ```
|
|
47700
|
+
*
|
|
47701
|
+
* Updates an {@link Amity.Event}
|
|
47702
|
+
*
|
|
47703
|
+
* @param eventId The ID of the {@link Amity.Event} to edit
|
|
47704
|
+
* @param bundle The data necessary to update an existing {@link Amity.Event}
|
|
47705
|
+
* @returns the updated {@link Amity.Event}
|
|
47706
|
+
*
|
|
47707
|
+
* @category Event API
|
|
47708
|
+
* @async
|
|
47709
|
+
*/
|
|
47710
|
+
const updateEvent = async (eventId, bundle) => {
|
|
47711
|
+
const client = getActiveClient();
|
|
47712
|
+
client.log('event/updateEvent', eventId, bundle);
|
|
47713
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
47714
|
+
fireEvent('local.event.updated', payload);
|
|
47715
|
+
const preparedPayload = prepareEventPayload(payload);
|
|
47716
|
+
const cachedAt = client.cache && Date.now();
|
|
47717
|
+
if (client.cache)
|
|
47718
|
+
ingestInCache(preparedPayload, { cachedAt });
|
|
47719
|
+
return {
|
|
47720
|
+
data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
|
|
47721
|
+
cachedAt,
|
|
47722
|
+
};
|
|
47723
|
+
};
|
|
47724
|
+
/* end_public_function */
|
|
47725
|
+
|
|
47726
|
+
/* begin_public_function
|
|
47727
|
+
id: event.get
|
|
47728
|
+
*/
|
|
47729
|
+
/**
|
|
47730
|
+
* ```js
|
|
47731
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47732
|
+
* const event = await EventRepository.getEvent(eventId)
|
|
47733
|
+
* ```
|
|
47734
|
+
*
|
|
47735
|
+
* Fetches a {@link Amity.Event} object
|
|
47736
|
+
*
|
|
47737
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
47738
|
+
* @returns the associated {@link Amity.Event} object
|
|
47739
|
+
*
|
|
47740
|
+
* @category Event API
|
|
47741
|
+
* @async
|
|
47742
|
+
*/
|
|
47743
|
+
const getEvent$1 = async (eventId) => {
|
|
47744
|
+
const client = getActiveClient();
|
|
47745
|
+
client.log('event/getEvent', eventId);
|
|
47746
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
|
|
47747
|
+
const data = prepareEventPayload(payload);
|
|
47748
|
+
const cachedAt = client.cache && Date.now();
|
|
47749
|
+
if (client.cache)
|
|
47750
|
+
ingestInCache(data, { cachedAt });
|
|
47751
|
+
return {
|
|
47752
|
+
data: data.events.find(event => event.eventId === eventId),
|
|
47753
|
+
cachedAt,
|
|
47754
|
+
};
|
|
47755
|
+
};
|
|
47756
|
+
/* end_public_function */
|
|
47757
|
+
/**
|
|
47758
|
+
* ```js
|
|
47759
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47760
|
+
* const event = EventRepository.getEvent.locally(eventId)
|
|
47761
|
+
* ```
|
|
47762
|
+
*
|
|
47763
|
+
* Fetches a {@link Amity.Event} object in cache
|
|
47764
|
+
*
|
|
47765
|
+
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
47766
|
+
* @returns the associated {@link Amity.Event} object
|
|
47767
|
+
*
|
|
47768
|
+
* @category Event API
|
|
47769
|
+
*/
|
|
47770
|
+
getEvent$1.locally = (eventId) => {
|
|
47771
|
+
const client = getActiveClient();
|
|
47772
|
+
client.log('event/getEvent.locally', eventId);
|
|
47773
|
+
if (!client.cache)
|
|
47774
|
+
return;
|
|
47775
|
+
const cache = pullFromCache(['event', 'get', eventId]);
|
|
47776
|
+
if (!cache)
|
|
47777
|
+
return;
|
|
47778
|
+
return {
|
|
47779
|
+
data: cache.data,
|
|
47780
|
+
cachedAt: cache.cachedAt,
|
|
47781
|
+
};
|
|
47782
|
+
};
|
|
47783
|
+
|
|
47784
|
+
/* begin_public_function
|
|
47785
|
+
id: event.delete
|
|
47786
|
+
*/
|
|
47787
|
+
/**
|
|
47788
|
+
* ```js
|
|
47789
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47790
|
+
* const { success } = await EventRepository.deleteEvent(eventId)
|
|
47791
|
+
* ```
|
|
47792
|
+
*
|
|
47793
|
+
* Deletes a {@link Amity.Event}
|
|
47794
|
+
*
|
|
47795
|
+
* @param eventId The {@link Amity.Event} ID to delete
|
|
47796
|
+
*
|
|
47797
|
+
* @category Event API
|
|
47798
|
+
* @async
|
|
47799
|
+
*/
|
|
47800
|
+
const deleteEvent = async (eventId) => {
|
|
47801
|
+
const client = getActiveClient();
|
|
47802
|
+
client.log('event/deleteEvent', eventId);
|
|
47803
|
+
const event = await getEvent$1(eventId);
|
|
47804
|
+
await client.http.delete(`/api/v1/events/${eventId}`);
|
|
47805
|
+
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
47806
|
+
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
47807
|
+
fireEvent('local.event.deleted', {
|
|
47808
|
+
users: [],
|
|
47809
|
+
files: [],
|
|
47810
|
+
communities: [],
|
|
47811
|
+
videoStreamings: [],
|
|
47812
|
+
events: [deletedEvent],
|
|
47813
|
+
discussionCommunities: [],
|
|
47814
|
+
});
|
|
47815
|
+
};
|
|
47816
|
+
/* end_public_function */
|
|
47817
|
+
|
|
47818
|
+
/**
|
|
47819
|
+
* ```js
|
|
47820
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47821
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
47822
|
+
* // ...
|
|
47823
|
+
* })
|
|
47824
|
+
* ```
|
|
47825
|
+
*
|
|
47826
|
+
* Fired when a {@link Amity.Event} has been created
|
|
47827
|
+
*
|
|
47828
|
+
* @param callback The function to call when the event was fired
|
|
47829
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47830
|
+
*
|
|
47831
|
+
* @category Event Events
|
|
47832
|
+
*/
|
|
47833
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
47834
|
+
|
|
47835
|
+
/**
|
|
47836
|
+
* ```js
|
|
47837
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47838
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
47839
|
+
* // ...
|
|
47840
|
+
* })
|
|
47841
|
+
* ```
|
|
47842
|
+
*
|
|
47843
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
47844
|
+
*
|
|
47845
|
+
* @param callback The function to call when the event was fired
|
|
47846
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47847
|
+
*
|
|
47848
|
+
* @category Event Events
|
|
47849
|
+
*/
|
|
47850
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
47851
|
+
|
|
47852
|
+
/**
|
|
47853
|
+
* ```js
|
|
47854
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47855
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
47856
|
+
* // ...
|
|
47857
|
+
* })
|
|
47858
|
+
* ```
|
|
47859
|
+
*
|
|
47860
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
47861
|
+
*
|
|
47862
|
+
* @param callback The function to call when the event was fired
|
|
47863
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47864
|
+
*
|
|
47865
|
+
* @category Event Events
|
|
47866
|
+
*/
|
|
47867
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
47868
|
+
|
|
47869
|
+
/**
|
|
47870
|
+
* ```js
|
|
47871
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47872
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
47873
|
+
* // ...
|
|
47874
|
+
* })
|
|
47875
|
+
* ```
|
|
47876
|
+
*
|
|
47877
|
+
* Fired when a {@link Amity.Event} has been created
|
|
47878
|
+
*
|
|
47879
|
+
* @param callback The function to call when the event was fired
|
|
47880
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47881
|
+
*
|
|
47882
|
+
* @category Event Events
|
|
47883
|
+
*/
|
|
47884
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
47885
|
+
|
|
47886
|
+
/**
|
|
47887
|
+
* ```js
|
|
47888
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47889
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
47890
|
+
* // ...
|
|
47891
|
+
* })
|
|
47892
|
+
* ```
|
|
47893
|
+
*
|
|
47894
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
47895
|
+
*
|
|
47896
|
+
* @param callback The function to call when the event was fired
|
|
47897
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47898
|
+
*
|
|
47899
|
+
* @category Event Events
|
|
47900
|
+
*/
|
|
47901
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
47902
|
+
|
|
47903
|
+
/**
|
|
47904
|
+
* ```js
|
|
47905
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
47906
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
47907
|
+
* // ...
|
|
47908
|
+
* })
|
|
47909
|
+
* ```
|
|
47910
|
+
*
|
|
47911
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
47912
|
+
*
|
|
47913
|
+
* @param callback The function to call when the event was fired
|
|
47914
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
47915
|
+
*
|
|
47916
|
+
* @category Event Events
|
|
47917
|
+
*/
|
|
47918
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
47919
|
+
|
|
47920
|
+
/* begin_public_function
|
|
47921
|
+
id: event.get
|
|
47922
|
+
*/
|
|
47923
|
+
/**
|
|
47924
|
+
* ```js
|
|
47925
|
+
* import { EventRepository } from '@amityco/ts-sdk';
|
|
47926
|
+
*
|
|
47927
|
+
* let event;
|
|
47928
|
+
*
|
|
47929
|
+
* const unsubscribe = EventRepository.getEvent(eventId, response => {
|
|
47930
|
+
* event = response.data;
|
|
47931
|
+
* });
|
|
47932
|
+
* ```
|
|
47933
|
+
*
|
|
47934
|
+
* Observe all mutation on a given {@link Amity.Event}
|
|
47935
|
+
*
|
|
47936
|
+
* @param eventId the ID of the event to observe
|
|
47937
|
+
* @param callback the function to call when new snapshot of event are available
|
|
47938
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
|
|
47939
|
+
*
|
|
47940
|
+
* @category Event Live Object
|
|
47941
|
+
*/
|
|
47942
|
+
const getEvent = (eventId, callback) => {
|
|
47943
|
+
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
|
|
47944
|
+
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
47945
|
+
});
|
|
47946
|
+
};
|
|
47947
|
+
/* end_public_function */
|
|
47948
|
+
|
|
47949
|
+
var EventActionsEnum;
|
|
47950
|
+
(function (EventActionsEnum) {
|
|
47951
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
47952
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
47953
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
47954
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
47955
|
+
|
|
47956
|
+
class EventPaginationController extends PaginationController {
|
|
47957
|
+
async getRequest(queryParams, token) {
|
|
47958
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
47959
|
+
const options = token ? { token } : { limit };
|
|
47960
|
+
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
47961
|
+
return response;
|
|
47962
|
+
}
|
|
47963
|
+
}
|
|
47964
|
+
|
|
47965
|
+
class EventQueryStreamController extends QueryStreamController {
|
|
47966
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
47967
|
+
super(query, cacheKey);
|
|
47968
|
+
this.notifyChange = notifyChange;
|
|
47969
|
+
this.preparePayload = preparePayload;
|
|
47970
|
+
}
|
|
47971
|
+
async saveToMainDB(response) {
|
|
47972
|
+
const processedPayload = this.preparePayload(response);
|
|
47973
|
+
const client = getActiveClient();
|
|
47974
|
+
const cachedAt = client.cache && Date.now();
|
|
47975
|
+
if (client.cache)
|
|
47976
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
47977
|
+
}
|
|
47978
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
47979
|
+
var _a, _b;
|
|
47980
|
+
if (refresh) {
|
|
47981
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
47982
|
+
}
|
|
47983
|
+
else {
|
|
47984
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47985
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
47986
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
47987
|
+
}
|
|
47988
|
+
}
|
|
47989
|
+
reactor(action) {
|
|
47990
|
+
return (event) => {
|
|
47991
|
+
var _a;
|
|
47992
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
47993
|
+
if (!collection)
|
|
47994
|
+
return;
|
|
47995
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
47996
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
47997
|
+
}
|
|
47998
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
47999
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
48000
|
+
}
|
|
48001
|
+
pushToCache(this.cacheKey, collection);
|
|
48002
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
48003
|
+
};
|
|
48004
|
+
}
|
|
48005
|
+
subscribeRTE(createSubscriber) {
|
|
48006
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
48007
|
+
}
|
|
48008
|
+
}
|
|
48009
|
+
|
|
48010
|
+
class EventLiveCollectionController extends LiveCollectionController {
|
|
48011
|
+
constructor(query, callback) {
|
|
48012
|
+
const queryStreamId = hash(query);
|
|
48013
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
48014
|
+
const paginationController = new EventPaginationController(query);
|
|
48015
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
48016
|
+
this.query = query;
|
|
48017
|
+
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
48018
|
+
this.callback = callback.bind(this);
|
|
48019
|
+
this.loadPage({ initial: true });
|
|
48020
|
+
}
|
|
48021
|
+
setup() {
|
|
48022
|
+
var _a;
|
|
48023
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48024
|
+
if (!collection)
|
|
48025
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
48026
|
+
}
|
|
48027
|
+
async persistModel(queryPayload) {
|
|
48028
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
48029
|
+
}
|
|
48030
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
48031
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
48032
|
+
}
|
|
48033
|
+
startSubscription() {
|
|
48034
|
+
return this.queryStreamController.subscribeRTE([
|
|
48035
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
48036
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
48037
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
48038
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
48039
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
48040
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
48041
|
+
]);
|
|
48042
|
+
}
|
|
48043
|
+
notifyChange({ origin, loading, error }) {
|
|
48044
|
+
var _a, _b;
|
|
48045
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48046
|
+
if (!collection)
|
|
48047
|
+
return;
|
|
48048
|
+
const data = ((_b = collection.data
|
|
48049
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
48050
|
+
.filter(isNonNullable)
|
|
48051
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
48052
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
48053
|
+
return;
|
|
48054
|
+
this.callback({
|
|
48055
|
+
data,
|
|
48056
|
+
error,
|
|
48057
|
+
loading,
|
|
48058
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
48059
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
48060
|
+
});
|
|
48061
|
+
}
|
|
48062
|
+
}
|
|
48063
|
+
|
|
48064
|
+
/**
|
|
48065
|
+
* Get events
|
|
48066
|
+
*
|
|
48067
|
+
* @param params the query parameters
|
|
48068
|
+
* @param callback the callback to be called when the events are updated
|
|
48069
|
+
* @returns events
|
|
48070
|
+
*
|
|
48071
|
+
* @category Event Live Collection
|
|
48072
|
+
*
|
|
48073
|
+
*/
|
|
48074
|
+
const getEvents = (params, callback, config) => {
|
|
48075
|
+
const { log, cache } = getActiveClient();
|
|
48076
|
+
if (!cache)
|
|
48077
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
48078
|
+
const timestamp = Date.now();
|
|
48079
|
+
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
48080
|
+
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
48081
|
+
const disposers = eventLiveCollection.startSubscription();
|
|
48082
|
+
const cacheKey = eventLiveCollection.getCacheKey();
|
|
48083
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
48084
|
+
return () => {
|
|
48085
|
+
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
48086
|
+
disposers.forEach(fn => fn());
|
|
48087
|
+
};
|
|
48088
|
+
};
|
|
48089
|
+
|
|
48090
|
+
class MyEventPaginationController extends PaginationController {
|
|
48091
|
+
async getRequest(queryParams, token) {
|
|
48092
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
48093
|
+
const options = token ? { token } : { limit };
|
|
48094
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
48095
|
+
return response;
|
|
48096
|
+
}
|
|
48097
|
+
}
|
|
48098
|
+
|
|
48099
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
48100
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
48101
|
+
super(query, cacheKey);
|
|
48102
|
+
this.notifyChange = notifyChange;
|
|
48103
|
+
this.preparePayload = preparePayload;
|
|
48104
|
+
}
|
|
48105
|
+
async saveToMainDB(response) {
|
|
48106
|
+
const processedPayload = this.preparePayload(response);
|
|
48107
|
+
const client = getActiveClient();
|
|
48108
|
+
const cachedAt = client.cache && Date.now();
|
|
48109
|
+
if (client.cache)
|
|
48110
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
48111
|
+
}
|
|
48112
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
48113
|
+
var _a, _b;
|
|
48114
|
+
if (refresh) {
|
|
48115
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
48116
|
+
}
|
|
48117
|
+
else {
|
|
48118
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48119
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
48120
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
48121
|
+
}
|
|
48122
|
+
}
|
|
48123
|
+
reactor(action) {
|
|
48124
|
+
return (event) => {
|
|
48125
|
+
var _a;
|
|
48126
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48127
|
+
if (!collection)
|
|
48128
|
+
return;
|
|
48129
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
48130
|
+
const client = getActiveClient();
|
|
48131
|
+
if (client.userId !== event.userId)
|
|
48132
|
+
return;
|
|
48133
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
48134
|
+
}
|
|
48135
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
48136
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
48137
|
+
}
|
|
48138
|
+
pushToCache(this.cacheKey, collection);
|
|
48139
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
48140
|
+
};
|
|
48141
|
+
}
|
|
48142
|
+
subscribeRTE(createSubscriber) {
|
|
48143
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
48144
|
+
}
|
|
48145
|
+
}
|
|
48146
|
+
|
|
48147
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
48148
|
+
constructor(query, callback) {
|
|
48149
|
+
const queryStreamId = hash(query);
|
|
48150
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
48151
|
+
const paginationController = new MyEventPaginationController(query);
|
|
48152
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
48153
|
+
this.query = query;
|
|
48154
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
48155
|
+
this.callback = callback.bind(this);
|
|
48156
|
+
this.loadPage({ initial: true });
|
|
48157
|
+
}
|
|
48158
|
+
setup() {
|
|
48159
|
+
var _a;
|
|
48160
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48161
|
+
if (!collection)
|
|
48162
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
48163
|
+
}
|
|
48164
|
+
async persistModel(queryPayload) {
|
|
48165
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
48166
|
+
}
|
|
48167
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
48168
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
48169
|
+
}
|
|
48170
|
+
startSubscription() {
|
|
48171
|
+
return this.queryStreamController.subscribeRTE([
|
|
48172
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
48173
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
48174
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
48175
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
48176
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
48177
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
48178
|
+
]);
|
|
48179
|
+
}
|
|
48180
|
+
notifyChange({ origin, loading, error }) {
|
|
48181
|
+
var _a, _b;
|
|
48182
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
48183
|
+
if (!collection)
|
|
48184
|
+
return;
|
|
48185
|
+
const data = ((_b = collection.data
|
|
48186
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
48187
|
+
.filter(isNonNullable)
|
|
48188
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
48189
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
48190
|
+
return;
|
|
48191
|
+
this.callback({
|
|
48192
|
+
data,
|
|
48193
|
+
error,
|
|
48194
|
+
loading,
|
|
48195
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
48196
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
48197
|
+
});
|
|
48198
|
+
}
|
|
48199
|
+
}
|
|
48200
|
+
|
|
48201
|
+
/**
|
|
48202
|
+
* Get my events
|
|
48203
|
+
*
|
|
48204
|
+
* @param params the query parameters
|
|
48205
|
+
* @param callback the callback to be called when the events are updated
|
|
48206
|
+
* @returns events
|
|
48207
|
+
*
|
|
48208
|
+
* @category Event Live Collection
|
|
48209
|
+
*
|
|
48210
|
+
*/
|
|
48211
|
+
const getMyEvents = (params, callback, config) => {
|
|
48212
|
+
const { log, cache } = getActiveClient();
|
|
48213
|
+
if (!cache)
|
|
48214
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
48215
|
+
const timestamp = Date.now();
|
|
48216
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
48217
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
48218
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
48219
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
48220
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
48221
|
+
return () => {
|
|
48222
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
48223
|
+
disposers.forEach(fn => fn());
|
|
48224
|
+
};
|
|
48225
|
+
};
|
|
48226
|
+
|
|
48227
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
48228
|
+
__proto__: null,
|
|
48229
|
+
createEvent: createEvent,
|
|
48230
|
+
updateEvent: updateEvent,
|
|
48231
|
+
deleteEvent: deleteEvent,
|
|
48232
|
+
onEventCreated: onEventCreated,
|
|
48233
|
+
onEventUpdated: onEventUpdated,
|
|
48234
|
+
onEventDeleted: onEventDeleted,
|
|
48235
|
+
onLocalEventCreated: onLocalEventCreated,
|
|
48236
|
+
onLocalEventUpdated: onLocalEventUpdated,
|
|
48237
|
+
onLocalEventDeleted: onLocalEventDeleted,
|
|
48238
|
+
getEvent: getEvent,
|
|
48239
|
+
getEvents: getEvents,
|
|
48240
|
+
getMyEvents: getMyEvents
|
|
48241
|
+
});
|
|
48242
|
+
|
|
48243
|
+
export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$d as CategoryRepository, index$h as ChannelRepository, index$q as Client, index$c as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$e as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$b as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$n as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$l as MessageRepository, index$7 as PollRepository, PostContentType, index$a as PostRepository, PostStructureType, index$m as ReactionRepository, index$8 as RoomRepository, index$5 as StoryRepository, index$9 as StreamRepository, index$k as SubChannelRepository, SubscriptionLevels, index$o as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|