@stream-io/feeds-client 0.1.11 → 0.2.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/CHANGELOG.md +17 -0
- package/dist/index-react-bindings.browser.cjs +172 -124
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +172 -124
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +172 -124
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +172 -124
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +170 -122
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +170 -122
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.node.cjs +170 -122
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +170 -122
- package/dist/index.node.js.map +1 -1
- 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 +163 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- 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 +15 -0
- package/src/gen/models/index.ts +278 -29
- package/src/test-utils/response-generators.ts +10 -11
- package/src/utils/state-update-queue.ts +1 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -634,6 +634,7 @@ decoders.FeedResponse = (input) => {
|
|
|
634
634
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
635
635
|
created_by: { type: 'UserResponse', isSingle: true },
|
|
636
636
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
637
|
+
own_follows: { type: 'FollowResponse', isSingle: false },
|
|
637
638
|
};
|
|
638
639
|
return decode(typeMappings, input);
|
|
639
640
|
};
|
|
@@ -852,6 +853,13 @@ decoders.ModerationCustomActionEvent = (input) => {
|
|
|
852
853
|
};
|
|
853
854
|
return decode(typeMappings, input);
|
|
854
855
|
};
|
|
856
|
+
decoders.ModerationFlagResponse = (input) => {
|
|
857
|
+
const typeMappings = {
|
|
858
|
+
review_queue_item: { type: 'ReviewQueueItemResponse', isSingle: true },
|
|
859
|
+
user: { type: 'UserResponse', isSingle: true },
|
|
860
|
+
};
|
|
861
|
+
return decode(typeMappings, input);
|
|
862
|
+
};
|
|
855
863
|
decoders.ModerationFlaggedEvent = (input) => {
|
|
856
864
|
const typeMappings = {
|
|
857
865
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -888,6 +896,7 @@ decoders.NotificationFeedUpdatedEvent = (input) => {
|
|
|
888
896
|
};
|
|
889
897
|
decoders.NotificationStatusResponse = (input) => {
|
|
890
898
|
const typeMappings = {
|
|
899
|
+
last_read_at: { type: 'DatetimeType', isSingle: true },
|
|
891
900
|
last_seen_at: { type: 'DatetimeType', isSingle: true },
|
|
892
901
|
};
|
|
893
902
|
return decode(typeMappings, input);
|
|
@@ -1155,6 +1164,7 @@ decoders.ReviewQueueItemResponse = (input) => {
|
|
|
1155
1164
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1156
1165
|
actions: { type: 'ActionLogResponse', isSingle: false },
|
|
1157
1166
|
bans: { type: 'Ban', isSingle: false },
|
|
1167
|
+
flags: { type: 'ModerationFlagResponse', isSingle: false },
|
|
1158
1168
|
completed_at: { type: 'DatetimeType', isSingle: true },
|
|
1159
1169
|
reviewed_at: { type: 'DatetimeType', isSingle: true },
|
|
1160
1170
|
assigned_to: { type: 'UserResponse', isSingle: true },
|
|
@@ -1477,7 +1487,7 @@ class FeedsApi {
|
|
|
1477
1487
|
async addActivity(request) {
|
|
1478
1488
|
const body = {
|
|
1479
1489
|
type: request?.type,
|
|
1480
|
-
|
|
1490
|
+
feeds: request?.feeds,
|
|
1481
1491
|
expires_at: request?.expires_at,
|
|
1482
1492
|
id: request?.id,
|
|
1483
1493
|
parent_id: request?.parent_id,
|
|
@@ -1507,7 +1517,7 @@ class FeedsApi {
|
|
|
1507
1517
|
}
|
|
1508
1518
|
async deleteActivities(request) {
|
|
1509
1519
|
const body = {
|
|
1510
|
-
|
|
1520
|
+
ids: request?.ids,
|
|
1511
1521
|
hard_delete: request?.hard_delete,
|
|
1512
1522
|
};
|
|
1513
1523
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/delete', undefined, undefined, body, 'application/json');
|
|
@@ -1526,56 +1536,6 @@ class FeedsApi {
|
|
|
1526
1536
|
decoders.QueryActivitiesResponse?.(response.body);
|
|
1527
1537
|
return { ...response.body, metadata: response.metadata };
|
|
1528
1538
|
}
|
|
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
1539
|
async deleteBookmark(request) {
|
|
1580
1540
|
const queryParams = {
|
|
1581
1541
|
folder_id: request?.folder_id,
|
|
@@ -1614,6 +1574,21 @@ class FeedsApi {
|
|
|
1614
1574
|
decoders.AddBookmarkResponse?.(response.body);
|
|
1615
1575
|
return { ...response.body, metadata: response.metadata };
|
|
1616
1576
|
}
|
|
1577
|
+
async activityFeedback(request) {
|
|
1578
|
+
const pathParams = {
|
|
1579
|
+
activity_id: request?.activity_id,
|
|
1580
|
+
};
|
|
1581
|
+
const body = {
|
|
1582
|
+
hide: request?.hide,
|
|
1583
|
+
mute_user: request?.mute_user,
|
|
1584
|
+
reason: request?.reason,
|
|
1585
|
+
report: request?.report,
|
|
1586
|
+
show_less: request?.show_less,
|
|
1587
|
+
};
|
|
1588
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/{activity_id}/feedback', pathParams, undefined, body, 'application/json');
|
|
1589
|
+
decoders.ActivityFeedbackResponse?.(response.body);
|
|
1590
|
+
return { ...response.body, metadata: response.metadata };
|
|
1591
|
+
}
|
|
1617
1592
|
async castPollVote(request) {
|
|
1618
1593
|
const pathParams = {
|
|
1619
1594
|
activity_id: request?.activity_id,
|
|
@@ -1676,6 +1651,56 @@ class FeedsApi {
|
|
|
1676
1651
|
decoders.DeleteActivityReactionResponse?.(response.body);
|
|
1677
1652
|
return { ...response.body, metadata: response.metadata };
|
|
1678
1653
|
}
|
|
1654
|
+
async deleteActivity(request) {
|
|
1655
|
+
const queryParams = {
|
|
1656
|
+
hard_delete: request?.hard_delete,
|
|
1657
|
+
};
|
|
1658
|
+
const pathParams = {
|
|
1659
|
+
id: request?.id,
|
|
1660
|
+
};
|
|
1661
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{id}', pathParams, queryParams);
|
|
1662
|
+
decoders.DeleteActivityResponse?.(response.body);
|
|
1663
|
+
return { ...response.body, metadata: response.metadata };
|
|
1664
|
+
}
|
|
1665
|
+
async getActivity(request) {
|
|
1666
|
+
const pathParams = {
|
|
1667
|
+
id: request?.id,
|
|
1668
|
+
};
|
|
1669
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{id}', pathParams, undefined);
|
|
1670
|
+
decoders.GetActivityResponse?.(response.body);
|
|
1671
|
+
return { ...response.body, metadata: response.metadata };
|
|
1672
|
+
}
|
|
1673
|
+
async updateActivityPartial(request) {
|
|
1674
|
+
const pathParams = {
|
|
1675
|
+
id: request?.id,
|
|
1676
|
+
};
|
|
1677
|
+
const body = {
|
|
1678
|
+
unset: request?.unset,
|
|
1679
|
+
set: request?.set,
|
|
1680
|
+
};
|
|
1681
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1682
|
+
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1683
|
+
return { ...response.body, metadata: response.metadata };
|
|
1684
|
+
}
|
|
1685
|
+
async updateActivity(request) {
|
|
1686
|
+
const pathParams = {
|
|
1687
|
+
id: request?.id,
|
|
1688
|
+
};
|
|
1689
|
+
const body = {
|
|
1690
|
+
expires_at: request?.expires_at,
|
|
1691
|
+
poll_id: request?.poll_id,
|
|
1692
|
+
text: request?.text,
|
|
1693
|
+
visibility: request?.visibility,
|
|
1694
|
+
attachments: request?.attachments,
|
|
1695
|
+
filter_tags: request?.filter_tags,
|
|
1696
|
+
interest_tags: request?.interest_tags,
|
|
1697
|
+
custom: request?.custom,
|
|
1698
|
+
location: request?.location,
|
|
1699
|
+
};
|
|
1700
|
+
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1701
|
+
decoders.UpdateActivityResponse?.(response.body);
|
|
1702
|
+
return { ...response.body, metadata: response.metadata };
|
|
1703
|
+
}
|
|
1679
1704
|
async queryBookmarkFolders(request) {
|
|
1680
1705
|
const body = {
|
|
1681
1706
|
limit: request?.limit,
|
|
@@ -1771,49 +1796,52 @@ class FeedsApi {
|
|
|
1771
1796
|
return { ...response.body, metadata: response.metadata };
|
|
1772
1797
|
}
|
|
1773
1798
|
async deleteComment(request) {
|
|
1799
|
+
const queryParams = {
|
|
1800
|
+
hard_delete: request?.hard_delete,
|
|
1801
|
+
};
|
|
1774
1802
|
const pathParams = {
|
|
1775
|
-
|
|
1803
|
+
id: request?.id,
|
|
1776
1804
|
};
|
|
1777
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1805
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}', pathParams, queryParams);
|
|
1778
1806
|
decoders.DeleteCommentResponse?.(response.body);
|
|
1779
1807
|
return { ...response.body, metadata: response.metadata };
|
|
1780
1808
|
}
|
|
1781
1809
|
async getComment(request) {
|
|
1782
1810
|
const pathParams = {
|
|
1783
|
-
|
|
1811
|
+
id: request?.id,
|
|
1784
1812
|
};
|
|
1785
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1813
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}', pathParams, undefined);
|
|
1786
1814
|
decoders.GetCommentResponse?.(response.body);
|
|
1787
1815
|
return { ...response.body, metadata: response.metadata };
|
|
1788
1816
|
}
|
|
1789
1817
|
async updateComment(request) {
|
|
1790
1818
|
const pathParams = {
|
|
1791
|
-
|
|
1819
|
+
id: request?.id,
|
|
1792
1820
|
};
|
|
1793
1821
|
const body = {
|
|
1794
1822
|
comment: request?.comment,
|
|
1795
1823
|
custom: request?.custom,
|
|
1796
1824
|
};
|
|
1797
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{
|
|
1825
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{id}', pathParams, undefined, body, 'application/json');
|
|
1798
1826
|
decoders.UpdateCommentResponse?.(response.body);
|
|
1799
1827
|
return { ...response.body, metadata: response.metadata };
|
|
1800
1828
|
}
|
|
1801
1829
|
async addCommentReaction(request) {
|
|
1802
1830
|
const pathParams = {
|
|
1803
|
-
|
|
1831
|
+
id: request?.id,
|
|
1804
1832
|
};
|
|
1805
1833
|
const body = {
|
|
1806
1834
|
type: request?.type,
|
|
1807
1835
|
create_notification_activity: request?.create_notification_activity,
|
|
1808
1836
|
custom: request?.custom,
|
|
1809
1837
|
};
|
|
1810
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1838
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions', pathParams, undefined, body, 'application/json');
|
|
1811
1839
|
decoders.AddCommentReactionResponse?.(response.body);
|
|
1812
1840
|
return { ...response.body, metadata: response.metadata };
|
|
1813
1841
|
}
|
|
1814
1842
|
async queryCommentReactions(request) {
|
|
1815
1843
|
const pathParams = {
|
|
1816
|
-
|
|
1844
|
+
id: request?.id,
|
|
1817
1845
|
};
|
|
1818
1846
|
const body = {
|
|
1819
1847
|
limit: request?.limit,
|
|
@@ -1822,16 +1850,16 @@ class FeedsApi {
|
|
|
1822
1850
|
sort: request?.sort,
|
|
1823
1851
|
filter: request?.filter,
|
|
1824
1852
|
};
|
|
1825
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1853
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions/query', pathParams, undefined, body, 'application/json');
|
|
1826
1854
|
decoders.QueryCommentReactionsResponse?.(response.body);
|
|
1827
1855
|
return { ...response.body, metadata: response.metadata };
|
|
1828
1856
|
}
|
|
1829
1857
|
async deleteCommentReaction(request) {
|
|
1830
1858
|
const pathParams = {
|
|
1831
|
-
|
|
1859
|
+
id: request?.id,
|
|
1832
1860
|
type: request?.type,
|
|
1833
1861
|
};
|
|
1834
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1862
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}/reactions/{type}', pathParams, undefined);
|
|
1835
1863
|
decoders.DeleteCommentReactionResponse?.(response.body);
|
|
1836
1864
|
return { ...response.body, metadata: response.metadata };
|
|
1837
1865
|
}
|
|
@@ -1845,9 +1873,9 @@ class FeedsApi {
|
|
|
1845
1873
|
next: request?.next,
|
|
1846
1874
|
};
|
|
1847
1875
|
const pathParams = {
|
|
1848
|
-
|
|
1876
|
+
id: request?.id,
|
|
1849
1877
|
};
|
|
1850
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1878
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}/replies', pathParams, queryParams);
|
|
1851
1879
|
decoders.GetCommentRepliesResponse?.(response.body);
|
|
1852
1880
|
return { ...response.body, metadata: response.metadata };
|
|
1853
1881
|
}
|
|
@@ -1896,7 +1924,6 @@ class FeedsApi {
|
|
|
1896
1924
|
feed_id: request?.feed_id,
|
|
1897
1925
|
};
|
|
1898
1926
|
const body = {
|
|
1899
|
-
created_by_id: request?.created_by_id,
|
|
1900
1927
|
custom: request?.custom,
|
|
1901
1928
|
};
|
|
1902
1929
|
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 +1939,7 @@ class FeedsApi {
|
|
|
1912
1939
|
mark_all_read: request?.mark_all_read,
|
|
1913
1940
|
mark_all_seen: request?.mark_all_seen,
|
|
1914
1941
|
mark_read: request?.mark_read,
|
|
1942
|
+
mark_seen: request?.mark_seen,
|
|
1915
1943
|
mark_watched: request?.mark_watched,
|
|
1916
1944
|
};
|
|
1917
1945
|
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 +2050,7 @@ class FeedsApi {
|
|
|
2022
2050
|
decoders.CreateFeedsBatchResponse?.(response.body);
|
|
2023
2051
|
return { ...response.body, metadata: response.metadata };
|
|
2024
2052
|
}
|
|
2025
|
-
async
|
|
2053
|
+
async _queryFeeds(request) {
|
|
2026
2054
|
const queryParams = {
|
|
2027
2055
|
connection_id: request?.connection_id,
|
|
2028
2056
|
};
|
|
@@ -2065,8 +2093,8 @@ class FeedsApi {
|
|
|
2065
2093
|
}
|
|
2066
2094
|
async acceptFollow(request) {
|
|
2067
2095
|
const body = {
|
|
2068
|
-
|
|
2069
|
-
|
|
2096
|
+
source: request?.source,
|
|
2097
|
+
target: request?.target,
|
|
2070
2098
|
follower_role: request?.follower_role,
|
|
2071
2099
|
};
|
|
2072
2100
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/accept', undefined, undefined, body, 'application/json');
|
|
@@ -2095,8 +2123,8 @@ class FeedsApi {
|
|
|
2095
2123
|
}
|
|
2096
2124
|
async rejectFollow(request) {
|
|
2097
2125
|
const body = {
|
|
2098
|
-
|
|
2099
|
-
|
|
2126
|
+
source: request?.source,
|
|
2127
|
+
target: request?.target,
|
|
2100
2128
|
};
|
|
2101
2129
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/reject', undefined, undefined, body, 'application/json');
|
|
2102
2130
|
decoders.RejectFollowResponse?.(response.body);
|
|
@@ -4264,7 +4292,7 @@ const shouldUpdateState = ({ stateUpdateQueueId, stateUpdateQueue, watch, }) =>
|
|
|
4264
4292
|
};
|
|
4265
4293
|
function getStateUpdateQueueId(data, prefix) {
|
|
4266
4294
|
if (isFollowResponse(data)) {
|
|
4267
|
-
const toJoin = [data.source_feed.
|
|
4295
|
+
const toJoin = [data.source_feed.feed, data.target_feed.feed];
|
|
4268
4296
|
if (prefix) {
|
|
4269
4297
|
toJoin.unshift(prefix);
|
|
4270
4298
|
}
|
|
@@ -4282,7 +4310,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4282
4310
|
}
|
|
4283
4311
|
let newState = { ...currentState };
|
|
4284
4312
|
// this feed followed someone
|
|
4285
|
-
if (follow.source_feed.
|
|
4313
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4286
4314
|
newState = {
|
|
4287
4315
|
...newState,
|
|
4288
4316
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4295,7 +4323,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4295
4323
|
}
|
|
4296
4324
|
else if (
|
|
4297
4325
|
// someone followed this feed
|
|
4298
|
-
follow.target_feed.
|
|
4326
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4299
4327
|
const source = follow.source_feed;
|
|
4300
4328
|
newState = {
|
|
4301
4329
|
...newState,
|
|
@@ -4324,7 +4352,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4324
4352
|
return;
|
|
4325
4353
|
}
|
|
4326
4354
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4327
|
-
const result = updateStateFollowCreated(follow, this.currentState, this.
|
|
4355
|
+
const result = updateStateFollowCreated(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4328
4356
|
if (result.changed) {
|
|
4329
4357
|
this.state.next(result.data);
|
|
4330
4358
|
}
|
|
@@ -4333,7 +4361,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4333
4361
|
const updateStateFollowDeleted = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4334
4362
|
let newState = { ...currentState };
|
|
4335
4363
|
// this feed unfollowed someone
|
|
4336
|
-
if (follow.source_feed.
|
|
4364
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4337
4365
|
newState = {
|
|
4338
4366
|
...newState,
|
|
4339
4367
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4341,12 +4369,12 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4341
4369
|
};
|
|
4342
4370
|
// Only update if following array already exists
|
|
4343
4371
|
if (currentState.following !== undefined) {
|
|
4344
|
-
newState.following = currentState.following.filter((followItem) => followItem.target_feed.
|
|
4372
|
+
newState.following = currentState.following.filter((followItem) => followItem.target_feed.feed !== follow.target_feed.feed);
|
|
4345
4373
|
}
|
|
4346
4374
|
}
|
|
4347
4375
|
else if (
|
|
4348
4376
|
// someone unfollowed this feed
|
|
4349
|
-
follow.target_feed.
|
|
4377
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4350
4378
|
const source = follow.source_feed;
|
|
4351
4379
|
newState = {
|
|
4352
4380
|
...newState,
|
|
@@ -4355,11 +4383,11 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4355
4383
|
};
|
|
4356
4384
|
if (source.created_by.id === connectedUserId &&
|
|
4357
4385
|
currentState.own_follows !== undefined) {
|
|
4358
|
-
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.
|
|
4386
|
+
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4359
4387
|
}
|
|
4360
4388
|
// Only update if followers array already exists
|
|
4361
4389
|
if (currentState.followers !== undefined) {
|
|
4362
|
-
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.
|
|
4390
|
+
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4363
4391
|
}
|
|
4364
4392
|
}
|
|
4365
4393
|
return { changed: true, data: newState };
|
|
@@ -4374,7 +4402,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4374
4402
|
return;
|
|
4375
4403
|
}
|
|
4376
4404
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4377
|
-
const result = updateStateFollowDeleted(follow, this.currentState, this.
|
|
4405
|
+
const result = updateStateFollowDeleted(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4378
4406
|
{
|
|
4379
4407
|
this.state.next(result.data);
|
|
4380
4408
|
}
|
|
@@ -4383,7 +4411,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4383
4411
|
function handleFollowUpdated(eventOrResponse) {
|
|
4384
4412
|
const follow = eventOrResponse.follow;
|
|
4385
4413
|
const connectedUserId = this.client.state.getLatestValue().connected_user?.id;
|
|
4386
|
-
const currentFeedId = this.
|
|
4414
|
+
const currentFeedId = this.feed;
|
|
4387
4415
|
if (!shouldUpdateState({
|
|
4388
4416
|
stateUpdateQueueId: getStateUpdateQueueId(follow, 'updated'),
|
|
4389
4417
|
stateUpdateQueue: this.stateUpdateQueue,
|
|
@@ -4394,13 +4422,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4394
4422
|
this.state.next((currentState) => {
|
|
4395
4423
|
let newState;
|
|
4396
4424
|
// this feed followed someone
|
|
4397
|
-
if (follow.source_feed.
|
|
4425
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4398
4426
|
newState ?? (newState = {
|
|
4399
4427
|
...currentState,
|
|
4400
4428
|
// Update FeedResponse fields, that has the new follower/following count
|
|
4401
4429
|
...follow.source_feed,
|
|
4402
4430
|
});
|
|
4403
|
-
const index = currentState.following?.findIndex((f) => f.target_feed.
|
|
4431
|
+
const index = currentState.following?.findIndex((f) => f.target_feed.feed === follow.target_feed.feed) ?? -1;
|
|
4404
4432
|
if (index >= 0) {
|
|
4405
4433
|
newState.following = [...newState.following];
|
|
4406
4434
|
newState.following[index] = follow;
|
|
@@ -4408,7 +4436,7 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4408
4436
|
}
|
|
4409
4437
|
else if (
|
|
4410
4438
|
// someone followed this feed
|
|
4411
|
-
follow.target_feed.
|
|
4439
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4412
4440
|
const source = follow.source_feed;
|
|
4413
4441
|
newState ?? (newState = {
|
|
4414
4442
|
...currentState,
|
|
@@ -4417,13 +4445,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4417
4445
|
});
|
|
4418
4446
|
if (source.created_by.id === connectedUserId &&
|
|
4419
4447
|
currentState.own_follows) {
|
|
4420
|
-
const index = currentState.own_follows.findIndex((f) => f.source_feed.
|
|
4448
|
+
const index = currentState.own_follows.findIndex((f) => f.source_feed.feed === follow.source_feed.feed);
|
|
4421
4449
|
if (index >= 0) {
|
|
4422
4450
|
newState.own_follows = [...currentState.own_follows];
|
|
4423
4451
|
newState.own_follows[index] = follow;
|
|
4424
4452
|
}
|
|
4425
4453
|
}
|
|
4426
|
-
const index = currentState.followers?.findIndex((f) => f.source_feed.
|
|
4454
|
+
const index = currentState.followers?.findIndex((f) => f.source_feed.feed === follow.source_feed.feed) ?? -1;
|
|
4427
4455
|
if (index >= 0) {
|
|
4428
4456
|
newState.followers = [...newState.followers];
|
|
4429
4457
|
newState.followers[index] = follow;
|
|
@@ -4911,6 +4939,14 @@ function handleNotificationFeedUpdated(event) {
|
|
|
4911
4939
|
// TODO: handle notification feed updates
|
|
4912
4940
|
}
|
|
4913
4941
|
|
|
4942
|
+
function handleWatchStarted() {
|
|
4943
|
+
this.state.partialNext({ watch: true });
|
|
4944
|
+
}
|
|
4945
|
+
|
|
4946
|
+
function handleWatchStopped() {
|
|
4947
|
+
this.state.partialNext({ watch: false });
|
|
4948
|
+
}
|
|
4949
|
+
|
|
4914
4950
|
class Feed extends FeedApi {
|
|
4915
4951
|
constructor(client, groupId, id, data, watch = false) {
|
|
4916
4952
|
super(client, groupId, id);
|
|
@@ -4971,7 +5007,7 @@ class Feed extends FeedApi {
|
|
|
4971
5007
|
this.on = this.eventDispatcher.on;
|
|
4972
5008
|
this.off = this.eventDispatcher.off;
|
|
4973
5009
|
this.state = new StateStore({
|
|
4974
|
-
|
|
5010
|
+
feed: `${groupId}:${id}`,
|
|
4975
5011
|
group_id: groupId,
|
|
4976
5012
|
id,
|
|
4977
5013
|
...(data ?? {}),
|
|
@@ -4982,7 +5018,7 @@ class Feed extends FeedApi {
|
|
|
4982
5018
|
});
|
|
4983
5019
|
this.client = client;
|
|
4984
5020
|
}
|
|
4985
|
-
get
|
|
5021
|
+
get feed() {
|
|
4986
5022
|
return `${this.group}:${this.id}`;
|
|
4987
5023
|
}
|
|
4988
5024
|
get currentState() {
|
|
@@ -5057,22 +5093,6 @@ class Feed extends FeedApi {
|
|
|
5057
5093
|
});
|
|
5058
5094
|
}
|
|
5059
5095
|
}
|
|
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
5096
|
/**
|
|
5077
5097
|
* Returns index of the provided comment object.
|
|
5078
5098
|
*/
|
|
@@ -5232,7 +5252,7 @@ class Feed extends FeedApi {
|
|
|
5232
5252
|
entityId: comment.id,
|
|
5233
5253
|
base: () => this.client.getCommentReplies({
|
|
5234
5254
|
...request,
|
|
5235
|
-
|
|
5255
|
+
id: comment.id,
|
|
5236
5256
|
// use known sort first (prevents broken pagination)
|
|
5237
5257
|
sort,
|
|
5238
5258
|
next: currentNextCursor,
|
|
@@ -5272,7 +5292,7 @@ class Feed extends FeedApi {
|
|
|
5272
5292
|
...currentState,
|
|
5273
5293
|
[type]: currentState[type] === undefined
|
|
5274
5294
|
? follows
|
|
5275
|
-
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.
|
|
5295
|
+
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.feed}-${follow.target_feed.feed}`),
|
|
5276
5296
|
[paginationKey]: {
|
|
5277
5297
|
...currentState[paginationKey],
|
|
5278
5298
|
next: newNextCursor,
|
|
@@ -5365,7 +5385,7 @@ class Feed extends FeedApi {
|
|
|
5365
5385
|
*/
|
|
5366
5386
|
async queryFollowers(request) {
|
|
5367
5387
|
const filter = {
|
|
5368
|
-
target_feed: this.
|
|
5388
|
+
target_feed: this.feed,
|
|
5369
5389
|
};
|
|
5370
5390
|
const response = await this.client.queryFollows({
|
|
5371
5391
|
filter,
|
|
@@ -5380,7 +5400,7 @@ class Feed extends FeedApi {
|
|
|
5380
5400
|
*/
|
|
5381
5401
|
async queryFollowing(request) {
|
|
5382
5402
|
const filter = {
|
|
5383
|
-
source_feed: this.
|
|
5403
|
+
source_feed: this.feed,
|
|
5384
5404
|
};
|
|
5385
5405
|
const response = await this.client.queryFollows({
|
|
5386
5406
|
filter,
|
|
@@ -5389,18 +5409,18 @@ class Feed extends FeedApi {
|
|
|
5389
5409
|
return response;
|
|
5390
5410
|
}
|
|
5391
5411
|
async follow(feedOrFid, options) {
|
|
5392
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5412
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5393
5413
|
const response = await this.client.follow({
|
|
5394
5414
|
...options,
|
|
5395
|
-
source: this.
|
|
5415
|
+
source: this.feed,
|
|
5396
5416
|
target: fid,
|
|
5397
5417
|
});
|
|
5398
5418
|
return response;
|
|
5399
5419
|
}
|
|
5400
5420
|
async unfollow(feedOrFid) {
|
|
5401
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5421
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5402
5422
|
const response = await this.client.unfollow({
|
|
5403
|
-
source: this.
|
|
5423
|
+
source: this.feed,
|
|
5404
5424
|
target: fid,
|
|
5405
5425
|
});
|
|
5406
5426
|
return response;
|
|
@@ -5424,7 +5444,7 @@ class Feed extends FeedApi {
|
|
|
5424
5444
|
addActivity(request) {
|
|
5425
5445
|
return this.feedsApi.addActivity({
|
|
5426
5446
|
...request,
|
|
5427
|
-
|
|
5447
|
+
feeds: [this.feed],
|
|
5428
5448
|
});
|
|
5429
5449
|
}
|
|
5430
5450
|
handleWSEvent(event) {
|
|
@@ -5442,6 +5462,24 @@ class Feed extends FeedApi {
|
|
|
5442
5462
|
}
|
|
5443
5463
|
Feed.noop = () => { };
|
|
5444
5464
|
|
|
5465
|
+
function handleUserUpdated(event) {
|
|
5466
|
+
this.state.next((currentState) => {
|
|
5467
|
+
let newState;
|
|
5468
|
+
const { connected_user } = currentState;
|
|
5469
|
+
if (connected_user && connected_user.id === event.user.id) {
|
|
5470
|
+
newState ?? (newState = {
|
|
5471
|
+
...currentState,
|
|
5472
|
+
});
|
|
5473
|
+
newState.connected_user = {
|
|
5474
|
+
...connected_user,
|
|
5475
|
+
...event.user,
|
|
5476
|
+
};
|
|
5477
|
+
}
|
|
5478
|
+
// TODO: update other users in user map (if/once applicable)
|
|
5479
|
+
return newState ?? currentState;
|
|
5480
|
+
});
|
|
5481
|
+
}
|
|
5482
|
+
|
|
5445
5483
|
class FeedsClient extends FeedsApi {
|
|
5446
5484
|
constructor(apiKey, options) {
|
|
5447
5485
|
const tokenManager = new TokenManager();
|
|
@@ -5549,7 +5587,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5549
5587
|
if (this.activeFeeds[fid]) {
|
|
5550
5588
|
const feed = this.activeFeeds[fid];
|
|
5551
5589
|
if (watch && !feed.currentState.watch) {
|
|
5552
|
-
|
|
5590
|
+
handleWatchStarted.bind(feed)();
|
|
5553
5591
|
}
|
|
5554
5592
|
return feed;
|
|
5555
5593
|
}
|
|
@@ -5585,7 +5623,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5585
5623
|
}
|
|
5586
5624
|
else {
|
|
5587
5625
|
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
5588
|
-
|
|
5626
|
+
handleWatchStopped.bind(activeFeed)();
|
|
5589
5627
|
}
|
|
5590
5628
|
}
|
|
5591
5629
|
break;
|
|
@@ -5665,6 +5703,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5665
5703
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
5666
5704
|
break;
|
|
5667
5705
|
}
|
|
5706
|
+
case 'user.updated': {
|
|
5707
|
+
handleUserUpdated.call(this, event);
|
|
5708
|
+
break;
|
|
5709
|
+
}
|
|
5668
5710
|
default: {
|
|
5669
5711
|
feed?.handleWSEvent(event);
|
|
5670
5712
|
}
|
|
@@ -5690,7 +5732,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5690
5732
|
}
|
|
5691
5733
|
}
|
|
5692
5734
|
async queryFeeds(request) {
|
|
5693
|
-
const response = await this.
|
|
5735
|
+
const response = await this._queryFeeds(request);
|
|
5694
5736
|
const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
|
|
5695
5737
|
return {
|
|
5696
5738
|
feeds,
|
|
@@ -5702,7 +5744,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5702
5744
|
}
|
|
5703
5745
|
async updateFollow(request) {
|
|
5704
5746
|
const response = await super.updateFollow(request);
|
|
5705
|
-
[
|
|
5747
|
+
[
|
|
5748
|
+
response.follow.source_feed.feed,
|
|
5749
|
+
response.follow.target_feed.feed,
|
|
5750
|
+
].forEach((fid) => {
|
|
5706
5751
|
const feed = this.activeFeeds[fid];
|
|
5707
5752
|
if (feed) {
|
|
5708
5753
|
handleFollowUpdated.bind(feed)(response);
|
|
@@ -5713,7 +5758,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5713
5758
|
// For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
|
|
5714
5759
|
async follow(request) {
|
|
5715
5760
|
const response = await super.follow(request);
|
|
5716
|
-
[
|
|
5761
|
+
[
|
|
5762
|
+
response.follow.source_feed.feed,
|
|
5763
|
+
response.follow.target_feed.feed,
|
|
5764
|
+
].forEach((fid) => {
|
|
5717
5765
|
const feed = this.activeFeeds[fid];
|
|
5718
5766
|
if (feed) {
|
|
5719
5767
|
handleFollowCreated.bind(feed)(response);
|
|
@@ -5724,7 +5772,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5724
5772
|
async followBatch(request) {
|
|
5725
5773
|
const response = await super.followBatch(request);
|
|
5726
5774
|
response.follows.forEach((follow) => {
|
|
5727
|
-
const feed = this.activeFeeds[follow.source_feed.
|
|
5775
|
+
const feed = this.activeFeeds[follow.source_feed.feed];
|
|
5728
5776
|
if (feed) {
|
|
5729
5777
|
handleFollowCreated.bind(feed)({ follow });
|
|
5730
5778
|
}
|
|
@@ -5749,7 +5797,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5749
5797
|
});
|
|
5750
5798
|
const feed = this.activeFeeds[`${request.feed_group_id}:${request.feed_id}`];
|
|
5751
5799
|
if (feed) {
|
|
5752
|
-
|
|
5800
|
+
handleWatchStopped.bind(feed)();
|
|
5753
5801
|
}
|
|
5754
5802
|
return response;
|
|
5755
5803
|
}
|