@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.js
CHANGED
|
@@ -632,6 +632,7 @@ decoders.FeedResponse = (input) => {
|
|
|
632
632
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
633
633
|
created_by: { type: 'UserResponse', isSingle: true },
|
|
634
634
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
635
|
+
own_follows: { type: 'FollowResponse', isSingle: false },
|
|
635
636
|
};
|
|
636
637
|
return decode(typeMappings, input);
|
|
637
638
|
};
|
|
@@ -850,6 +851,13 @@ decoders.ModerationCustomActionEvent = (input) => {
|
|
|
850
851
|
};
|
|
851
852
|
return decode(typeMappings, input);
|
|
852
853
|
};
|
|
854
|
+
decoders.ModerationFlagResponse = (input) => {
|
|
855
|
+
const typeMappings = {
|
|
856
|
+
review_queue_item: { type: 'ReviewQueueItemResponse', isSingle: true },
|
|
857
|
+
user: { type: 'UserResponse', isSingle: true },
|
|
858
|
+
};
|
|
859
|
+
return decode(typeMappings, input);
|
|
860
|
+
};
|
|
853
861
|
decoders.ModerationFlaggedEvent = (input) => {
|
|
854
862
|
const typeMappings = {
|
|
855
863
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -886,6 +894,7 @@ decoders.NotificationFeedUpdatedEvent = (input) => {
|
|
|
886
894
|
};
|
|
887
895
|
decoders.NotificationStatusResponse = (input) => {
|
|
888
896
|
const typeMappings = {
|
|
897
|
+
last_read_at: { type: 'DatetimeType', isSingle: true },
|
|
889
898
|
last_seen_at: { type: 'DatetimeType', isSingle: true },
|
|
890
899
|
};
|
|
891
900
|
return decode(typeMappings, input);
|
|
@@ -1153,6 +1162,7 @@ decoders.ReviewQueueItemResponse = (input) => {
|
|
|
1153
1162
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1154
1163
|
actions: { type: 'ActionLogResponse', isSingle: false },
|
|
1155
1164
|
bans: { type: 'Ban', isSingle: false },
|
|
1165
|
+
flags: { type: 'ModerationFlagResponse', isSingle: false },
|
|
1156
1166
|
completed_at: { type: 'DatetimeType', isSingle: true },
|
|
1157
1167
|
reviewed_at: { type: 'DatetimeType', isSingle: true },
|
|
1158
1168
|
assigned_to: { type: 'UserResponse', isSingle: true },
|
|
@@ -1475,7 +1485,7 @@ class FeedsApi {
|
|
|
1475
1485
|
async addActivity(request) {
|
|
1476
1486
|
const body = {
|
|
1477
1487
|
type: request?.type,
|
|
1478
|
-
|
|
1488
|
+
feeds: request?.feeds,
|
|
1479
1489
|
expires_at: request?.expires_at,
|
|
1480
1490
|
id: request?.id,
|
|
1481
1491
|
parent_id: request?.parent_id,
|
|
@@ -1505,7 +1515,7 @@ class FeedsApi {
|
|
|
1505
1515
|
}
|
|
1506
1516
|
async deleteActivities(request) {
|
|
1507
1517
|
const body = {
|
|
1508
|
-
|
|
1518
|
+
ids: request?.ids,
|
|
1509
1519
|
hard_delete: request?.hard_delete,
|
|
1510
1520
|
};
|
|
1511
1521
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/delete', undefined, undefined, body, 'application/json');
|
|
@@ -1524,56 +1534,6 @@ class FeedsApi {
|
|
|
1524
1534
|
decoders.QueryActivitiesResponse?.(response.body);
|
|
1525
1535
|
return { ...response.body, metadata: response.metadata };
|
|
1526
1536
|
}
|
|
1527
|
-
async deleteActivity(request) {
|
|
1528
|
-
const queryParams = {
|
|
1529
|
-
hard_delete: request?.hard_delete,
|
|
1530
|
-
};
|
|
1531
|
-
const pathParams = {
|
|
1532
|
-
activity_id: request?.activity_id,
|
|
1533
|
-
};
|
|
1534
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{activity_id}', pathParams, queryParams);
|
|
1535
|
-
decoders.DeleteActivityResponse?.(response.body);
|
|
1536
|
-
return { ...response.body, metadata: response.metadata };
|
|
1537
|
-
}
|
|
1538
|
-
async getActivity(request) {
|
|
1539
|
-
const pathParams = {
|
|
1540
|
-
activity_id: request?.activity_id,
|
|
1541
|
-
};
|
|
1542
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined);
|
|
1543
|
-
decoders.GetActivityResponse?.(response.body);
|
|
1544
|
-
return { ...response.body, metadata: response.metadata };
|
|
1545
|
-
}
|
|
1546
|
-
async updateActivityPartial(request) {
|
|
1547
|
-
const pathParams = {
|
|
1548
|
-
activity_id: request?.activity_id,
|
|
1549
|
-
};
|
|
1550
|
-
const body = {
|
|
1551
|
-
unset: request?.unset,
|
|
1552
|
-
set: request?.set,
|
|
1553
|
-
};
|
|
1554
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1555
|
-
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1556
|
-
return { ...response.body, metadata: response.metadata };
|
|
1557
|
-
}
|
|
1558
|
-
async updateActivity(request) {
|
|
1559
|
-
const pathParams = {
|
|
1560
|
-
activity_id: request?.activity_id,
|
|
1561
|
-
};
|
|
1562
|
-
const body = {
|
|
1563
|
-
expires_at: request?.expires_at,
|
|
1564
|
-
poll_id: request?.poll_id,
|
|
1565
|
-
text: request?.text,
|
|
1566
|
-
visibility: request?.visibility,
|
|
1567
|
-
attachments: request?.attachments,
|
|
1568
|
-
filter_tags: request?.filter_tags,
|
|
1569
|
-
interest_tags: request?.interest_tags,
|
|
1570
|
-
custom: request?.custom,
|
|
1571
|
-
location: request?.location,
|
|
1572
|
-
};
|
|
1573
|
-
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1574
|
-
decoders.UpdateActivityResponse?.(response.body);
|
|
1575
|
-
return { ...response.body, metadata: response.metadata };
|
|
1576
|
-
}
|
|
1577
1537
|
async deleteBookmark(request) {
|
|
1578
1538
|
const queryParams = {
|
|
1579
1539
|
folder_id: request?.folder_id,
|
|
@@ -1612,6 +1572,21 @@ class FeedsApi {
|
|
|
1612
1572
|
decoders.AddBookmarkResponse?.(response.body);
|
|
1613
1573
|
return { ...response.body, metadata: response.metadata };
|
|
1614
1574
|
}
|
|
1575
|
+
async activityFeedback(request) {
|
|
1576
|
+
const pathParams = {
|
|
1577
|
+
activity_id: request?.activity_id,
|
|
1578
|
+
};
|
|
1579
|
+
const body = {
|
|
1580
|
+
hide: request?.hide,
|
|
1581
|
+
mute_user: request?.mute_user,
|
|
1582
|
+
reason: request?.reason,
|
|
1583
|
+
report: request?.report,
|
|
1584
|
+
show_less: request?.show_less,
|
|
1585
|
+
};
|
|
1586
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/{activity_id}/feedback', pathParams, undefined, body, 'application/json');
|
|
1587
|
+
decoders.ActivityFeedbackResponse?.(response.body);
|
|
1588
|
+
return { ...response.body, metadata: response.metadata };
|
|
1589
|
+
}
|
|
1615
1590
|
async castPollVote(request) {
|
|
1616
1591
|
const pathParams = {
|
|
1617
1592
|
activity_id: request?.activity_id,
|
|
@@ -1674,6 +1649,56 @@ class FeedsApi {
|
|
|
1674
1649
|
decoders.DeleteActivityReactionResponse?.(response.body);
|
|
1675
1650
|
return { ...response.body, metadata: response.metadata };
|
|
1676
1651
|
}
|
|
1652
|
+
async deleteActivity(request) {
|
|
1653
|
+
const queryParams = {
|
|
1654
|
+
hard_delete: request?.hard_delete,
|
|
1655
|
+
};
|
|
1656
|
+
const pathParams = {
|
|
1657
|
+
id: request?.id,
|
|
1658
|
+
};
|
|
1659
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{id}', pathParams, queryParams);
|
|
1660
|
+
decoders.DeleteActivityResponse?.(response.body);
|
|
1661
|
+
return { ...response.body, metadata: response.metadata };
|
|
1662
|
+
}
|
|
1663
|
+
async getActivity(request) {
|
|
1664
|
+
const pathParams = {
|
|
1665
|
+
id: request?.id,
|
|
1666
|
+
};
|
|
1667
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{id}', pathParams, undefined);
|
|
1668
|
+
decoders.GetActivityResponse?.(response.body);
|
|
1669
|
+
return { ...response.body, metadata: response.metadata };
|
|
1670
|
+
}
|
|
1671
|
+
async updateActivityPartial(request) {
|
|
1672
|
+
const pathParams = {
|
|
1673
|
+
id: request?.id,
|
|
1674
|
+
};
|
|
1675
|
+
const body = {
|
|
1676
|
+
unset: request?.unset,
|
|
1677
|
+
set: request?.set,
|
|
1678
|
+
};
|
|
1679
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1680
|
+
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1681
|
+
return { ...response.body, metadata: response.metadata };
|
|
1682
|
+
}
|
|
1683
|
+
async updateActivity(request) {
|
|
1684
|
+
const pathParams = {
|
|
1685
|
+
id: request?.id,
|
|
1686
|
+
};
|
|
1687
|
+
const body = {
|
|
1688
|
+
expires_at: request?.expires_at,
|
|
1689
|
+
poll_id: request?.poll_id,
|
|
1690
|
+
text: request?.text,
|
|
1691
|
+
visibility: request?.visibility,
|
|
1692
|
+
attachments: request?.attachments,
|
|
1693
|
+
filter_tags: request?.filter_tags,
|
|
1694
|
+
interest_tags: request?.interest_tags,
|
|
1695
|
+
custom: request?.custom,
|
|
1696
|
+
location: request?.location,
|
|
1697
|
+
};
|
|
1698
|
+
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1699
|
+
decoders.UpdateActivityResponse?.(response.body);
|
|
1700
|
+
return { ...response.body, metadata: response.metadata };
|
|
1701
|
+
}
|
|
1677
1702
|
async queryBookmarkFolders(request) {
|
|
1678
1703
|
const body = {
|
|
1679
1704
|
limit: request?.limit,
|
|
@@ -1769,49 +1794,52 @@ class FeedsApi {
|
|
|
1769
1794
|
return { ...response.body, metadata: response.metadata };
|
|
1770
1795
|
}
|
|
1771
1796
|
async deleteComment(request) {
|
|
1797
|
+
const queryParams = {
|
|
1798
|
+
hard_delete: request?.hard_delete,
|
|
1799
|
+
};
|
|
1772
1800
|
const pathParams = {
|
|
1773
|
-
|
|
1801
|
+
id: request?.id,
|
|
1774
1802
|
};
|
|
1775
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1803
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}', pathParams, queryParams);
|
|
1776
1804
|
decoders.DeleteCommentResponse?.(response.body);
|
|
1777
1805
|
return { ...response.body, metadata: response.metadata };
|
|
1778
1806
|
}
|
|
1779
1807
|
async getComment(request) {
|
|
1780
1808
|
const pathParams = {
|
|
1781
|
-
|
|
1809
|
+
id: request?.id,
|
|
1782
1810
|
};
|
|
1783
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1811
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}', pathParams, undefined);
|
|
1784
1812
|
decoders.GetCommentResponse?.(response.body);
|
|
1785
1813
|
return { ...response.body, metadata: response.metadata };
|
|
1786
1814
|
}
|
|
1787
1815
|
async updateComment(request) {
|
|
1788
1816
|
const pathParams = {
|
|
1789
|
-
|
|
1817
|
+
id: request?.id,
|
|
1790
1818
|
};
|
|
1791
1819
|
const body = {
|
|
1792
1820
|
comment: request?.comment,
|
|
1793
1821
|
custom: request?.custom,
|
|
1794
1822
|
};
|
|
1795
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{
|
|
1823
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{id}', pathParams, undefined, body, 'application/json');
|
|
1796
1824
|
decoders.UpdateCommentResponse?.(response.body);
|
|
1797
1825
|
return { ...response.body, metadata: response.metadata };
|
|
1798
1826
|
}
|
|
1799
1827
|
async addCommentReaction(request) {
|
|
1800
1828
|
const pathParams = {
|
|
1801
|
-
|
|
1829
|
+
id: request?.id,
|
|
1802
1830
|
};
|
|
1803
1831
|
const body = {
|
|
1804
1832
|
type: request?.type,
|
|
1805
1833
|
create_notification_activity: request?.create_notification_activity,
|
|
1806
1834
|
custom: request?.custom,
|
|
1807
1835
|
};
|
|
1808
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1836
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions', pathParams, undefined, body, 'application/json');
|
|
1809
1837
|
decoders.AddCommentReactionResponse?.(response.body);
|
|
1810
1838
|
return { ...response.body, metadata: response.metadata };
|
|
1811
1839
|
}
|
|
1812
1840
|
async queryCommentReactions(request) {
|
|
1813
1841
|
const pathParams = {
|
|
1814
|
-
|
|
1842
|
+
id: request?.id,
|
|
1815
1843
|
};
|
|
1816
1844
|
const body = {
|
|
1817
1845
|
limit: request?.limit,
|
|
@@ -1820,16 +1848,16 @@ class FeedsApi {
|
|
|
1820
1848
|
sort: request?.sort,
|
|
1821
1849
|
filter: request?.filter,
|
|
1822
1850
|
};
|
|
1823
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
1851
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions/query', pathParams, undefined, body, 'application/json');
|
|
1824
1852
|
decoders.QueryCommentReactionsResponse?.(response.body);
|
|
1825
1853
|
return { ...response.body, metadata: response.metadata };
|
|
1826
1854
|
}
|
|
1827
1855
|
async deleteCommentReaction(request) {
|
|
1828
1856
|
const pathParams = {
|
|
1829
|
-
|
|
1857
|
+
id: request?.id,
|
|
1830
1858
|
type: request?.type,
|
|
1831
1859
|
};
|
|
1832
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
1860
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}/reactions/{type}', pathParams, undefined);
|
|
1833
1861
|
decoders.DeleteCommentReactionResponse?.(response.body);
|
|
1834
1862
|
return { ...response.body, metadata: response.metadata };
|
|
1835
1863
|
}
|
|
@@ -1843,9 +1871,9 @@ class FeedsApi {
|
|
|
1843
1871
|
next: request?.next,
|
|
1844
1872
|
};
|
|
1845
1873
|
const pathParams = {
|
|
1846
|
-
|
|
1874
|
+
id: request?.id,
|
|
1847
1875
|
};
|
|
1848
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
1876
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}/replies', pathParams, queryParams);
|
|
1849
1877
|
decoders.GetCommentRepliesResponse?.(response.body);
|
|
1850
1878
|
return { ...response.body, metadata: response.metadata };
|
|
1851
1879
|
}
|
|
@@ -1894,7 +1922,6 @@ class FeedsApi {
|
|
|
1894
1922
|
feed_id: request?.feed_id,
|
|
1895
1923
|
};
|
|
1896
1924
|
const body = {
|
|
1897
|
-
created_by_id: request?.created_by_id,
|
|
1898
1925
|
custom: request?.custom,
|
|
1899
1926
|
};
|
|
1900
1927
|
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}', pathParams, undefined, body, 'application/json');
|
|
@@ -1910,6 +1937,7 @@ class FeedsApi {
|
|
|
1910
1937
|
mark_all_read: request?.mark_all_read,
|
|
1911
1938
|
mark_all_seen: request?.mark_all_seen,
|
|
1912
1939
|
mark_read: request?.mark_read,
|
|
1940
|
+
mark_seen: request?.mark_seen,
|
|
1913
1941
|
mark_watched: request?.mark_watched,
|
|
1914
1942
|
};
|
|
1915
1943
|
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');
|
|
@@ -2020,7 +2048,7 @@ class FeedsApi {
|
|
|
2020
2048
|
decoders.CreateFeedsBatchResponse?.(response.body);
|
|
2021
2049
|
return { ...response.body, metadata: response.metadata };
|
|
2022
2050
|
}
|
|
2023
|
-
async
|
|
2051
|
+
async _queryFeeds(request) {
|
|
2024
2052
|
const queryParams = {
|
|
2025
2053
|
connection_id: request?.connection_id,
|
|
2026
2054
|
};
|
|
@@ -2063,8 +2091,8 @@ class FeedsApi {
|
|
|
2063
2091
|
}
|
|
2064
2092
|
async acceptFollow(request) {
|
|
2065
2093
|
const body = {
|
|
2066
|
-
|
|
2067
|
-
|
|
2094
|
+
source: request?.source,
|
|
2095
|
+
target: request?.target,
|
|
2068
2096
|
follower_role: request?.follower_role,
|
|
2069
2097
|
};
|
|
2070
2098
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/accept', undefined, undefined, body, 'application/json');
|
|
@@ -2093,8 +2121,8 @@ class FeedsApi {
|
|
|
2093
2121
|
}
|
|
2094
2122
|
async rejectFollow(request) {
|
|
2095
2123
|
const body = {
|
|
2096
|
-
|
|
2097
|
-
|
|
2124
|
+
source: request?.source,
|
|
2125
|
+
target: request?.target,
|
|
2098
2126
|
};
|
|
2099
2127
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/reject', undefined, undefined, body, 'application/json');
|
|
2100
2128
|
decoders.RejectFollowResponse?.(response.body);
|
|
@@ -4262,7 +4290,7 @@ const shouldUpdateState = ({ stateUpdateQueueId, stateUpdateQueue, watch, }) =>
|
|
|
4262
4290
|
};
|
|
4263
4291
|
function getStateUpdateQueueId(data, prefix) {
|
|
4264
4292
|
if (isFollowResponse(data)) {
|
|
4265
|
-
const toJoin = [data.source_feed.
|
|
4293
|
+
const toJoin = [data.source_feed.feed, data.target_feed.feed];
|
|
4266
4294
|
if (prefix) {
|
|
4267
4295
|
toJoin.unshift(prefix);
|
|
4268
4296
|
}
|
|
@@ -4280,7 +4308,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4280
4308
|
}
|
|
4281
4309
|
let newState = { ...currentState };
|
|
4282
4310
|
// this feed followed someone
|
|
4283
|
-
if (follow.source_feed.
|
|
4311
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4284
4312
|
newState = {
|
|
4285
4313
|
...newState,
|
|
4286
4314
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4293,7 +4321,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4293
4321
|
}
|
|
4294
4322
|
else if (
|
|
4295
4323
|
// someone followed this feed
|
|
4296
|
-
follow.target_feed.
|
|
4324
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4297
4325
|
const source = follow.source_feed;
|
|
4298
4326
|
newState = {
|
|
4299
4327
|
...newState,
|
|
@@ -4322,7 +4350,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4322
4350
|
return;
|
|
4323
4351
|
}
|
|
4324
4352
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4325
|
-
const result = updateStateFollowCreated(follow, this.currentState, this.
|
|
4353
|
+
const result = updateStateFollowCreated(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4326
4354
|
if (result.changed) {
|
|
4327
4355
|
this.state.next(result.data);
|
|
4328
4356
|
}
|
|
@@ -4331,7 +4359,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4331
4359
|
const updateStateFollowDeleted = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4332
4360
|
let newState = { ...currentState };
|
|
4333
4361
|
// this feed unfollowed someone
|
|
4334
|
-
if (follow.source_feed.
|
|
4362
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4335
4363
|
newState = {
|
|
4336
4364
|
...newState,
|
|
4337
4365
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4339,12 +4367,12 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4339
4367
|
};
|
|
4340
4368
|
// Only update if following array already exists
|
|
4341
4369
|
if (currentState.following !== undefined) {
|
|
4342
|
-
newState.following = currentState.following.filter((followItem) => followItem.target_feed.
|
|
4370
|
+
newState.following = currentState.following.filter((followItem) => followItem.target_feed.feed !== follow.target_feed.feed);
|
|
4343
4371
|
}
|
|
4344
4372
|
}
|
|
4345
4373
|
else if (
|
|
4346
4374
|
// someone unfollowed this feed
|
|
4347
|
-
follow.target_feed.
|
|
4375
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4348
4376
|
const source = follow.source_feed;
|
|
4349
4377
|
newState = {
|
|
4350
4378
|
...newState,
|
|
@@ -4353,11 +4381,11 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4353
4381
|
};
|
|
4354
4382
|
if (source.created_by.id === connectedUserId &&
|
|
4355
4383
|
currentState.own_follows !== undefined) {
|
|
4356
|
-
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.
|
|
4384
|
+
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4357
4385
|
}
|
|
4358
4386
|
// Only update if followers array already exists
|
|
4359
4387
|
if (currentState.followers !== undefined) {
|
|
4360
|
-
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.
|
|
4388
|
+
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4361
4389
|
}
|
|
4362
4390
|
}
|
|
4363
4391
|
return { changed: true, data: newState };
|
|
@@ -4372,7 +4400,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4372
4400
|
return;
|
|
4373
4401
|
}
|
|
4374
4402
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4375
|
-
const result = updateStateFollowDeleted(follow, this.currentState, this.
|
|
4403
|
+
const result = updateStateFollowDeleted(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4376
4404
|
{
|
|
4377
4405
|
this.state.next(result.data);
|
|
4378
4406
|
}
|
|
@@ -4381,7 +4409,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4381
4409
|
function handleFollowUpdated(eventOrResponse) {
|
|
4382
4410
|
const follow = eventOrResponse.follow;
|
|
4383
4411
|
const connectedUserId = this.client.state.getLatestValue().connected_user?.id;
|
|
4384
|
-
const currentFeedId = this.
|
|
4412
|
+
const currentFeedId = this.feed;
|
|
4385
4413
|
if (!shouldUpdateState({
|
|
4386
4414
|
stateUpdateQueueId: getStateUpdateQueueId(follow, 'updated'),
|
|
4387
4415
|
stateUpdateQueue: this.stateUpdateQueue,
|
|
@@ -4392,13 +4420,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4392
4420
|
this.state.next((currentState) => {
|
|
4393
4421
|
let newState;
|
|
4394
4422
|
// this feed followed someone
|
|
4395
|
-
if (follow.source_feed.
|
|
4423
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4396
4424
|
newState ?? (newState = {
|
|
4397
4425
|
...currentState,
|
|
4398
4426
|
// Update FeedResponse fields, that has the new follower/following count
|
|
4399
4427
|
...follow.source_feed,
|
|
4400
4428
|
});
|
|
4401
|
-
const index = currentState.following?.findIndex((f) => f.target_feed.
|
|
4429
|
+
const index = currentState.following?.findIndex((f) => f.target_feed.feed === follow.target_feed.feed) ?? -1;
|
|
4402
4430
|
if (index >= 0) {
|
|
4403
4431
|
newState.following = [...newState.following];
|
|
4404
4432
|
newState.following[index] = follow;
|
|
@@ -4406,7 +4434,7 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4406
4434
|
}
|
|
4407
4435
|
else if (
|
|
4408
4436
|
// someone followed this feed
|
|
4409
|
-
follow.target_feed.
|
|
4437
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4410
4438
|
const source = follow.source_feed;
|
|
4411
4439
|
newState ?? (newState = {
|
|
4412
4440
|
...currentState,
|
|
@@ -4415,13 +4443,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4415
4443
|
});
|
|
4416
4444
|
if (source.created_by.id === connectedUserId &&
|
|
4417
4445
|
currentState.own_follows) {
|
|
4418
|
-
const index = currentState.own_follows.findIndex((f) => f.source_feed.
|
|
4446
|
+
const index = currentState.own_follows.findIndex((f) => f.source_feed.feed === follow.source_feed.feed);
|
|
4419
4447
|
if (index >= 0) {
|
|
4420
4448
|
newState.own_follows = [...currentState.own_follows];
|
|
4421
4449
|
newState.own_follows[index] = follow;
|
|
4422
4450
|
}
|
|
4423
4451
|
}
|
|
4424
|
-
const index = currentState.followers?.findIndex((f) => f.source_feed.
|
|
4452
|
+
const index = currentState.followers?.findIndex((f) => f.source_feed.feed === follow.source_feed.feed) ?? -1;
|
|
4425
4453
|
if (index >= 0) {
|
|
4426
4454
|
newState.followers = [...newState.followers];
|
|
4427
4455
|
newState.followers[index] = follow;
|
|
@@ -4909,6 +4937,14 @@ function handleNotificationFeedUpdated(event) {
|
|
|
4909
4937
|
// TODO: handle notification feed updates
|
|
4910
4938
|
}
|
|
4911
4939
|
|
|
4940
|
+
function handleWatchStarted() {
|
|
4941
|
+
this.state.partialNext({ watch: true });
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4944
|
+
function handleWatchStopped() {
|
|
4945
|
+
this.state.partialNext({ watch: false });
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4912
4948
|
class Feed extends FeedApi {
|
|
4913
4949
|
constructor(client, groupId, id, data, watch = false) {
|
|
4914
4950
|
super(client, groupId, id);
|
|
@@ -4969,7 +5005,7 @@ class Feed extends FeedApi {
|
|
|
4969
5005
|
this.on = this.eventDispatcher.on;
|
|
4970
5006
|
this.off = this.eventDispatcher.off;
|
|
4971
5007
|
this.state = new StateStore({
|
|
4972
|
-
|
|
5008
|
+
feed: `${groupId}:${id}`,
|
|
4973
5009
|
group_id: groupId,
|
|
4974
5010
|
id,
|
|
4975
5011
|
...(data ?? {}),
|
|
@@ -4980,7 +5016,7 @@ class Feed extends FeedApi {
|
|
|
4980
5016
|
});
|
|
4981
5017
|
this.client = client;
|
|
4982
5018
|
}
|
|
4983
|
-
get
|
|
5019
|
+
get feed() {
|
|
4984
5020
|
return `${this.group}:${this.id}`;
|
|
4985
5021
|
}
|
|
4986
5022
|
get currentState() {
|
|
@@ -5055,22 +5091,6 @@ class Feed extends FeedApi {
|
|
|
5055
5091
|
});
|
|
5056
5092
|
}
|
|
5057
5093
|
}
|
|
5058
|
-
/**
|
|
5059
|
-
* @internal
|
|
5060
|
-
*/
|
|
5061
|
-
handleWatchStopped() {
|
|
5062
|
-
this.state.partialNext({
|
|
5063
|
-
watch: false,
|
|
5064
|
-
});
|
|
5065
|
-
}
|
|
5066
|
-
/**
|
|
5067
|
-
* @internal
|
|
5068
|
-
*/
|
|
5069
|
-
handleWatchStarted() {
|
|
5070
|
-
this.state.partialNext({
|
|
5071
|
-
watch: true,
|
|
5072
|
-
});
|
|
5073
|
-
}
|
|
5074
5094
|
/**
|
|
5075
5095
|
* Returns index of the provided comment object.
|
|
5076
5096
|
*/
|
|
@@ -5230,7 +5250,7 @@ class Feed extends FeedApi {
|
|
|
5230
5250
|
entityId: comment.id,
|
|
5231
5251
|
base: () => this.client.getCommentReplies({
|
|
5232
5252
|
...request,
|
|
5233
|
-
|
|
5253
|
+
id: comment.id,
|
|
5234
5254
|
// use known sort first (prevents broken pagination)
|
|
5235
5255
|
sort,
|
|
5236
5256
|
next: currentNextCursor,
|
|
@@ -5270,7 +5290,7 @@ class Feed extends FeedApi {
|
|
|
5270
5290
|
...currentState,
|
|
5271
5291
|
[type]: currentState[type] === undefined
|
|
5272
5292
|
? follows
|
|
5273
|
-
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.
|
|
5293
|
+
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.feed}-${follow.target_feed.feed}`),
|
|
5274
5294
|
[paginationKey]: {
|
|
5275
5295
|
...currentState[paginationKey],
|
|
5276
5296
|
next: newNextCursor,
|
|
@@ -5363,7 +5383,7 @@ class Feed extends FeedApi {
|
|
|
5363
5383
|
*/
|
|
5364
5384
|
async queryFollowers(request) {
|
|
5365
5385
|
const filter = {
|
|
5366
|
-
target_feed: this.
|
|
5386
|
+
target_feed: this.feed,
|
|
5367
5387
|
};
|
|
5368
5388
|
const response = await this.client.queryFollows({
|
|
5369
5389
|
filter,
|
|
@@ -5378,7 +5398,7 @@ class Feed extends FeedApi {
|
|
|
5378
5398
|
*/
|
|
5379
5399
|
async queryFollowing(request) {
|
|
5380
5400
|
const filter = {
|
|
5381
|
-
source_feed: this.
|
|
5401
|
+
source_feed: this.feed,
|
|
5382
5402
|
};
|
|
5383
5403
|
const response = await this.client.queryFollows({
|
|
5384
5404
|
filter,
|
|
@@ -5387,18 +5407,18 @@ class Feed extends FeedApi {
|
|
|
5387
5407
|
return response;
|
|
5388
5408
|
}
|
|
5389
5409
|
async follow(feedOrFid, options) {
|
|
5390
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5410
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5391
5411
|
const response = await this.client.follow({
|
|
5392
5412
|
...options,
|
|
5393
|
-
source: this.
|
|
5413
|
+
source: this.feed,
|
|
5394
5414
|
target: fid,
|
|
5395
5415
|
});
|
|
5396
5416
|
return response;
|
|
5397
5417
|
}
|
|
5398
5418
|
async unfollow(feedOrFid) {
|
|
5399
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5419
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5400
5420
|
const response = await this.client.unfollow({
|
|
5401
|
-
source: this.
|
|
5421
|
+
source: this.feed,
|
|
5402
5422
|
target: fid,
|
|
5403
5423
|
});
|
|
5404
5424
|
return response;
|
|
@@ -5422,7 +5442,7 @@ class Feed extends FeedApi {
|
|
|
5422
5442
|
addActivity(request) {
|
|
5423
5443
|
return this.feedsApi.addActivity({
|
|
5424
5444
|
...request,
|
|
5425
|
-
|
|
5445
|
+
feeds: [this.feed],
|
|
5426
5446
|
});
|
|
5427
5447
|
}
|
|
5428
5448
|
handleWSEvent(event) {
|
|
@@ -5440,6 +5460,24 @@ class Feed extends FeedApi {
|
|
|
5440
5460
|
}
|
|
5441
5461
|
Feed.noop = () => { };
|
|
5442
5462
|
|
|
5463
|
+
function handleUserUpdated(event) {
|
|
5464
|
+
this.state.next((currentState) => {
|
|
5465
|
+
let newState;
|
|
5466
|
+
const { connected_user } = currentState;
|
|
5467
|
+
if (connected_user && connected_user.id === event.user.id) {
|
|
5468
|
+
newState ?? (newState = {
|
|
5469
|
+
...currentState,
|
|
5470
|
+
});
|
|
5471
|
+
newState.connected_user = {
|
|
5472
|
+
...connected_user,
|
|
5473
|
+
...event.user,
|
|
5474
|
+
};
|
|
5475
|
+
}
|
|
5476
|
+
// TODO: update other users in user map (if/once applicable)
|
|
5477
|
+
return newState ?? currentState;
|
|
5478
|
+
});
|
|
5479
|
+
}
|
|
5480
|
+
|
|
5443
5481
|
class FeedsClient extends FeedsApi {
|
|
5444
5482
|
constructor(apiKey, options) {
|
|
5445
5483
|
const tokenManager = new TokenManager();
|
|
@@ -5547,7 +5585,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5547
5585
|
if (this.activeFeeds[fid]) {
|
|
5548
5586
|
const feed = this.activeFeeds[fid];
|
|
5549
5587
|
if (watch && !feed.currentState.watch) {
|
|
5550
|
-
|
|
5588
|
+
handleWatchStarted.bind(feed)();
|
|
5551
5589
|
}
|
|
5552
5590
|
return feed;
|
|
5553
5591
|
}
|
|
@@ -5583,7 +5621,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5583
5621
|
}
|
|
5584
5622
|
else {
|
|
5585
5623
|
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
5586
|
-
|
|
5624
|
+
handleWatchStopped.bind(activeFeed)();
|
|
5587
5625
|
}
|
|
5588
5626
|
}
|
|
5589
5627
|
break;
|
|
@@ -5663,6 +5701,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5663
5701
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
5664
5702
|
break;
|
|
5665
5703
|
}
|
|
5704
|
+
case 'user.updated': {
|
|
5705
|
+
handleUserUpdated.call(this, event);
|
|
5706
|
+
break;
|
|
5707
|
+
}
|
|
5666
5708
|
default: {
|
|
5667
5709
|
feed?.handleWSEvent(event);
|
|
5668
5710
|
}
|
|
@@ -5688,7 +5730,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5688
5730
|
}
|
|
5689
5731
|
}
|
|
5690
5732
|
async queryFeeds(request) {
|
|
5691
|
-
const response = await this.
|
|
5733
|
+
const response = await this._queryFeeds(request);
|
|
5692
5734
|
const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
|
|
5693
5735
|
return {
|
|
5694
5736
|
feeds,
|
|
@@ -5700,7 +5742,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5700
5742
|
}
|
|
5701
5743
|
async updateFollow(request) {
|
|
5702
5744
|
const response = await super.updateFollow(request);
|
|
5703
|
-
[
|
|
5745
|
+
[
|
|
5746
|
+
response.follow.source_feed.feed,
|
|
5747
|
+
response.follow.target_feed.feed,
|
|
5748
|
+
].forEach((fid) => {
|
|
5704
5749
|
const feed = this.activeFeeds[fid];
|
|
5705
5750
|
if (feed) {
|
|
5706
5751
|
handleFollowUpdated.bind(feed)(response);
|
|
@@ -5711,7 +5756,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5711
5756
|
// For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
|
|
5712
5757
|
async follow(request) {
|
|
5713
5758
|
const response = await super.follow(request);
|
|
5714
|
-
[
|
|
5759
|
+
[
|
|
5760
|
+
response.follow.source_feed.feed,
|
|
5761
|
+
response.follow.target_feed.feed,
|
|
5762
|
+
].forEach((fid) => {
|
|
5715
5763
|
const feed = this.activeFeeds[fid];
|
|
5716
5764
|
if (feed) {
|
|
5717
5765
|
handleFollowCreated.bind(feed)(response);
|
|
@@ -5722,7 +5770,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5722
5770
|
async followBatch(request) {
|
|
5723
5771
|
const response = await super.followBatch(request);
|
|
5724
5772
|
response.follows.forEach((follow) => {
|
|
5725
|
-
const feed = this.activeFeeds[follow.source_feed.
|
|
5773
|
+
const feed = this.activeFeeds[follow.source_feed.feed];
|
|
5726
5774
|
if (feed) {
|
|
5727
5775
|
handleFollowCreated.bind(feed)({ follow });
|
|
5728
5776
|
}
|
|
@@ -5747,7 +5795,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5747
5795
|
});
|
|
5748
5796
|
const feed = this.activeFeeds[`${request.feed_group_id}:${request.feed_id}`];
|
|
5749
5797
|
if (feed) {
|
|
5750
|
-
|
|
5798
|
+
handleWatchStopped.bind(feed)();
|
|
5751
5799
|
}
|
|
5752
5800
|
return response;
|
|
5753
5801
|
}
|