@stream-io/feeds-client 0.1.11 → 0.2.1
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/CHANGELOG.md +25 -0
- package/dist/index-react-bindings.browser.cjs +537 -331
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +537 -331
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +537 -331
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +537 -331
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +536 -329
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +536 -330
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.node.cjs +536 -329
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +536 -330
- package/dist/index.node.js.map +1 -1
- package/dist/src/feed/event-handlers/activity/handle-activity-deleted.d.ts +12 -3
- package/dist/src/feed/event-handlers/activity/handle-activity-pinned.d.ts +3 -0
- package/dist/src/feed/event-handlers/activity/handle-activity-reaction-added.d.ts +10 -6
- package/dist/src/feed/event-handlers/activity/handle-activity-reaction-deleted.d.ts +10 -6
- package/dist/src/feed/event-handlers/activity/handle-activity-unpinned.d.ts +3 -0
- package/dist/src/feed/event-handlers/activity/handle-activity-updated.d.ts +7 -3
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-added.d.ts +10 -6
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-deleted.d.ts +10 -6
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-updated.d.ts +10 -6
- package/dist/src/feed/event-handlers/index.d.ts +1 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-started.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-stopped.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/index.d.ts +2 -0
- package/dist/src/feed/feed.d.ts +4 -12
- package/dist/src/feeds-client/event-handlers/index.d.ts +1 -0
- package/dist/src/feeds-client/event-handlers/user/handle-user-updated.d.ts +3 -0
- package/dist/src/{feeds-client.d.ts → feeds-client/feeds-client.d.ts} +16 -16
- package/dist/src/feeds-client/index.d.ts +2 -0
- package/dist/src/gen/feeds/FeedsApi.d.ts +27 -23
- package/dist/src/gen/models/index.d.ts +198 -23
- package/dist/src/test-utils/response-generators.d.ts +46 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/update-entity-in-array.d.ts +27 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- package/src/feed/event-handlers/activity/activity-reaction-utils.test.ts +108 -96
- package/src/feed/event-handlers/activity/activity-utils.test.ts +84 -122
- package/src/feed/event-handlers/activity/handle-activity-deleted.ts +43 -10
- package/src/feed/event-handlers/activity/handle-activity-pinned.test.ts +60 -0
- package/src/feed/event-handlers/activity/handle-activity-pinned.ts +30 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-added.test.ts +157 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-added.ts +82 -40
- package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.test.ts +200 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.ts +89 -51
- package/src/feed/event-handlers/activity/handle-activity-unpinned.test.ts +94 -0
- package/src/feed/event-handlers/activity/handle-activity-unpinned.ts +30 -0
- package/src/feed/event-handlers/activity/handle-activity-updated.test.ts +115 -0
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +73 -35
- package/src/feed/event-handlers/bookmark/bookmark-utils.test.ts +121 -109
- package/src/feed/event-handlers/bookmark/handle-bookmark-added.test.ts +178 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-added.ts +82 -39
- package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.test.ts +188 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.ts +86 -48
- package/src/feed/event-handlers/bookmark/handle-bookmark-updated.test.ts +196 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-updated.ts +83 -44
- package/src/feed/event-handlers/follow/handle-follow-created.test.ts +16 -12
- package/src/feed/event-handlers/follow/handle-follow-created.ts +4 -7
- package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +19 -15
- package/src/feed/event-handlers/follow/handle-follow-deleted.ts +6 -6
- package/src/feed/event-handlers/follow/handle-follow-updated.ts +7 -10
- package/src/feed/event-handlers/index.ts +2 -1
- package/src/feed/event-handlers/watch/handle-watch-started.ts +5 -0
- package/src/feed/event-handlers/watch/handle-watch-stopped.ts +5 -0
- package/src/feed/event-handlers/watch/index.ts +2 -0
- package/src/feed/feed.ts +15 -33
- package/src/feeds-client/event-handlers/index.ts +1 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.test.ts +53 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.ts +28 -0
- package/src/{feeds-client.ts → feeds-client/feeds-client.ts} +48 -39
- package/src/feeds-client/index.ts +2 -0
- package/src/gen/feeds/FeedsApi.ts +164 -138
- package/src/gen/model-decoders/decoders.ts +28 -0
- package/src/gen/models/index.ts +349 -29
- package/src/gen/moderation/ModerationApi.ts +1 -0
- package/src/test-utils/response-generators.ts +270 -11
- package/src/utils/index.ts +1 -0
- package/src/utils/state-update-queue.ts +1 -1
- package/src/utils/update-entity-in-array.ts +51 -0
package/dist/index.node.cjs
CHANGED
|
@@ -340,6 +340,7 @@ decoders.Channel = (input) => {
|
|
|
340
340
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
341
341
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
342
342
|
last_message_at: { type: 'DatetimeType', isSingle: true },
|
|
343
|
+
message_count_updated_at: { type: 'DatetimeType', isSingle: true },
|
|
343
344
|
active_live_locations: { type: 'SharedLocation', isSingle: false },
|
|
344
345
|
invites: { type: 'ChannelMember', isSingle: false },
|
|
345
346
|
members: { type: 'ChannelMember', isSingle: false },
|
|
@@ -617,6 +618,7 @@ decoders.FeedMemberResponse = (input) => {
|
|
|
617
618
|
user: { type: 'UserResponse', isSingle: true },
|
|
618
619
|
invite_accepted_at: { type: 'DatetimeType', isSingle: true },
|
|
619
620
|
invite_rejected_at: { type: 'DatetimeType', isSingle: true },
|
|
621
|
+
membership_level: { type: 'MembershipLevelResponse', isSingle: true },
|
|
620
622
|
};
|
|
621
623
|
return decode(typeMappings, input);
|
|
622
624
|
};
|
|
@@ -634,6 +636,7 @@ decoders.FeedResponse = (input) => {
|
|
|
634
636
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
635
637
|
created_by: { type: 'UserResponse', isSingle: true },
|
|
636
638
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
639
|
+
own_follows: { type: 'FollowResponse', isSingle: false },
|
|
637
640
|
};
|
|
638
641
|
return decode(typeMappings, input);
|
|
639
642
|
};
|
|
@@ -788,6 +791,13 @@ decoders.ListDevicesResponse = (input) => {
|
|
|
788
791
|
};
|
|
789
792
|
return decode(typeMappings, input);
|
|
790
793
|
};
|
|
794
|
+
decoders.MembershipLevelResponse = (input) => {
|
|
795
|
+
const typeMappings = {
|
|
796
|
+
created_at: { type: 'DatetimeType', isSingle: true },
|
|
797
|
+
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
798
|
+
};
|
|
799
|
+
return decode(typeMappings, input);
|
|
800
|
+
};
|
|
791
801
|
decoders.Message = (input) => {
|
|
792
802
|
const typeMappings = {
|
|
793
803
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -852,6 +862,13 @@ decoders.ModerationCustomActionEvent = (input) => {
|
|
|
852
862
|
};
|
|
853
863
|
return decode(typeMappings, input);
|
|
854
864
|
};
|
|
865
|
+
decoders.ModerationFlagResponse = (input) => {
|
|
866
|
+
const typeMappings = {
|
|
867
|
+
review_queue_item: { type: 'ReviewQueueItemResponse', isSingle: true },
|
|
868
|
+
user: { type: 'UserResponse', isSingle: true },
|
|
869
|
+
};
|
|
870
|
+
return decode(typeMappings, input);
|
|
871
|
+
};
|
|
855
872
|
decoders.ModerationFlaggedEvent = (input) => {
|
|
856
873
|
const typeMappings = {
|
|
857
874
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -888,6 +905,7 @@ decoders.NotificationFeedUpdatedEvent = (input) => {
|
|
|
888
905
|
};
|
|
889
906
|
decoders.NotificationStatusResponse = (input) => {
|
|
890
907
|
const typeMappings = {
|
|
908
|
+
last_read_at: { type: 'DatetimeType', isSingle: true },
|
|
891
909
|
last_seen_at: { type: 'DatetimeType', isSingle: true },
|
|
892
910
|
};
|
|
893
911
|
return decode(typeMappings, input);
|
|
@@ -1155,6 +1173,7 @@ decoders.ReviewQueueItemResponse = (input) => {
|
|
|
1155
1173
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1156
1174
|
actions: { type: 'ActionLogResponse', isSingle: false },
|
|
1157
1175
|
bans: { type: 'Ban', isSingle: false },
|
|
1176
|
+
flags: { type: 'ModerationFlagResponse', isSingle: false },
|
|
1158
1177
|
completed_at: { type: 'DatetimeType', isSingle: true },
|
|
1159
1178
|
reviewed_at: { type: 'DatetimeType', isSingle: true },
|
|
1160
1179
|
assigned_to: { type: 'UserResponse', isSingle: true },
|
|
@@ -1477,7 +1496,7 @@ class FeedsApi {
|
|
|
1477
1496
|
async addActivity(request) {
|
|
1478
1497
|
const body = {
|
|
1479
1498
|
type: request?.type,
|
|
1480
|
-
|
|
1499
|
+
feeds: request?.feeds,
|
|
1481
1500
|
expires_at: request?.expires_at,
|
|
1482
1501
|
id: request?.id,
|
|
1483
1502
|
parent_id: request?.parent_id,
|
|
@@ -1507,7 +1526,7 @@ class FeedsApi {
|
|
|
1507
1526
|
}
|
|
1508
1527
|
async deleteActivities(request) {
|
|
1509
1528
|
const body = {
|
|
1510
|
-
|
|
1529
|
+
ids: request?.ids,
|
|
1511
1530
|
hard_delete: request?.hard_delete,
|
|
1512
1531
|
};
|
|
1513
1532
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/delete', undefined, undefined, body, 'application/json');
|
|
@@ -1526,56 +1545,6 @@ class FeedsApi {
|
|
|
1526
1545
|
decoders.QueryActivitiesResponse?.(response.body);
|
|
1527
1546
|
return { ...response.body, metadata: response.metadata };
|
|
1528
1547
|
}
|
|
1529
|
-
async deleteActivity(request) {
|
|
1530
|
-
const queryParams = {
|
|
1531
|
-
hard_delete: request?.hard_delete,
|
|
1532
|
-
};
|
|
1533
|
-
const pathParams = {
|
|
1534
|
-
activity_id: request?.activity_id,
|
|
1535
|
-
};
|
|
1536
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{activity_id}', pathParams, queryParams);
|
|
1537
|
-
decoders.DeleteActivityResponse?.(response.body);
|
|
1538
|
-
return { ...response.body, metadata: response.metadata };
|
|
1539
|
-
}
|
|
1540
|
-
async getActivity(request) {
|
|
1541
|
-
const pathParams = {
|
|
1542
|
-
activity_id: request?.activity_id,
|
|
1543
|
-
};
|
|
1544
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined);
|
|
1545
|
-
decoders.GetActivityResponse?.(response.body);
|
|
1546
|
-
return { ...response.body, metadata: response.metadata };
|
|
1547
|
-
}
|
|
1548
|
-
async updateActivityPartial(request) {
|
|
1549
|
-
const pathParams = {
|
|
1550
|
-
activity_id: request?.activity_id,
|
|
1551
|
-
};
|
|
1552
|
-
const body = {
|
|
1553
|
-
unset: request?.unset,
|
|
1554
|
-
set: request?.set,
|
|
1555
|
-
};
|
|
1556
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1557
|
-
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1558
|
-
return { ...response.body, metadata: response.metadata };
|
|
1559
|
-
}
|
|
1560
|
-
async updateActivity(request) {
|
|
1561
|
-
const pathParams = {
|
|
1562
|
-
activity_id: request?.activity_id,
|
|
1563
|
-
};
|
|
1564
|
-
const body = {
|
|
1565
|
-
expires_at: request?.expires_at,
|
|
1566
|
-
poll_id: request?.poll_id,
|
|
1567
|
-
text: request?.text,
|
|
1568
|
-
visibility: request?.visibility,
|
|
1569
|
-
attachments: request?.attachments,
|
|
1570
|
-
filter_tags: request?.filter_tags,
|
|
1571
|
-
interest_tags: request?.interest_tags,
|
|
1572
|
-
custom: request?.custom,
|
|
1573
|
-
location: request?.location,
|
|
1574
|
-
};
|
|
1575
|
-
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1576
|
-
decoders.UpdateActivityResponse?.(response.body);
|
|
1577
|
-
return { ...response.body, metadata: response.metadata };
|
|
1578
|
-
}
|
|
1579
1548
|
async deleteBookmark(request) {
|
|
1580
1549
|
const queryParams = {
|
|
1581
1550
|
folder_id: request?.folder_id,
|
|
@@ -1614,6 +1583,21 @@ class FeedsApi {
|
|
|
1614
1583
|
decoders.AddBookmarkResponse?.(response.body);
|
|
1615
1584
|
return { ...response.body, metadata: response.metadata };
|
|
1616
1585
|
}
|
|
1586
|
+
async activityFeedback(request) {
|
|
1587
|
+
const pathParams = {
|
|
1588
|
+
activity_id: request?.activity_id,
|
|
1589
|
+
};
|
|
1590
|
+
const body = {
|
|
1591
|
+
hide: request?.hide,
|
|
1592
|
+
mute_user: request?.mute_user,
|
|
1593
|
+
reason: request?.reason,
|
|
1594
|
+
report: request?.report,
|
|
1595
|
+
show_less: request?.show_less,
|
|
1596
|
+
};
|
|
1597
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/{activity_id}/feedback', pathParams, undefined, body, 'application/json');
|
|
1598
|
+
decoders.ActivityFeedbackResponse?.(response.body);
|
|
1599
|
+
return { ...response.body, metadata: response.metadata };
|
|
1600
|
+
}
|
|
1617
1601
|
async castPollVote(request) {
|
|
1618
1602
|
const pathParams = {
|
|
1619
1603
|
activity_id: request?.activity_id,
|
|
@@ -1676,6 +1660,56 @@ class FeedsApi {
|
|
|
1676
1660
|
decoders.DeleteActivityReactionResponse?.(response.body);
|
|
1677
1661
|
return { ...response.body, metadata: response.metadata };
|
|
1678
1662
|
}
|
|
1663
|
+
async deleteActivity(request) {
|
|
1664
|
+
const queryParams = {
|
|
1665
|
+
hard_delete: request?.hard_delete,
|
|
1666
|
+
};
|
|
1667
|
+
const pathParams = {
|
|
1668
|
+
id: request?.id,
|
|
1669
|
+
};
|
|
1670
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{id}', pathParams, queryParams);
|
|
1671
|
+
decoders.DeleteActivityResponse?.(response.body);
|
|
1672
|
+
return { ...response.body, metadata: response.metadata };
|
|
1673
|
+
}
|
|
1674
|
+
async getActivity(request) {
|
|
1675
|
+
const pathParams = {
|
|
1676
|
+
id: request?.id,
|
|
1677
|
+
};
|
|
1678
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{id}', pathParams, undefined);
|
|
1679
|
+
decoders.GetActivityResponse?.(response.body);
|
|
1680
|
+
return { ...response.body, metadata: response.metadata };
|
|
1681
|
+
}
|
|
1682
|
+
async updateActivityPartial(request) {
|
|
1683
|
+
const pathParams = {
|
|
1684
|
+
id: request?.id,
|
|
1685
|
+
};
|
|
1686
|
+
const body = {
|
|
1687
|
+
unset: request?.unset,
|
|
1688
|
+
set: request?.set,
|
|
1689
|
+
};
|
|
1690
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1691
|
+
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1692
|
+
return { ...response.body, metadata: response.metadata };
|
|
1693
|
+
}
|
|
1694
|
+
async updateActivity(request) {
|
|
1695
|
+
const pathParams = {
|
|
1696
|
+
id: request?.id,
|
|
1697
|
+
};
|
|
1698
|
+
const body = {
|
|
1699
|
+
expires_at: request?.expires_at,
|
|
1700
|
+
poll_id: request?.poll_id,
|
|
1701
|
+
text: request?.text,
|
|
1702
|
+
visibility: request?.visibility,
|
|
1703
|
+
attachments: request?.attachments,
|
|
1704
|
+
filter_tags: request?.filter_tags,
|
|
1705
|
+
interest_tags: request?.interest_tags,
|
|
1706
|
+
custom: request?.custom,
|
|
1707
|
+
location: request?.location,
|
|
1708
|
+
};
|
|
1709
|
+
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1710
|
+
decoders.UpdateActivityResponse?.(response.body);
|
|
1711
|
+
return { ...response.body, metadata: response.metadata };
|
|
1712
|
+
}
|
|
1679
1713
|
async queryBookmarkFolders(request) {
|
|
1680
1714
|
const body = {
|
|
1681
1715
|
limit: request?.limit,
|
|
@@ -1771,49 +1805,52 @@ class FeedsApi {
|
|
|
1771
1805
|
return { ...response.body, metadata: response.metadata };
|
|
1772
1806
|
}
|
|
1773
1807
|
async deleteComment(request) {
|
|
1808
|
+
const queryParams = {
|
|
1809
|
+
hard_delete: request?.hard_delete,
|
|
1810
|
+
};
|
|
1774
1811
|
const pathParams = {
|
|
1775
|
-
|
|
1812
|
+
id: request?.id,
|
|
1776
1813
|
};
|
|
1777
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1814
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}', pathParams, queryParams);
|
|
1778
1815
|
decoders.DeleteCommentResponse?.(response.body);
|
|
1779
1816
|
return { ...response.body, metadata: response.metadata };
|
|
1780
1817
|
}
|
|
1781
1818
|
async getComment(request) {
|
|
1782
1819
|
const pathParams = {
|
|
1783
|
-
|
|
1820
|
+
id: request?.id,
|
|
1784
1821
|
};
|
|
1785
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1822
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}', pathParams, undefined);
|
|
1786
1823
|
decoders.GetCommentResponse?.(response.body);
|
|
1787
1824
|
return { ...response.body, metadata: response.metadata };
|
|
1788
1825
|
}
|
|
1789
1826
|
async updateComment(request) {
|
|
1790
1827
|
const pathParams = {
|
|
1791
|
-
|
|
1828
|
+
id: request?.id,
|
|
1792
1829
|
};
|
|
1793
1830
|
const body = {
|
|
1794
1831
|
comment: request?.comment,
|
|
1795
1832
|
custom: request?.custom,
|
|
1796
1833
|
};
|
|
1797
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{
|
|
1834
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{id}', pathParams, undefined, body, 'application/json');
|
|
1798
1835
|
decoders.UpdateCommentResponse?.(response.body);
|
|
1799
1836
|
return { ...response.body, metadata: response.metadata };
|
|
1800
1837
|
}
|
|
1801
1838
|
async addCommentReaction(request) {
|
|
1802
1839
|
const pathParams = {
|
|
1803
|
-
|
|
1840
|
+
id: request?.id,
|
|
1804
1841
|
};
|
|
1805
1842
|
const body = {
|
|
1806
1843
|
type: request?.type,
|
|
1807
1844
|
create_notification_activity: request?.create_notification_activity,
|
|
1808
1845
|
custom: request?.custom,
|
|
1809
1846
|
};
|
|
1810
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1847
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions', pathParams, undefined, body, 'application/json');
|
|
1811
1848
|
decoders.AddCommentReactionResponse?.(response.body);
|
|
1812
1849
|
return { ...response.body, metadata: response.metadata };
|
|
1813
1850
|
}
|
|
1814
1851
|
async queryCommentReactions(request) {
|
|
1815
1852
|
const pathParams = {
|
|
1816
|
-
|
|
1853
|
+
id: request?.id,
|
|
1817
1854
|
};
|
|
1818
1855
|
const body = {
|
|
1819
1856
|
limit: request?.limit,
|
|
@@ -1822,16 +1859,16 @@ class FeedsApi {
|
|
|
1822
1859
|
sort: request?.sort,
|
|
1823
1860
|
filter: request?.filter,
|
|
1824
1861
|
};
|
|
1825
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1862
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions/query', pathParams, undefined, body, 'application/json');
|
|
1826
1863
|
decoders.QueryCommentReactionsResponse?.(response.body);
|
|
1827
1864
|
return { ...response.body, metadata: response.metadata };
|
|
1828
1865
|
}
|
|
1829
1866
|
async deleteCommentReaction(request) {
|
|
1830
1867
|
const pathParams = {
|
|
1831
|
-
|
|
1868
|
+
id: request?.id,
|
|
1832
1869
|
type: request?.type,
|
|
1833
1870
|
};
|
|
1834
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1871
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}/reactions/{type}', pathParams, undefined);
|
|
1835
1872
|
decoders.DeleteCommentReactionResponse?.(response.body);
|
|
1836
1873
|
return { ...response.body, metadata: response.metadata };
|
|
1837
1874
|
}
|
|
@@ -1845,9 +1882,9 @@ class FeedsApi {
|
|
|
1845
1882
|
next: request?.next,
|
|
1846
1883
|
};
|
|
1847
1884
|
const pathParams = {
|
|
1848
|
-
|
|
1885
|
+
id: request?.id,
|
|
1849
1886
|
};
|
|
1850
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1887
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}/replies', pathParams, queryParams);
|
|
1851
1888
|
decoders.GetCommentRepliesResponse?.(response.body);
|
|
1852
1889
|
return { ...response.body, metadata: response.metadata };
|
|
1853
1890
|
}
|
|
@@ -1896,7 +1933,6 @@ class FeedsApi {
|
|
|
1896
1933
|
feed_id: request?.feed_id,
|
|
1897
1934
|
};
|
|
1898
1935
|
const body = {
|
|
1899
|
-
created_by_id: request?.created_by_id,
|
|
1900
1936
|
custom: request?.custom,
|
|
1901
1937
|
};
|
|
1902
1938
|
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}', pathParams, undefined, body, 'application/json');
|
|
@@ -1912,6 +1948,7 @@ class FeedsApi {
|
|
|
1912
1948
|
mark_all_read: request?.mark_all_read,
|
|
1913
1949
|
mark_all_seen: request?.mark_all_seen,
|
|
1914
1950
|
mark_read: request?.mark_read,
|
|
1951
|
+
mark_seen: request?.mark_seen,
|
|
1915
1952
|
mark_watched: request?.mark_watched,
|
|
1916
1953
|
};
|
|
1917
1954
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}/activities/mark/batch', pathParams, undefined, body, 'application/json');
|
|
@@ -2022,7 +2059,7 @@ class FeedsApi {
|
|
|
2022
2059
|
decoders.CreateFeedsBatchResponse?.(response.body);
|
|
2023
2060
|
return { ...response.body, metadata: response.metadata };
|
|
2024
2061
|
}
|
|
2025
|
-
async
|
|
2062
|
+
async _queryFeeds(request) {
|
|
2026
2063
|
const queryParams = {
|
|
2027
2064
|
connection_id: request?.connection_id,
|
|
2028
2065
|
};
|
|
@@ -2065,8 +2102,8 @@ class FeedsApi {
|
|
|
2065
2102
|
}
|
|
2066
2103
|
async acceptFollow(request) {
|
|
2067
2104
|
const body = {
|
|
2068
|
-
|
|
2069
|
-
|
|
2105
|
+
source: request?.source,
|
|
2106
|
+
target: request?.target,
|
|
2070
2107
|
follower_role: request?.follower_role,
|
|
2071
2108
|
};
|
|
2072
2109
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/accept', undefined, undefined, body, 'application/json');
|
|
@@ -2095,8 +2132,8 @@ class FeedsApi {
|
|
|
2095
2132
|
}
|
|
2096
2133
|
async rejectFollow(request) {
|
|
2097
2134
|
const body = {
|
|
2098
|
-
|
|
2099
|
-
|
|
2135
|
+
source: request?.source,
|
|
2136
|
+
target: request?.target,
|
|
2100
2137
|
};
|
|
2101
2138
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/reject', undefined, undefined, body, 'application/json');
|
|
2102
2139
|
decoders.RejectFollowResponse?.(response.body);
|
|
@@ -3792,6 +3829,7 @@ class ModerationApi {
|
|
|
3792
3829
|
block_list_config: request?.block_list_config,
|
|
3793
3830
|
bodyguard_config: request?.bodyguard_config,
|
|
3794
3831
|
google_vision_config: request?.google_vision_config,
|
|
3832
|
+
llm_config: request?.llm_config,
|
|
3795
3833
|
rule_builder_config: request?.rule_builder_config,
|
|
3796
3834
|
velocity_filter_config: request?.velocity_filter_config,
|
|
3797
3835
|
video_call_rule_config: request?.video_call_rule_config,
|
|
@@ -4264,7 +4302,7 @@ const shouldUpdateState = ({ stateUpdateQueueId, stateUpdateQueue, watch, }) =>
|
|
|
4264
4302
|
};
|
|
4265
4303
|
function getStateUpdateQueueId(data, prefix) {
|
|
4266
4304
|
if (isFollowResponse(data)) {
|
|
4267
|
-
const toJoin = [data.source_feed.
|
|
4305
|
+
const toJoin = [data.source_feed.feed, data.target_feed.feed];
|
|
4268
4306
|
if (prefix) {
|
|
4269
4307
|
toJoin.unshift(prefix);
|
|
4270
4308
|
}
|
|
@@ -4275,6 +4313,23 @@ function getStateUpdateQueueId(data, prefix) {
|
|
|
4275
4313
|
throw new Error(`Cannot create state update queueId for data: ${JSON.stringify(data)}`);
|
|
4276
4314
|
}
|
|
4277
4315
|
|
|
4316
|
+
function updateEntityInArray({ matcher, updater, entities, }) {
|
|
4317
|
+
if (!entities || !entities.length) {
|
|
4318
|
+
return { changed: false, entities };
|
|
4319
|
+
}
|
|
4320
|
+
const index = entities.findIndex(matcher);
|
|
4321
|
+
if (index === -1) {
|
|
4322
|
+
return { changed: false, entities };
|
|
4323
|
+
}
|
|
4324
|
+
const newEntity = updater(entities[index]);
|
|
4325
|
+
if (newEntity === entities[index]) {
|
|
4326
|
+
return { changed: false, entities };
|
|
4327
|
+
}
|
|
4328
|
+
const updatedEntities = [...entities];
|
|
4329
|
+
updatedEntities[index] = newEntity;
|
|
4330
|
+
return { changed: true, entities: updatedEntities };
|
|
4331
|
+
}
|
|
4332
|
+
|
|
4278
4333
|
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4279
4334
|
// filter non-accepted follows (the way getOrCreate does by default)
|
|
4280
4335
|
if (follow.status !== 'accepted') {
|
|
@@ -4282,7 +4337,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4282
4337
|
}
|
|
4283
4338
|
let newState = { ...currentState };
|
|
4284
4339
|
// this feed followed someone
|
|
4285
|
-
if (follow.source_feed.
|
|
4340
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4286
4341
|
newState = {
|
|
4287
4342
|
...newState,
|
|
4288
4343
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4295,7 +4350,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4295
4350
|
}
|
|
4296
4351
|
else if (
|
|
4297
4352
|
// someone followed this feed
|
|
4298
|
-
follow.target_feed.
|
|
4353
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4299
4354
|
const source = follow.source_feed;
|
|
4300
4355
|
newState = {
|
|
4301
4356
|
...newState,
|
|
@@ -4324,7 +4379,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4324
4379
|
return;
|
|
4325
4380
|
}
|
|
4326
4381
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4327
|
-
const result = updateStateFollowCreated(follow, this.currentState, this.
|
|
4382
|
+
const result = updateStateFollowCreated(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4328
4383
|
if (result.changed) {
|
|
4329
4384
|
this.state.next(result.data);
|
|
4330
4385
|
}
|
|
@@ -4333,7 +4388,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4333
4388
|
const updateStateFollowDeleted = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4334
4389
|
let newState = { ...currentState };
|
|
4335
4390
|
// this feed unfollowed someone
|
|
4336
|
-
if (follow.source_feed.
|
|
4391
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4337
4392
|
newState = {
|
|
4338
4393
|
...newState,
|
|
4339
4394
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4341,12 +4396,12 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4341
4396
|
};
|
|
4342
4397
|
// Only update if following array already exists
|
|
4343
4398
|
if (currentState.following !== undefined) {
|
|
4344
|
-
newState.following = currentState.following.filter((followItem) => followItem.target_feed.
|
|
4399
|
+
newState.following = currentState.following.filter((followItem) => followItem.target_feed.feed !== follow.target_feed.feed);
|
|
4345
4400
|
}
|
|
4346
4401
|
}
|
|
4347
4402
|
else if (
|
|
4348
4403
|
// someone unfollowed this feed
|
|
4349
|
-
follow.target_feed.
|
|
4404
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4350
4405
|
const source = follow.source_feed;
|
|
4351
4406
|
newState = {
|
|
4352
4407
|
...newState,
|
|
@@ -4355,11 +4410,11 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4355
4410
|
};
|
|
4356
4411
|
if (source.created_by.id === connectedUserId &&
|
|
4357
4412
|
currentState.own_follows !== undefined) {
|
|
4358
|
-
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.
|
|
4413
|
+
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4359
4414
|
}
|
|
4360
4415
|
// Only update if followers array already exists
|
|
4361
4416
|
if (currentState.followers !== undefined) {
|
|
4362
|
-
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.
|
|
4417
|
+
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4363
4418
|
}
|
|
4364
4419
|
}
|
|
4365
4420
|
return { changed: true, data: newState };
|
|
@@ -4374,7 +4429,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4374
4429
|
return;
|
|
4375
4430
|
}
|
|
4376
4431
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4377
|
-
const result = updateStateFollowDeleted(follow, this.currentState, this.
|
|
4432
|
+
const result = updateStateFollowDeleted(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4378
4433
|
{
|
|
4379
4434
|
this.state.next(result.data);
|
|
4380
4435
|
}
|
|
@@ -4383,7 +4438,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4383
4438
|
function handleFollowUpdated(eventOrResponse) {
|
|
4384
4439
|
const follow = eventOrResponse.follow;
|
|
4385
4440
|
const connectedUserId = this.client.state.getLatestValue().connected_user?.id;
|
|
4386
|
-
const currentFeedId = this.
|
|
4441
|
+
const currentFeedId = this.feed;
|
|
4387
4442
|
if (!shouldUpdateState({
|
|
4388
4443
|
stateUpdateQueueId: getStateUpdateQueueId(follow, 'updated'),
|
|
4389
4444
|
stateUpdateQueue: this.stateUpdateQueue,
|
|
@@ -4394,13 +4449,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4394
4449
|
this.state.next((currentState) => {
|
|
4395
4450
|
let newState;
|
|
4396
4451
|
// this feed followed someone
|
|
4397
|
-
if (follow.source_feed.
|
|
4452
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4398
4453
|
newState ?? (newState = {
|
|
4399
4454
|
...currentState,
|
|
4400
4455
|
// Update FeedResponse fields, that has the new follower/following count
|
|
4401
4456
|
...follow.source_feed,
|
|
4402
4457
|
});
|
|
4403
|
-
const index = currentState.following?.findIndex((f) => f.target_feed.
|
|
4458
|
+
const index = currentState.following?.findIndex((f) => f.target_feed.feed === follow.target_feed.feed) ?? -1;
|
|
4404
4459
|
if (index >= 0) {
|
|
4405
4460
|
newState.following = [...newState.following];
|
|
4406
4461
|
newState.following[index] = follow;
|
|
@@ -4408,7 +4463,7 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4408
4463
|
}
|
|
4409
4464
|
else if (
|
|
4410
4465
|
// someone followed this feed
|
|
4411
|
-
follow.target_feed.
|
|
4466
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4412
4467
|
const source = follow.source_feed;
|
|
4413
4468
|
newState ?? (newState = {
|
|
4414
4469
|
...currentState,
|
|
@@ -4417,13 +4472,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4417
4472
|
});
|
|
4418
4473
|
if (source.created_by.id === connectedUserId &&
|
|
4419
4474
|
currentState.own_follows) {
|
|
4420
|
-
const index = currentState.own_follows.findIndex((f) => f.source_feed.
|
|
4475
|
+
const index = currentState.own_follows.findIndex((f) => f.source_feed.feed === follow.source_feed.feed);
|
|
4421
4476
|
if (index >= 0) {
|
|
4422
4477
|
newState.own_follows = [...currentState.own_follows];
|
|
4423
4478
|
newState.own_follows[index] = follow;
|
|
4424
4479
|
}
|
|
4425
4480
|
}
|
|
4426
|
-
const index = currentState.followers?.findIndex((f) => f.source_feed.
|
|
4481
|
+
const index = currentState.followers?.findIndex((f) => f.source_feed.feed === follow.source_feed.feed) ?? -1;
|
|
4427
4482
|
if (index >= 0) {
|
|
4428
4483
|
newState.followers = [...newState.followers];
|
|
4429
4484
|
newState.followers[index] = follow;
|
|
@@ -4610,6 +4665,179 @@ function handleFeedMemberRemoved(event) {
|
|
|
4610
4665
|
});
|
|
4611
4666
|
}
|
|
4612
4667
|
|
|
4668
|
+
const sharedUpdateActivity$5 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4669
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4670
|
+
if (eventBelongsToCurrentUser) {
|
|
4671
|
+
newOwnBookmarks = [...newOwnBookmarks, event.bookmark];
|
|
4672
|
+
}
|
|
4673
|
+
return {
|
|
4674
|
+
...event.bookmark.activity,
|
|
4675
|
+
own_bookmarks: newOwnBookmarks,
|
|
4676
|
+
own_reactions: currentActivity.own_reactions,
|
|
4677
|
+
};
|
|
4678
|
+
};
|
|
4679
|
+
const addBookmarkToActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4680
|
+
entities: activities,
|
|
4681
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4682
|
+
updater: (matchedActivity) => sharedUpdateActivity$5({
|
|
4683
|
+
currentActivity: matchedActivity,
|
|
4684
|
+
event,
|
|
4685
|
+
eventBelongsToCurrentUser,
|
|
4686
|
+
}),
|
|
4687
|
+
});
|
|
4688
|
+
const addBookmarkToPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4689
|
+
entities: pinnedActivities,
|
|
4690
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4691
|
+
updater: (matchedPinnedActivity) => {
|
|
4692
|
+
const newActivity = sharedUpdateActivity$5({
|
|
4693
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4694
|
+
event,
|
|
4695
|
+
eventBelongsToCurrentUser,
|
|
4696
|
+
});
|
|
4697
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4698
|
+
return matchedPinnedActivity;
|
|
4699
|
+
}
|
|
4700
|
+
return {
|
|
4701
|
+
...matchedPinnedActivity,
|
|
4702
|
+
activity: newActivity,
|
|
4703
|
+
};
|
|
4704
|
+
},
|
|
4705
|
+
});
|
|
4706
|
+
function handleBookmarkAdded(event) {
|
|
4707
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4708
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4709
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4710
|
+
const [result1, result2] = [
|
|
4711
|
+
addBookmarkToActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4712
|
+
addBookmarkToPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4713
|
+
];
|
|
4714
|
+
if (result1.changed || result2.changed) {
|
|
4715
|
+
this.state.partialNext({
|
|
4716
|
+
activities: result1.entities,
|
|
4717
|
+
pinned_activities: result2.entities,
|
|
4718
|
+
});
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4722
|
+
// Helper function to check if two bookmarks are the same
|
|
4723
|
+
// A bookmark is identified by activity_id + folder_id + user_id
|
|
4724
|
+
const isSameBookmark = (bookmark1, bookmark2) => {
|
|
4725
|
+
return (bookmark1.user.id === bookmark2.user.id &&
|
|
4726
|
+
bookmark1.activity.id === bookmark2.activity.id &&
|
|
4727
|
+
bookmark1.folder?.id === bookmark2.folder?.id);
|
|
4728
|
+
};
|
|
4729
|
+
const sharedUpdateActivity$4 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4730
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4731
|
+
if (eventBelongsToCurrentUser) {
|
|
4732
|
+
newOwnBookmarks = currentActivity.own_bookmarks.filter((bookmark) => !isSameBookmark(bookmark, event.bookmark));
|
|
4733
|
+
}
|
|
4734
|
+
return {
|
|
4735
|
+
...event.bookmark.activity,
|
|
4736
|
+
own_bookmarks: newOwnBookmarks,
|
|
4737
|
+
own_reactions: currentActivity.own_reactions,
|
|
4738
|
+
};
|
|
4739
|
+
};
|
|
4740
|
+
const removeBookmarkFromActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4741
|
+
entities: activities,
|
|
4742
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4743
|
+
updater: (matchedActivity) => sharedUpdateActivity$4({
|
|
4744
|
+
currentActivity: matchedActivity,
|
|
4745
|
+
event,
|
|
4746
|
+
eventBelongsToCurrentUser,
|
|
4747
|
+
}),
|
|
4748
|
+
});
|
|
4749
|
+
const removeBookmarkFromPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4750
|
+
entities: pinnedActivities,
|
|
4751
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4752
|
+
updater: (matchedPinnedActivity) => {
|
|
4753
|
+
const newActivity = sharedUpdateActivity$4({
|
|
4754
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4755
|
+
event,
|
|
4756
|
+
eventBelongsToCurrentUser,
|
|
4757
|
+
});
|
|
4758
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4759
|
+
return matchedPinnedActivity;
|
|
4760
|
+
}
|
|
4761
|
+
return {
|
|
4762
|
+
...matchedPinnedActivity,
|
|
4763
|
+
activity: newActivity,
|
|
4764
|
+
};
|
|
4765
|
+
},
|
|
4766
|
+
});
|
|
4767
|
+
function handleBookmarkDeleted(event) {
|
|
4768
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4769
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4770
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4771
|
+
const [result1, result2] = [
|
|
4772
|
+
removeBookmarkFromActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4773
|
+
removeBookmarkFromPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4774
|
+
];
|
|
4775
|
+
if (result1.changed || result2.changed) {
|
|
4776
|
+
this.state.partialNext({
|
|
4777
|
+
activities: result1.entities,
|
|
4778
|
+
pinned_activities: result2.entities,
|
|
4779
|
+
});
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
|
|
4783
|
+
const sharedUpdateActivity$3 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4784
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4785
|
+
if (eventBelongsToCurrentUser) {
|
|
4786
|
+
const bookmarkIndex = newOwnBookmarks.findIndex((bookmark) => isSameBookmark(bookmark, event.bookmark));
|
|
4787
|
+
if (bookmarkIndex !== -1) {
|
|
4788
|
+
newOwnBookmarks = [...newOwnBookmarks];
|
|
4789
|
+
newOwnBookmarks[bookmarkIndex] = event.bookmark;
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
return {
|
|
4793
|
+
...event.bookmark.activity,
|
|
4794
|
+
own_bookmarks: newOwnBookmarks,
|
|
4795
|
+
own_reactions: currentActivity.own_reactions,
|
|
4796
|
+
};
|
|
4797
|
+
};
|
|
4798
|
+
const updateBookmarkInActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4799
|
+
entities: activities,
|
|
4800
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4801
|
+
updater: (matchedActivity) => sharedUpdateActivity$3({
|
|
4802
|
+
currentActivity: matchedActivity,
|
|
4803
|
+
event,
|
|
4804
|
+
eventBelongsToCurrentUser,
|
|
4805
|
+
}),
|
|
4806
|
+
});
|
|
4807
|
+
const updateBookmarkInPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4808
|
+
entities: pinnedActivities,
|
|
4809
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4810
|
+
updater: (matchedPinnedActivity) => {
|
|
4811
|
+
const newActivity = sharedUpdateActivity$3({
|
|
4812
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4813
|
+
event,
|
|
4814
|
+
eventBelongsToCurrentUser,
|
|
4815
|
+
});
|
|
4816
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4817
|
+
return matchedPinnedActivity;
|
|
4818
|
+
}
|
|
4819
|
+
return {
|
|
4820
|
+
...matchedPinnedActivity,
|
|
4821
|
+
activity: newActivity,
|
|
4822
|
+
};
|
|
4823
|
+
},
|
|
4824
|
+
});
|
|
4825
|
+
function handleBookmarkUpdated(event) {
|
|
4826
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4827
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4828
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4829
|
+
const [result1, result2] = [
|
|
4830
|
+
updateBookmarkInActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4831
|
+
updateBookmarkInPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4832
|
+
];
|
|
4833
|
+
if (result1.changed || result2.changed) {
|
|
4834
|
+
this.state.partialNext({
|
|
4835
|
+
activities: result1.entities,
|
|
4836
|
+
pinned_activities: result2.entities,
|
|
4837
|
+
});
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
|
|
4613
4841
|
const addActivitiesToState = (newActivities, activities, position) => {
|
|
4614
4842
|
let result;
|
|
4615
4843
|
if (activities === undefined) {
|
|
@@ -4654,7 +4882,8 @@ function handleActivityAdded(event) {
|
|
|
4654
4882
|
}
|
|
4655
4883
|
|
|
4656
4884
|
const removeActivityFromState = (activityResponse, activities) => {
|
|
4657
|
-
const index = activities
|
|
4885
|
+
const index = activities?.findIndex((activity) => activity.id === activityResponse.id) ??
|
|
4886
|
+
-1;
|
|
4658
4887
|
if (index !== -1) {
|
|
4659
4888
|
const newActivities = [...activities];
|
|
4660
4889
|
newActivities.splice(index, 1);
|
|
@@ -4664,13 +4893,28 @@ const removeActivityFromState = (activityResponse, activities) => {
|
|
|
4664
4893
|
return { changed: false, activities };
|
|
4665
4894
|
}
|
|
4666
4895
|
};
|
|
4896
|
+
const removePinnedActivityFromState = (activityResponse, pinnedActivities) => {
|
|
4897
|
+
const index = pinnedActivities?.findIndex((pinnedActivity) => pinnedActivity.activity.id === activityResponse.id) ?? -1;
|
|
4898
|
+
if (index !== -1) {
|
|
4899
|
+
const newActivities = [...pinnedActivities];
|
|
4900
|
+
newActivities.splice(index, 1);
|
|
4901
|
+
return { changed: true, activities: newActivities };
|
|
4902
|
+
}
|
|
4903
|
+
else {
|
|
4904
|
+
return { changed: false, pinned_activities: pinnedActivities };
|
|
4905
|
+
}
|
|
4906
|
+
};
|
|
4667
4907
|
function handleActivityDeleted(event) {
|
|
4668
|
-
const currentActivities = this.currentState
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4908
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4909
|
+
const [result1, result2] = [
|
|
4910
|
+
removeActivityFromState(event.activity, currentActivities),
|
|
4911
|
+
removePinnedActivityFromState(event.activity, currentPinnedActivities),
|
|
4912
|
+
];
|
|
4913
|
+
if (result1.changed || result2.changed) {
|
|
4914
|
+
this.state.partialNext({
|
|
4915
|
+
activities: result1.activities,
|
|
4916
|
+
pinned_activities: result2.pinned_activities,
|
|
4917
|
+
});
|
|
4674
4918
|
}
|
|
4675
4919
|
}
|
|
4676
4920
|
|
|
@@ -4684,221 +4928,163 @@ function handleActivityRemovedFromFeed(event) {
|
|
|
4684
4928
|
}
|
|
4685
4929
|
}
|
|
4686
4930
|
|
|
4687
|
-
const
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4931
|
+
const sharedUpdateActivity$2 = ({ currentActivity, event, }) => {
|
|
4932
|
+
return {
|
|
4933
|
+
...event.activity,
|
|
4934
|
+
own_reactions: currentActivity.own_reactions,
|
|
4935
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
4936
|
+
};
|
|
4937
|
+
};
|
|
4938
|
+
const updateActivityInState = (event, activities) => updateEntityInArray({
|
|
4939
|
+
entities: activities,
|
|
4940
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
4941
|
+
updater: (matchedActivity) => sharedUpdateActivity$2({
|
|
4942
|
+
currentActivity: matchedActivity,
|
|
4943
|
+
event,
|
|
4944
|
+
}),
|
|
4945
|
+
});
|
|
4946
|
+
const updatePinnedActivityInState = (event, pinnedActivities) => updateEntityInArray({
|
|
4947
|
+
entities: pinnedActivities,
|
|
4948
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
4949
|
+
updater: (matchedPinnedActivity) => {
|
|
4950
|
+
const newActivity = sharedUpdateActivity$2({
|
|
4951
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4952
|
+
event,
|
|
4953
|
+
});
|
|
4954
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4955
|
+
return matchedPinnedActivity;
|
|
4703
4956
|
}
|
|
4704
|
-
return {
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
}
|
|
4709
|
-
};
|
|
4957
|
+
return {
|
|
4958
|
+
...matchedPinnedActivity,
|
|
4959
|
+
activity: newActivity,
|
|
4960
|
+
};
|
|
4961
|
+
},
|
|
4962
|
+
});
|
|
4710
4963
|
function handleActivityUpdated(event) {
|
|
4711
|
-
const currentActivities = this.currentState
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4964
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4965
|
+
const [result1, result2] = [
|
|
4966
|
+
updateActivityInState(event, currentActivities),
|
|
4967
|
+
updatePinnedActivityInState(event, currentPinnedActivities),
|
|
4968
|
+
];
|
|
4969
|
+
if (result1.changed || result2.changed) {
|
|
4970
|
+
this.client.hydratePollCache([event.activity]);
|
|
4971
|
+
this.state.partialNext({
|
|
4972
|
+
activities: result1.entities,
|
|
4973
|
+
pinned_activities: result2.entities,
|
|
4974
|
+
});
|
|
4718
4975
|
}
|
|
4719
4976
|
}
|
|
4720
4977
|
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
if (
|
|
4725
|
-
|
|
4978
|
+
// shared function to update the activity with the new reaction
|
|
4979
|
+
const sharedUpdateActivity$1 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4980
|
+
let newOwnReactions = currentActivity.own_reactions;
|
|
4981
|
+
if (eventBelongsToCurrentUser) {
|
|
4982
|
+
newOwnReactions = [...currentActivity.own_reactions, event.reaction];
|
|
4726
4983
|
}
|
|
4727
4984
|
return {
|
|
4728
|
-
...activity,
|
|
4729
|
-
own_reactions:
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4985
|
+
...event.activity,
|
|
4986
|
+
own_reactions: newOwnReactions,
|
|
4987
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
4988
|
+
};
|
|
4989
|
+
};
|
|
4990
|
+
const addReactionToActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4991
|
+
entities: activities,
|
|
4992
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
4993
|
+
updater: (matchedActivity) => sharedUpdateActivity$1({
|
|
4994
|
+
currentActivity: matchedActivity,
|
|
4995
|
+
event,
|
|
4996
|
+
eventBelongsToCurrentUser,
|
|
4997
|
+
}),
|
|
4998
|
+
});
|
|
4999
|
+
const addReactionToPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
5000
|
+
entities: pinnedActivities,
|
|
5001
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
5002
|
+
updater: (matchedPinnedActivity) => {
|
|
5003
|
+
const newActivity = sharedUpdateActivity$1({
|
|
5004
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
5005
|
+
event,
|
|
5006
|
+
eventBelongsToCurrentUser,
|
|
5007
|
+
});
|
|
5008
|
+
// this should never happen, but just in case
|
|
5009
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
5010
|
+
return matchedPinnedActivity;
|
|
5011
|
+
}
|
|
5012
|
+
return {
|
|
5013
|
+
...matchedPinnedActivity,
|
|
5014
|
+
activity: newActivity,
|
|
5015
|
+
};
|
|
5016
|
+
},
|
|
5017
|
+
});
|
|
4747
5018
|
function handleActivityReactionAdded(event) {
|
|
4748
|
-
const currentActivities = this.currentState
|
|
5019
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4749
5020
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4750
|
-
const
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
r.user.id === event.reaction.user.id))
|
|
4762
|
-
: activity.own_reactions;
|
|
4763
|
-
return {
|
|
4764
|
-
...activity,
|
|
4765
|
-
own_reactions: ownReactions,
|
|
4766
|
-
latest_reactions: event.activity.latest_reactions,
|
|
4767
|
-
reaction_groups: event.activity.reaction_groups,
|
|
4768
|
-
changed: true,
|
|
4769
|
-
};
|
|
4770
|
-
};
|
|
4771
|
-
const removeReactionFromActivities = (event, activities, isCurrentUser) => {
|
|
4772
|
-
if (!activities) {
|
|
4773
|
-
return { changed: false, activities: [] };
|
|
4774
|
-
}
|
|
4775
|
-
const activityIndex = activities.findIndex((a) => a.id === event.activity.id);
|
|
4776
|
-
if (activityIndex === -1) {
|
|
4777
|
-
return { changed: false, activities };
|
|
4778
|
-
}
|
|
4779
|
-
const activity = activities[activityIndex];
|
|
4780
|
-
const updatedActivity = removeReactionFromActivity(event, activity, isCurrentUser);
|
|
4781
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4782
|
-
};
|
|
4783
|
-
function handleActivityReactionDeleted(event) {
|
|
4784
|
-
const currentActivities = this.currentState.activities;
|
|
4785
|
-
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4786
|
-
const isCurrentUser = Boolean(connectedUser && event.reaction.user.id === connectedUser.id);
|
|
4787
|
-
const result = removeReactionFromActivities(event, currentActivities, isCurrentUser);
|
|
4788
|
-
if (result.changed) {
|
|
4789
|
-
this.state.partialNext({ activities: result.activities });
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
4792
|
-
|
|
4793
|
-
const addBookmarkToActivity = (event, activity, isCurrentUser) => {
|
|
4794
|
-
// Update own_bookmarks if the bookmark is from the current user
|
|
4795
|
-
const ownBookmarks = [...(activity.own_bookmarks || [])];
|
|
4796
|
-
if (isCurrentUser) {
|
|
4797
|
-
ownBookmarks.push(event.bookmark);
|
|
4798
|
-
}
|
|
4799
|
-
return {
|
|
4800
|
-
...activity,
|
|
4801
|
-
own_bookmarks: ownBookmarks,
|
|
4802
|
-
changed: true,
|
|
4803
|
-
};
|
|
4804
|
-
};
|
|
4805
|
-
const addBookmarkToActivities = (event, activities, isCurrentUser) => {
|
|
4806
|
-
if (!activities) {
|
|
4807
|
-
return { changed: false, activities: [] };
|
|
4808
|
-
}
|
|
4809
|
-
const activityIndex = activities.findIndex((a) => a.id === event.bookmark.activity.id);
|
|
4810
|
-
if (activityIndex === -1) {
|
|
4811
|
-
return { changed: false, activities };
|
|
4812
|
-
}
|
|
4813
|
-
const activity = activities[activityIndex];
|
|
4814
|
-
const updatedActivity = addBookmarkToActivity(event, activity, isCurrentUser);
|
|
4815
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4816
|
-
};
|
|
4817
|
-
function handleBookmarkAdded(event) {
|
|
4818
|
-
const currentActivities = this.currentState.activities;
|
|
4819
|
-
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4820
|
-
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4821
|
-
const result = addBookmarkToActivities(event, currentActivities, isCurrentUser);
|
|
4822
|
-
if (result.changed) {
|
|
4823
|
-
this.state.partialNext({ activities: result.activities });
|
|
5021
|
+
const eventBelongsToCurrentUser = typeof connectedUser !== 'undefined' &&
|
|
5022
|
+
event.reaction.user.id === connectedUser.id;
|
|
5023
|
+
const [result1, result2] = [
|
|
5024
|
+
addReactionToActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
5025
|
+
addReactionToPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
5026
|
+
];
|
|
5027
|
+
if (result1.changed || result2.changed) {
|
|
5028
|
+
this.state.partialNext({
|
|
5029
|
+
activities: result1.entities,
|
|
5030
|
+
pinned_activities: result2.entities,
|
|
5031
|
+
});
|
|
4824
5032
|
}
|
|
4825
5033
|
}
|
|
4826
5034
|
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
bookmark1.folder?.id === bookmark2.folder?.id);
|
|
4833
|
-
};
|
|
4834
|
-
const removeBookmarkFromActivities = (event, activities, isCurrentUser) => {
|
|
4835
|
-
if (!activities) {
|
|
4836
|
-
return { changed: false, activities: [] };
|
|
4837
|
-
}
|
|
4838
|
-
const activityIndex = activities.findIndex((a) => a.id === event.bookmark.activity.id);
|
|
4839
|
-
if (activityIndex === -1) {
|
|
4840
|
-
return { changed: false, activities };
|
|
5035
|
+
const sharedUpdateActivity = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
5036
|
+
let newOwnReactions = currentActivity.own_reactions;
|
|
5037
|
+
if (eventBelongsToCurrentUser) {
|
|
5038
|
+
newOwnReactions = currentActivity.own_reactions.filter((reaction) => !(reaction.type === event.reaction.type &&
|
|
5039
|
+
reaction.user.id === event.reaction.user.id));
|
|
4841
5040
|
}
|
|
4842
|
-
const activity = activities[activityIndex];
|
|
4843
|
-
const updatedActivity = removeBookmarkFromActivity(event, activity, isCurrentUser);
|
|
4844
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4845
|
-
};
|
|
4846
|
-
const removeBookmarkFromActivity = (event, activity, isCurrentUser) => {
|
|
4847
|
-
// Update own_bookmarks if the bookmark is from the current user
|
|
4848
|
-
const ownBookmarks = isCurrentUser
|
|
4849
|
-
? (activity.own_bookmarks || []).filter((bookmark) => !isSameBookmark(bookmark, event.bookmark))
|
|
4850
|
-
: activity.own_bookmarks;
|
|
4851
5041
|
return {
|
|
4852
|
-
...activity,
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
};
|
|
4856
|
-
};
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
}
|
|
4865
|
-
}
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
5042
|
+
...event.activity,
|
|
5043
|
+
own_reactions: newOwnReactions,
|
|
5044
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
5045
|
+
};
|
|
5046
|
+
};
|
|
5047
|
+
const removeReactionFromActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
5048
|
+
entities: activities,
|
|
5049
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
5050
|
+
updater: (matchedActivity) => sharedUpdateActivity({
|
|
5051
|
+
currentActivity: matchedActivity,
|
|
5052
|
+
event,
|
|
5053
|
+
eventBelongsToCurrentUser,
|
|
5054
|
+
}),
|
|
5055
|
+
});
|
|
5056
|
+
const removeReactionFromPinnedActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
5057
|
+
entities: activities,
|
|
5058
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
5059
|
+
updater: (matchedPinnedActivity) => {
|
|
5060
|
+
const newActivity = sharedUpdateActivity({
|
|
5061
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
5062
|
+
event,
|
|
5063
|
+
eventBelongsToCurrentUser,
|
|
5064
|
+
});
|
|
5065
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
5066
|
+
return matchedPinnedActivity;
|
|
4875
5067
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
const
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
const
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
const currentActivities = this.currentState.activities;
|
|
4897
|
-
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4898
|
-
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4899
|
-
const result = updateBookmarkInActivities(event, currentActivities, isCurrentUser);
|
|
4900
|
-
if (result.changed) {
|
|
4901
|
-
this.state.partialNext({ activities: result.activities });
|
|
5068
|
+
return {
|
|
5069
|
+
...matchedPinnedActivity,
|
|
5070
|
+
activity: newActivity,
|
|
5071
|
+
};
|
|
5072
|
+
},
|
|
5073
|
+
});
|
|
5074
|
+
function handleActivityReactionDeleted(event) {
|
|
5075
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
5076
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
5077
|
+
const eventBelongsToCurrentUser = typeof connectedUser !== 'undefined' &&
|
|
5078
|
+
event.reaction.user.id === connectedUser.id;
|
|
5079
|
+
const [result1, result2] = [
|
|
5080
|
+
removeReactionFromActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
5081
|
+
removeReactionFromPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
5082
|
+
];
|
|
5083
|
+
if (result1.changed || result2.changed) {
|
|
5084
|
+
this.state.partialNext({
|
|
5085
|
+
activities: result1.entities,
|
|
5086
|
+
pinned_activities: result2.entities,
|
|
5087
|
+
});
|
|
4902
5088
|
}
|
|
4903
5089
|
}
|
|
4904
5090
|
|
|
@@ -4911,6 +5097,14 @@ function handleNotificationFeedUpdated(event) {
|
|
|
4911
5097
|
// TODO: handle notification feed updates
|
|
4912
5098
|
}
|
|
4913
5099
|
|
|
5100
|
+
function handleWatchStarted() {
|
|
5101
|
+
this.state.partialNext({ watch: true });
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
function handleWatchStopped() {
|
|
5105
|
+
this.state.partialNext({ watch: false });
|
|
5106
|
+
}
|
|
5107
|
+
|
|
4914
5108
|
class Feed extends FeedApi {
|
|
4915
5109
|
constructor(client, groupId, id, data, watch = false) {
|
|
4916
5110
|
super(client, groupId, id);
|
|
@@ -4971,7 +5165,7 @@ class Feed extends FeedApi {
|
|
|
4971
5165
|
this.on = this.eventDispatcher.on;
|
|
4972
5166
|
this.off = this.eventDispatcher.off;
|
|
4973
5167
|
this.state = new StateStore({
|
|
4974
|
-
|
|
5168
|
+
feed: `${groupId}:${id}`,
|
|
4975
5169
|
group_id: groupId,
|
|
4976
5170
|
id,
|
|
4977
5171
|
...(data ?? {}),
|
|
@@ -4982,7 +5176,7 @@ class Feed extends FeedApi {
|
|
|
4982
5176
|
});
|
|
4983
5177
|
this.client = client;
|
|
4984
5178
|
}
|
|
4985
|
-
get
|
|
5179
|
+
get feed() {
|
|
4986
5180
|
return `${this.group}:${this.id}`;
|
|
4987
5181
|
}
|
|
4988
5182
|
get currentState() {
|
|
@@ -5057,22 +5251,6 @@ class Feed extends FeedApi {
|
|
|
5057
5251
|
});
|
|
5058
5252
|
}
|
|
5059
5253
|
}
|
|
5060
|
-
/**
|
|
5061
|
-
* @internal
|
|
5062
|
-
*/
|
|
5063
|
-
handleWatchStopped() {
|
|
5064
|
-
this.state.partialNext({
|
|
5065
|
-
watch: false,
|
|
5066
|
-
});
|
|
5067
|
-
}
|
|
5068
|
-
/**
|
|
5069
|
-
* @internal
|
|
5070
|
-
*/
|
|
5071
|
-
handleWatchStarted() {
|
|
5072
|
-
this.state.partialNext({
|
|
5073
|
-
watch: true,
|
|
5074
|
-
});
|
|
5075
|
-
}
|
|
5076
5254
|
/**
|
|
5077
5255
|
* Returns index of the provided comment object.
|
|
5078
5256
|
*/
|
|
@@ -5232,7 +5410,7 @@ class Feed extends FeedApi {
|
|
|
5232
5410
|
entityId: comment.id,
|
|
5233
5411
|
base: () => this.client.getCommentReplies({
|
|
5234
5412
|
...request,
|
|
5235
|
-
|
|
5413
|
+
id: comment.id,
|
|
5236
5414
|
// use known sort first (prevents broken pagination)
|
|
5237
5415
|
sort,
|
|
5238
5416
|
next: currentNextCursor,
|
|
@@ -5272,7 +5450,7 @@ class Feed extends FeedApi {
|
|
|
5272
5450
|
...currentState,
|
|
5273
5451
|
[type]: currentState[type] === undefined
|
|
5274
5452
|
? follows
|
|
5275
|
-
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.
|
|
5453
|
+
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.feed}-${follow.target_feed.feed}`),
|
|
5276
5454
|
[paginationKey]: {
|
|
5277
5455
|
...currentState[paginationKey],
|
|
5278
5456
|
next: newNextCursor,
|
|
@@ -5365,7 +5543,7 @@ class Feed extends FeedApi {
|
|
|
5365
5543
|
*/
|
|
5366
5544
|
async queryFollowers(request) {
|
|
5367
5545
|
const filter = {
|
|
5368
|
-
target_feed: this.
|
|
5546
|
+
target_feed: this.feed,
|
|
5369
5547
|
};
|
|
5370
5548
|
const response = await this.client.queryFollows({
|
|
5371
5549
|
filter,
|
|
@@ -5380,7 +5558,7 @@ class Feed extends FeedApi {
|
|
|
5380
5558
|
*/
|
|
5381
5559
|
async queryFollowing(request) {
|
|
5382
5560
|
const filter = {
|
|
5383
|
-
source_feed: this.
|
|
5561
|
+
source_feed: this.feed,
|
|
5384
5562
|
};
|
|
5385
5563
|
const response = await this.client.queryFollows({
|
|
5386
5564
|
filter,
|
|
@@ -5389,18 +5567,18 @@ class Feed extends FeedApi {
|
|
|
5389
5567
|
return response;
|
|
5390
5568
|
}
|
|
5391
5569
|
async follow(feedOrFid, options) {
|
|
5392
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5570
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5393
5571
|
const response = await this.client.follow({
|
|
5394
5572
|
...options,
|
|
5395
|
-
source: this.
|
|
5573
|
+
source: this.feed,
|
|
5396
5574
|
target: fid,
|
|
5397
5575
|
});
|
|
5398
5576
|
return response;
|
|
5399
5577
|
}
|
|
5400
5578
|
async unfollow(feedOrFid) {
|
|
5401
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5579
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5402
5580
|
const response = await this.client.unfollow({
|
|
5403
|
-
source: this.
|
|
5581
|
+
source: this.feed,
|
|
5404
5582
|
target: fid,
|
|
5405
5583
|
});
|
|
5406
5584
|
return response;
|
|
@@ -5424,7 +5602,7 @@ class Feed extends FeedApi {
|
|
|
5424
5602
|
addActivity(request) {
|
|
5425
5603
|
return this.feedsApi.addActivity({
|
|
5426
5604
|
...request,
|
|
5427
|
-
|
|
5605
|
+
feeds: [this.feed],
|
|
5428
5606
|
});
|
|
5429
5607
|
}
|
|
5430
5608
|
handleWSEvent(event) {
|
|
@@ -5442,6 +5620,24 @@ class Feed extends FeedApi {
|
|
|
5442
5620
|
}
|
|
5443
5621
|
Feed.noop = () => { };
|
|
5444
5622
|
|
|
5623
|
+
function handleUserUpdated(event) {
|
|
5624
|
+
this.state.next((currentState) => {
|
|
5625
|
+
let newState;
|
|
5626
|
+
const { connected_user } = currentState;
|
|
5627
|
+
if (connected_user && connected_user.id === event.user.id) {
|
|
5628
|
+
newState ?? (newState = {
|
|
5629
|
+
...currentState,
|
|
5630
|
+
});
|
|
5631
|
+
newState.connected_user = {
|
|
5632
|
+
...connected_user,
|
|
5633
|
+
...event.user,
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5636
|
+
// TODO: update other users in user map (if/once applicable)
|
|
5637
|
+
return newState ?? currentState;
|
|
5638
|
+
});
|
|
5639
|
+
}
|
|
5640
|
+
|
|
5445
5641
|
class FeedsClient extends FeedsApi {
|
|
5446
5642
|
constructor(apiKey, options) {
|
|
5447
5643
|
const tokenManager = new TokenManager();
|
|
@@ -5549,7 +5745,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5549
5745
|
if (this.activeFeeds[fid]) {
|
|
5550
5746
|
const feed = this.activeFeeds[fid];
|
|
5551
5747
|
if (watch && !feed.currentState.watch) {
|
|
5552
|
-
|
|
5748
|
+
handleWatchStarted.bind(feed)();
|
|
5553
5749
|
}
|
|
5554
5750
|
return feed;
|
|
5555
5751
|
}
|
|
@@ -5585,7 +5781,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5585
5781
|
}
|
|
5586
5782
|
else {
|
|
5587
5783
|
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
5588
|
-
|
|
5784
|
+
handleWatchStopped.bind(activeFeed)();
|
|
5589
5785
|
}
|
|
5590
5786
|
}
|
|
5591
5787
|
break;
|
|
@@ -5665,6 +5861,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5665
5861
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
5666
5862
|
break;
|
|
5667
5863
|
}
|
|
5864
|
+
case 'user.updated': {
|
|
5865
|
+
handleUserUpdated.call(this, event);
|
|
5866
|
+
break;
|
|
5867
|
+
}
|
|
5668
5868
|
default: {
|
|
5669
5869
|
feed?.handleWSEvent(event);
|
|
5670
5870
|
}
|
|
@@ -5690,7 +5890,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5690
5890
|
}
|
|
5691
5891
|
}
|
|
5692
5892
|
async queryFeeds(request) {
|
|
5693
|
-
const response = await this.
|
|
5893
|
+
const response = await this._queryFeeds(request);
|
|
5694
5894
|
const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
|
|
5695
5895
|
return {
|
|
5696
5896
|
feeds,
|
|
@@ -5702,7 +5902,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5702
5902
|
}
|
|
5703
5903
|
async updateFollow(request) {
|
|
5704
5904
|
const response = await super.updateFollow(request);
|
|
5705
|
-
[
|
|
5905
|
+
[
|
|
5906
|
+
response.follow.source_feed.feed,
|
|
5907
|
+
response.follow.target_feed.feed,
|
|
5908
|
+
].forEach((fid) => {
|
|
5706
5909
|
const feed = this.activeFeeds[fid];
|
|
5707
5910
|
if (feed) {
|
|
5708
5911
|
handleFollowUpdated.bind(feed)(response);
|
|
@@ -5713,7 +5916,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5713
5916
|
// For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
|
|
5714
5917
|
async follow(request) {
|
|
5715
5918
|
const response = await super.follow(request);
|
|
5716
|
-
[
|
|
5919
|
+
[
|
|
5920
|
+
response.follow.source_feed.feed,
|
|
5921
|
+
response.follow.target_feed.feed,
|
|
5922
|
+
].forEach((fid) => {
|
|
5717
5923
|
const feed = this.activeFeeds[fid];
|
|
5718
5924
|
if (feed) {
|
|
5719
5925
|
handleFollowCreated.bind(feed)(response);
|
|
@@ -5724,7 +5930,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5724
5930
|
async followBatch(request) {
|
|
5725
5931
|
const response = await super.followBatch(request);
|
|
5726
5932
|
response.follows.forEach((follow) => {
|
|
5727
|
-
const feed = this.activeFeeds[follow.source_feed.
|
|
5933
|
+
const feed = this.activeFeeds[follow.source_feed.feed];
|
|
5728
5934
|
if (feed) {
|
|
5729
5935
|
handleFollowCreated.bind(feed)({ follow });
|
|
5730
5936
|
}
|
|
@@ -5749,7 +5955,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5749
5955
|
});
|
|
5750
5956
|
const feed = this.activeFeeds[`${request.feed_group_id}:${request.feed_id}`];
|
|
5751
5957
|
if (feed) {
|
|
5752
|
-
|
|
5958
|
+
handleWatchStopped.bind(feed)();
|
|
5753
5959
|
}
|
|
5754
5960
|
return response;
|
|
5755
5961
|
}
|
|
@@ -6190,4 +6396,5 @@ exports.isVideoFile = isVideoFile;
|
|
|
6190
6396
|
exports.isVoteAnswer = isVoteAnswer;
|
|
6191
6397
|
exports.shouldUpdateState = shouldUpdateState;
|
|
6192
6398
|
exports.uniqueArrayMerge = uniqueArrayMerge;
|
|
6399
|
+
exports.updateEntityInArray = updateEntityInArray;
|
|
6193
6400
|
//# sourceMappingURL=index.node.cjs.map
|