@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
|
@@ -611,6 +611,7 @@ decoders.Channel = (input) => {
|
|
|
611
611
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
612
612
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
613
613
|
last_message_at: { type: 'DatetimeType', isSingle: true },
|
|
614
|
+
message_count_updated_at: { type: 'DatetimeType', isSingle: true },
|
|
614
615
|
active_live_locations: { type: 'SharedLocation', isSingle: false },
|
|
615
616
|
invites: { type: 'ChannelMember', isSingle: false },
|
|
616
617
|
members: { type: 'ChannelMember', isSingle: false },
|
|
@@ -888,6 +889,7 @@ decoders.FeedMemberResponse = (input) => {
|
|
|
888
889
|
user: { type: 'UserResponse', isSingle: true },
|
|
889
890
|
invite_accepted_at: { type: 'DatetimeType', isSingle: true },
|
|
890
891
|
invite_rejected_at: { type: 'DatetimeType', isSingle: true },
|
|
892
|
+
membership_level: { type: 'MembershipLevelResponse', isSingle: true },
|
|
891
893
|
};
|
|
892
894
|
return decode(typeMappings, input);
|
|
893
895
|
};
|
|
@@ -905,6 +907,7 @@ decoders.FeedResponse = (input) => {
|
|
|
905
907
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
906
908
|
created_by: { type: 'UserResponse', isSingle: true },
|
|
907
909
|
deleted_at: { type: 'DatetimeType', isSingle: true },
|
|
910
|
+
own_follows: { type: 'FollowResponse', isSingle: false },
|
|
908
911
|
};
|
|
909
912
|
return decode(typeMappings, input);
|
|
910
913
|
};
|
|
@@ -1059,6 +1062,13 @@ decoders.ListDevicesResponse = (input) => {
|
|
|
1059
1062
|
};
|
|
1060
1063
|
return decode(typeMappings, input);
|
|
1061
1064
|
};
|
|
1065
|
+
decoders.MembershipLevelResponse = (input) => {
|
|
1066
|
+
const typeMappings = {
|
|
1067
|
+
created_at: { type: 'DatetimeType', isSingle: true },
|
|
1068
|
+
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1069
|
+
};
|
|
1070
|
+
return decode(typeMappings, input);
|
|
1071
|
+
};
|
|
1062
1072
|
decoders.Message = (input) => {
|
|
1063
1073
|
const typeMappings = {
|
|
1064
1074
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -1123,6 +1133,13 @@ decoders.ModerationCustomActionEvent = (input) => {
|
|
|
1123
1133
|
};
|
|
1124
1134
|
return decode(typeMappings, input);
|
|
1125
1135
|
};
|
|
1136
|
+
decoders.ModerationFlagResponse = (input) => {
|
|
1137
|
+
const typeMappings = {
|
|
1138
|
+
review_queue_item: { type: 'ReviewQueueItemResponse', isSingle: true },
|
|
1139
|
+
user: { type: 'UserResponse', isSingle: true },
|
|
1140
|
+
};
|
|
1141
|
+
return decode(typeMappings, input);
|
|
1142
|
+
};
|
|
1126
1143
|
decoders.ModerationFlaggedEvent = (input) => {
|
|
1127
1144
|
const typeMappings = {
|
|
1128
1145
|
created_at: { type: 'DatetimeType', isSingle: true },
|
|
@@ -1159,6 +1176,7 @@ decoders.NotificationFeedUpdatedEvent = (input) => {
|
|
|
1159
1176
|
};
|
|
1160
1177
|
decoders.NotificationStatusResponse = (input) => {
|
|
1161
1178
|
const typeMappings = {
|
|
1179
|
+
last_read_at: { type: 'DatetimeType', isSingle: true },
|
|
1162
1180
|
last_seen_at: { type: 'DatetimeType', isSingle: true },
|
|
1163
1181
|
};
|
|
1164
1182
|
return decode(typeMappings, input);
|
|
@@ -1426,6 +1444,7 @@ decoders.ReviewQueueItemResponse = (input) => {
|
|
|
1426
1444
|
updated_at: { type: 'DatetimeType', isSingle: true },
|
|
1427
1445
|
actions: { type: 'ActionLogResponse', isSingle: false },
|
|
1428
1446
|
bans: { type: 'Ban', isSingle: false },
|
|
1447
|
+
flags: { type: 'ModerationFlagResponse', isSingle: false },
|
|
1429
1448
|
completed_at: { type: 'DatetimeType', isSingle: true },
|
|
1430
1449
|
reviewed_at: { type: 'DatetimeType', isSingle: true },
|
|
1431
1450
|
assigned_to: { type: 'UserResponse', isSingle: true },
|
|
@@ -1748,7 +1767,7 @@ class FeedsApi {
|
|
|
1748
1767
|
async addActivity(request) {
|
|
1749
1768
|
const body = {
|
|
1750
1769
|
type: request?.type,
|
|
1751
|
-
|
|
1770
|
+
feeds: request?.feeds,
|
|
1752
1771
|
expires_at: request?.expires_at,
|
|
1753
1772
|
id: request?.id,
|
|
1754
1773
|
parent_id: request?.parent_id,
|
|
@@ -1778,7 +1797,7 @@ class FeedsApi {
|
|
|
1778
1797
|
}
|
|
1779
1798
|
async deleteActivities(request) {
|
|
1780
1799
|
const body = {
|
|
1781
|
-
|
|
1800
|
+
ids: request?.ids,
|
|
1782
1801
|
hard_delete: request?.hard_delete,
|
|
1783
1802
|
};
|
|
1784
1803
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/delete', undefined, undefined, body, 'application/json');
|
|
@@ -1797,56 +1816,6 @@ class FeedsApi {
|
|
|
1797
1816
|
decoders.QueryActivitiesResponse?.(response.body);
|
|
1798
1817
|
return { ...response.body, metadata: response.metadata };
|
|
1799
1818
|
}
|
|
1800
|
-
async deleteActivity(request) {
|
|
1801
|
-
const queryParams = {
|
|
1802
|
-
hard_delete: request?.hard_delete,
|
|
1803
|
-
};
|
|
1804
|
-
const pathParams = {
|
|
1805
|
-
activity_id: request?.activity_id,
|
|
1806
|
-
};
|
|
1807
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{activity_id}', pathParams, queryParams);
|
|
1808
|
-
decoders.DeleteActivityResponse?.(response.body);
|
|
1809
|
-
return { ...response.body, metadata: response.metadata };
|
|
1810
|
-
}
|
|
1811
|
-
async getActivity(request) {
|
|
1812
|
-
const pathParams = {
|
|
1813
|
-
activity_id: request?.activity_id,
|
|
1814
|
-
};
|
|
1815
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined);
|
|
1816
|
-
decoders.GetActivityResponse?.(response.body);
|
|
1817
|
-
return { ...response.body, metadata: response.metadata };
|
|
1818
|
-
}
|
|
1819
|
-
async updateActivityPartial(request) {
|
|
1820
|
-
const pathParams = {
|
|
1821
|
-
activity_id: request?.activity_id,
|
|
1822
|
-
};
|
|
1823
|
-
const body = {
|
|
1824
|
-
unset: request?.unset,
|
|
1825
|
-
set: request?.set,
|
|
1826
|
-
};
|
|
1827
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1828
|
-
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1829
|
-
return { ...response.body, metadata: response.metadata };
|
|
1830
|
-
}
|
|
1831
|
-
async updateActivity(request) {
|
|
1832
|
-
const pathParams = {
|
|
1833
|
-
activity_id: request?.activity_id,
|
|
1834
|
-
};
|
|
1835
|
-
const body = {
|
|
1836
|
-
expires_at: request?.expires_at,
|
|
1837
|
-
poll_id: request?.poll_id,
|
|
1838
|
-
text: request?.text,
|
|
1839
|
-
visibility: request?.visibility,
|
|
1840
|
-
attachments: request?.attachments,
|
|
1841
|
-
filter_tags: request?.filter_tags,
|
|
1842
|
-
interest_tags: request?.interest_tags,
|
|
1843
|
-
custom: request?.custom,
|
|
1844
|
-
location: request?.location,
|
|
1845
|
-
};
|
|
1846
|
-
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{activity_id}', pathParams, undefined, body, 'application/json');
|
|
1847
|
-
decoders.UpdateActivityResponse?.(response.body);
|
|
1848
|
-
return { ...response.body, metadata: response.metadata };
|
|
1849
|
-
}
|
|
1850
1819
|
async deleteBookmark(request) {
|
|
1851
1820
|
const queryParams = {
|
|
1852
1821
|
folder_id: request?.folder_id,
|
|
@@ -1885,6 +1854,21 @@ class FeedsApi {
|
|
|
1885
1854
|
decoders.AddBookmarkResponse?.(response.body);
|
|
1886
1855
|
return { ...response.body, metadata: response.metadata };
|
|
1887
1856
|
}
|
|
1857
|
+
async activityFeedback(request) {
|
|
1858
|
+
const pathParams = {
|
|
1859
|
+
activity_id: request?.activity_id,
|
|
1860
|
+
};
|
|
1861
|
+
const body = {
|
|
1862
|
+
hide: request?.hide,
|
|
1863
|
+
mute_user: request?.mute_user,
|
|
1864
|
+
reason: request?.reason,
|
|
1865
|
+
report: request?.report,
|
|
1866
|
+
show_less: request?.show_less,
|
|
1867
|
+
};
|
|
1868
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/activities/{activity_id}/feedback', pathParams, undefined, body, 'application/json');
|
|
1869
|
+
decoders.ActivityFeedbackResponse?.(response.body);
|
|
1870
|
+
return { ...response.body, metadata: response.metadata };
|
|
1871
|
+
}
|
|
1888
1872
|
async castPollVote(request) {
|
|
1889
1873
|
const pathParams = {
|
|
1890
1874
|
activity_id: request?.activity_id,
|
|
@@ -1947,6 +1931,56 @@ class FeedsApi {
|
|
|
1947
1931
|
decoders.DeleteActivityReactionResponse?.(response.body);
|
|
1948
1932
|
return { ...response.body, metadata: response.metadata };
|
|
1949
1933
|
}
|
|
1934
|
+
async deleteActivity(request) {
|
|
1935
|
+
const queryParams = {
|
|
1936
|
+
hard_delete: request?.hard_delete,
|
|
1937
|
+
};
|
|
1938
|
+
const pathParams = {
|
|
1939
|
+
id: request?.id,
|
|
1940
|
+
};
|
|
1941
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/activities/{id}', pathParams, queryParams);
|
|
1942
|
+
decoders.DeleteActivityResponse?.(response.body);
|
|
1943
|
+
return { ...response.body, metadata: response.metadata };
|
|
1944
|
+
}
|
|
1945
|
+
async getActivity(request) {
|
|
1946
|
+
const pathParams = {
|
|
1947
|
+
id: request?.id,
|
|
1948
|
+
};
|
|
1949
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/activities/{id}', pathParams, undefined);
|
|
1950
|
+
decoders.GetActivityResponse?.(response.body);
|
|
1951
|
+
return { ...response.body, metadata: response.metadata };
|
|
1952
|
+
}
|
|
1953
|
+
async updateActivityPartial(request) {
|
|
1954
|
+
const pathParams = {
|
|
1955
|
+
id: request?.id,
|
|
1956
|
+
};
|
|
1957
|
+
const body = {
|
|
1958
|
+
unset: request?.unset,
|
|
1959
|
+
set: request?.set,
|
|
1960
|
+
};
|
|
1961
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1962
|
+
decoders.UpdateActivityPartialResponse?.(response.body);
|
|
1963
|
+
return { ...response.body, metadata: response.metadata };
|
|
1964
|
+
}
|
|
1965
|
+
async updateActivity(request) {
|
|
1966
|
+
const pathParams = {
|
|
1967
|
+
id: request?.id,
|
|
1968
|
+
};
|
|
1969
|
+
const body = {
|
|
1970
|
+
expires_at: request?.expires_at,
|
|
1971
|
+
poll_id: request?.poll_id,
|
|
1972
|
+
text: request?.text,
|
|
1973
|
+
visibility: request?.visibility,
|
|
1974
|
+
attachments: request?.attachments,
|
|
1975
|
+
filter_tags: request?.filter_tags,
|
|
1976
|
+
interest_tags: request?.interest_tags,
|
|
1977
|
+
custom: request?.custom,
|
|
1978
|
+
location: request?.location,
|
|
1979
|
+
};
|
|
1980
|
+
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/activities/{id}', pathParams, undefined, body, 'application/json');
|
|
1981
|
+
decoders.UpdateActivityResponse?.(response.body);
|
|
1982
|
+
return { ...response.body, metadata: response.metadata };
|
|
1983
|
+
}
|
|
1950
1984
|
async queryBookmarkFolders(request) {
|
|
1951
1985
|
const body = {
|
|
1952
1986
|
limit: request?.limit,
|
|
@@ -2042,49 +2076,52 @@ class FeedsApi {
|
|
|
2042
2076
|
return { ...response.body, metadata: response.metadata };
|
|
2043
2077
|
}
|
|
2044
2078
|
async deleteComment(request) {
|
|
2079
|
+
const queryParams = {
|
|
2080
|
+
hard_delete: request?.hard_delete,
|
|
2081
|
+
};
|
|
2045
2082
|
const pathParams = {
|
|
2046
|
-
|
|
2083
|
+
id: request?.id,
|
|
2047
2084
|
};
|
|
2048
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
2085
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}', pathParams, queryParams);
|
|
2049
2086
|
decoders.DeleteCommentResponse?.(response.body);
|
|
2050
2087
|
return { ...response.body, metadata: response.metadata };
|
|
2051
2088
|
}
|
|
2052
2089
|
async getComment(request) {
|
|
2053
2090
|
const pathParams = {
|
|
2054
|
-
|
|
2091
|
+
id: request?.id,
|
|
2055
2092
|
};
|
|
2056
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
2093
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}', pathParams, undefined);
|
|
2057
2094
|
decoders.GetCommentResponse?.(response.body);
|
|
2058
2095
|
return { ...response.body, metadata: response.metadata };
|
|
2059
2096
|
}
|
|
2060
2097
|
async updateComment(request) {
|
|
2061
2098
|
const pathParams = {
|
|
2062
|
-
|
|
2099
|
+
id: request?.id,
|
|
2063
2100
|
};
|
|
2064
2101
|
const body = {
|
|
2065
2102
|
comment: request?.comment,
|
|
2066
2103
|
custom: request?.custom,
|
|
2067
2104
|
};
|
|
2068
|
-
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{
|
|
2105
|
+
const response = await this.apiClient.sendRequest('PATCH', '/api/v2/feeds/comments/{id}', pathParams, undefined, body, 'application/json');
|
|
2069
2106
|
decoders.UpdateCommentResponse?.(response.body);
|
|
2070
2107
|
return { ...response.body, metadata: response.metadata };
|
|
2071
2108
|
}
|
|
2072
2109
|
async addCommentReaction(request) {
|
|
2073
2110
|
const pathParams = {
|
|
2074
|
-
|
|
2111
|
+
id: request?.id,
|
|
2075
2112
|
};
|
|
2076
2113
|
const body = {
|
|
2077
2114
|
type: request?.type,
|
|
2078
2115
|
create_notification_activity: request?.create_notification_activity,
|
|
2079
2116
|
custom: request?.custom,
|
|
2080
2117
|
};
|
|
2081
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
2118
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions', pathParams, undefined, body, 'application/json');
|
|
2082
2119
|
decoders.AddCommentReactionResponse?.(response.body);
|
|
2083
2120
|
return { ...response.body, metadata: response.metadata };
|
|
2084
2121
|
}
|
|
2085
2122
|
async queryCommentReactions(request) {
|
|
2086
2123
|
const pathParams = {
|
|
2087
|
-
|
|
2124
|
+
id: request?.id,
|
|
2088
2125
|
};
|
|
2089
2126
|
const body = {
|
|
2090
2127
|
limit: request?.limit,
|
|
@@ -2093,16 +2130,16 @@ class FeedsApi {
|
|
|
2093
2130
|
sort: request?.sort,
|
|
2094
2131
|
filter: request?.filter,
|
|
2095
2132
|
};
|
|
2096
|
-
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{
|
|
2133
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/comments/{id}/reactions/query', pathParams, undefined, body, 'application/json');
|
|
2097
2134
|
decoders.QueryCommentReactionsResponse?.(response.body);
|
|
2098
2135
|
return { ...response.body, metadata: response.metadata };
|
|
2099
2136
|
}
|
|
2100
2137
|
async deleteCommentReaction(request) {
|
|
2101
2138
|
const pathParams = {
|
|
2102
|
-
|
|
2139
|
+
id: request?.id,
|
|
2103
2140
|
type: request?.type,
|
|
2104
2141
|
};
|
|
2105
|
-
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{
|
|
2142
|
+
const response = await this.apiClient.sendRequest('DELETE', '/api/v2/feeds/comments/{id}/reactions/{type}', pathParams, undefined);
|
|
2106
2143
|
decoders.DeleteCommentReactionResponse?.(response.body);
|
|
2107
2144
|
return { ...response.body, metadata: response.metadata };
|
|
2108
2145
|
}
|
|
@@ -2116,9 +2153,9 @@ class FeedsApi {
|
|
|
2116
2153
|
next: request?.next,
|
|
2117
2154
|
};
|
|
2118
2155
|
const pathParams = {
|
|
2119
|
-
|
|
2156
|
+
id: request?.id,
|
|
2120
2157
|
};
|
|
2121
|
-
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{
|
|
2158
|
+
const response = await this.apiClient.sendRequest('GET', '/api/v2/feeds/comments/{id}/replies', pathParams, queryParams);
|
|
2122
2159
|
decoders.GetCommentRepliesResponse?.(response.body);
|
|
2123
2160
|
return { ...response.body, metadata: response.metadata };
|
|
2124
2161
|
}
|
|
@@ -2167,7 +2204,6 @@ class FeedsApi {
|
|
|
2167
2204
|
feed_id: request?.feed_id,
|
|
2168
2205
|
};
|
|
2169
2206
|
const body = {
|
|
2170
|
-
created_by_id: request?.created_by_id,
|
|
2171
2207
|
custom: request?.custom,
|
|
2172
2208
|
};
|
|
2173
2209
|
const response = await this.apiClient.sendRequest('PUT', '/api/v2/feeds/feed_groups/{feed_group_id}/feeds/{feed_id}', pathParams, undefined, body, 'application/json');
|
|
@@ -2183,6 +2219,7 @@ class FeedsApi {
|
|
|
2183
2219
|
mark_all_read: request?.mark_all_read,
|
|
2184
2220
|
mark_all_seen: request?.mark_all_seen,
|
|
2185
2221
|
mark_read: request?.mark_read,
|
|
2222
|
+
mark_seen: request?.mark_seen,
|
|
2186
2223
|
mark_watched: request?.mark_watched,
|
|
2187
2224
|
};
|
|
2188
2225
|
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');
|
|
@@ -2293,7 +2330,7 @@ class FeedsApi {
|
|
|
2293
2330
|
decoders.CreateFeedsBatchResponse?.(response.body);
|
|
2294
2331
|
return { ...response.body, metadata: response.metadata };
|
|
2295
2332
|
}
|
|
2296
|
-
async
|
|
2333
|
+
async _queryFeeds(request) {
|
|
2297
2334
|
const queryParams = {
|
|
2298
2335
|
connection_id: request?.connection_id,
|
|
2299
2336
|
};
|
|
@@ -2336,8 +2373,8 @@ class FeedsApi {
|
|
|
2336
2373
|
}
|
|
2337
2374
|
async acceptFollow(request) {
|
|
2338
2375
|
const body = {
|
|
2339
|
-
|
|
2340
|
-
|
|
2376
|
+
source: request?.source,
|
|
2377
|
+
target: request?.target,
|
|
2341
2378
|
follower_role: request?.follower_role,
|
|
2342
2379
|
};
|
|
2343
2380
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/accept', undefined, undefined, body, 'application/json');
|
|
@@ -2366,8 +2403,8 @@ class FeedsApi {
|
|
|
2366
2403
|
}
|
|
2367
2404
|
async rejectFollow(request) {
|
|
2368
2405
|
const body = {
|
|
2369
|
-
|
|
2370
|
-
|
|
2406
|
+
source: request?.source,
|
|
2407
|
+
target: request?.target,
|
|
2371
2408
|
};
|
|
2372
2409
|
const response = await this.apiClient.sendRequest('POST', '/api/v2/feeds/follows/reject', undefined, undefined, body, 'application/json');
|
|
2373
2410
|
decoders.RejectFollowResponse?.(response.body);
|
|
@@ -3782,6 +3819,7 @@ class ModerationApi {
|
|
|
3782
3819
|
block_list_config: request?.block_list_config,
|
|
3783
3820
|
bodyguard_config: request?.bodyguard_config,
|
|
3784
3821
|
google_vision_config: request?.google_vision_config,
|
|
3822
|
+
llm_config: request?.llm_config,
|
|
3785
3823
|
rule_builder_config: request?.rule_builder_config,
|
|
3786
3824
|
velocity_filter_config: request?.velocity_filter_config,
|
|
3787
3825
|
video_call_rule_config: request?.video_call_rule_config,
|
|
@@ -4247,7 +4285,7 @@ const shouldUpdateState = ({ stateUpdateQueueId, stateUpdateQueue, watch, }) =>
|
|
|
4247
4285
|
};
|
|
4248
4286
|
function getStateUpdateQueueId(data, prefix) {
|
|
4249
4287
|
if (isFollowResponse(data)) {
|
|
4250
|
-
const toJoin = [data.source_feed.
|
|
4288
|
+
const toJoin = [data.source_feed.feed, data.target_feed.feed];
|
|
4251
4289
|
if (prefix) {
|
|
4252
4290
|
toJoin.unshift(prefix);
|
|
4253
4291
|
}
|
|
@@ -4258,6 +4296,23 @@ function getStateUpdateQueueId(data, prefix) {
|
|
|
4258
4296
|
throw new Error(`Cannot create state update queueId for data: ${JSON.stringify(data)}`);
|
|
4259
4297
|
}
|
|
4260
4298
|
|
|
4299
|
+
function updateEntityInArray({ matcher, updater, entities, }) {
|
|
4300
|
+
if (!entities || !entities.length) {
|
|
4301
|
+
return { changed: false, entities };
|
|
4302
|
+
}
|
|
4303
|
+
const index = entities.findIndex(matcher);
|
|
4304
|
+
if (index === -1) {
|
|
4305
|
+
return { changed: false, entities };
|
|
4306
|
+
}
|
|
4307
|
+
const newEntity = updater(entities[index]);
|
|
4308
|
+
if (newEntity === entities[index]) {
|
|
4309
|
+
return { changed: false, entities };
|
|
4310
|
+
}
|
|
4311
|
+
const updatedEntities = [...entities];
|
|
4312
|
+
updatedEntities[index] = newEntity;
|
|
4313
|
+
return { changed: true, entities: updatedEntities };
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4261
4316
|
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4262
4317
|
// filter non-accepted follows (the way getOrCreate does by default)
|
|
4263
4318
|
if (follow.status !== 'accepted') {
|
|
@@ -4265,7 +4320,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4265
4320
|
}
|
|
4266
4321
|
let newState = { ...currentState };
|
|
4267
4322
|
// this feed followed someone
|
|
4268
|
-
if (follow.source_feed.
|
|
4323
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4269
4324
|
newState = {
|
|
4270
4325
|
...newState,
|
|
4271
4326
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4278,7 +4333,7 @@ const updateStateFollowCreated = (follow, currentState, currentFeedId, connected
|
|
|
4278
4333
|
}
|
|
4279
4334
|
else if (
|
|
4280
4335
|
// someone followed this feed
|
|
4281
|
-
follow.target_feed.
|
|
4336
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4282
4337
|
const source = follow.source_feed;
|
|
4283
4338
|
newState = {
|
|
4284
4339
|
...newState,
|
|
@@ -4307,7 +4362,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4307
4362
|
return;
|
|
4308
4363
|
}
|
|
4309
4364
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4310
|
-
const result = updateStateFollowCreated(follow, this.currentState, this.
|
|
4365
|
+
const result = updateStateFollowCreated(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4311
4366
|
if (result.changed) {
|
|
4312
4367
|
this.state.next(result.data);
|
|
4313
4368
|
}
|
|
@@ -4316,7 +4371,7 @@ function handleFollowCreated(eventOrResponse) {
|
|
|
4316
4371
|
const updateStateFollowDeleted = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4317
4372
|
let newState = { ...currentState };
|
|
4318
4373
|
// this feed unfollowed someone
|
|
4319
|
-
if (follow.source_feed.
|
|
4374
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4320
4375
|
newState = {
|
|
4321
4376
|
...newState,
|
|
4322
4377
|
// Update FeedResponse fields, that has the new follower/following count
|
|
@@ -4324,12 +4379,12 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4324
4379
|
};
|
|
4325
4380
|
// Only update if following array already exists
|
|
4326
4381
|
if (currentState.following !== undefined) {
|
|
4327
|
-
newState.following = currentState.following.filter((followItem) => followItem.target_feed.
|
|
4382
|
+
newState.following = currentState.following.filter((followItem) => followItem.target_feed.feed !== follow.target_feed.feed);
|
|
4328
4383
|
}
|
|
4329
4384
|
}
|
|
4330
4385
|
else if (
|
|
4331
4386
|
// someone unfollowed this feed
|
|
4332
|
-
follow.target_feed.
|
|
4387
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4333
4388
|
const source = follow.source_feed;
|
|
4334
4389
|
newState = {
|
|
4335
4390
|
...newState,
|
|
@@ -4338,11 +4393,11 @@ const updateStateFollowDeleted = (follow, currentState, currentFeedId, connected
|
|
|
4338
4393
|
};
|
|
4339
4394
|
if (source.created_by.id === connectedUserId &&
|
|
4340
4395
|
currentState.own_follows !== undefined) {
|
|
4341
|
-
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.
|
|
4396
|
+
newState.own_follows = currentState.own_follows.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4342
4397
|
}
|
|
4343
4398
|
// Only update if followers array already exists
|
|
4344
4399
|
if (currentState.followers !== undefined) {
|
|
4345
|
-
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.
|
|
4400
|
+
newState.followers = currentState.followers.filter((followItem) => followItem.source_feed.feed !== follow.source_feed.feed);
|
|
4346
4401
|
}
|
|
4347
4402
|
}
|
|
4348
4403
|
return { changed: true, data: newState };
|
|
@@ -4357,7 +4412,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4357
4412
|
return;
|
|
4358
4413
|
}
|
|
4359
4414
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4360
|
-
const result = updateStateFollowDeleted(follow, this.currentState, this.
|
|
4415
|
+
const result = updateStateFollowDeleted(follow, this.currentState, this.feed, connectedUser?.id);
|
|
4361
4416
|
{
|
|
4362
4417
|
this.state.next(result.data);
|
|
4363
4418
|
}
|
|
@@ -4366,7 +4421,7 @@ function handleFollowDeleted(eventOrResponse) {
|
|
|
4366
4421
|
function handleFollowUpdated(eventOrResponse) {
|
|
4367
4422
|
const follow = eventOrResponse.follow;
|
|
4368
4423
|
const connectedUserId = this.client.state.getLatestValue().connected_user?.id;
|
|
4369
|
-
const currentFeedId = this.
|
|
4424
|
+
const currentFeedId = this.feed;
|
|
4370
4425
|
if (!shouldUpdateState({
|
|
4371
4426
|
stateUpdateQueueId: getStateUpdateQueueId(follow, 'updated'),
|
|
4372
4427
|
stateUpdateQueue: this.stateUpdateQueue,
|
|
@@ -4377,13 +4432,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4377
4432
|
this.state.next((currentState) => {
|
|
4378
4433
|
let newState;
|
|
4379
4434
|
// this feed followed someone
|
|
4380
|
-
if (follow.source_feed.
|
|
4435
|
+
if (follow.source_feed.feed === currentFeedId) {
|
|
4381
4436
|
newState ?? (newState = {
|
|
4382
4437
|
...currentState,
|
|
4383
4438
|
// Update FeedResponse fields, that has the new follower/following count
|
|
4384
4439
|
...follow.source_feed,
|
|
4385
4440
|
});
|
|
4386
|
-
const index = currentState.following?.findIndex((f) => f.target_feed.
|
|
4441
|
+
const index = currentState.following?.findIndex((f) => f.target_feed.feed === follow.target_feed.feed) ?? -1;
|
|
4387
4442
|
if (index >= 0) {
|
|
4388
4443
|
newState.following = [...newState.following];
|
|
4389
4444
|
newState.following[index] = follow;
|
|
@@ -4391,7 +4446,7 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4391
4446
|
}
|
|
4392
4447
|
else if (
|
|
4393
4448
|
// someone followed this feed
|
|
4394
|
-
follow.target_feed.
|
|
4449
|
+
follow.target_feed.feed === currentFeedId) {
|
|
4395
4450
|
const source = follow.source_feed;
|
|
4396
4451
|
newState ?? (newState = {
|
|
4397
4452
|
...currentState,
|
|
@@ -4400,13 +4455,13 @@ function handleFollowUpdated(eventOrResponse) {
|
|
|
4400
4455
|
});
|
|
4401
4456
|
if (source.created_by.id === connectedUserId &&
|
|
4402
4457
|
currentState.own_follows) {
|
|
4403
|
-
const index = currentState.own_follows.findIndex((f) => f.source_feed.
|
|
4458
|
+
const index = currentState.own_follows.findIndex((f) => f.source_feed.feed === follow.source_feed.feed);
|
|
4404
4459
|
if (index >= 0) {
|
|
4405
4460
|
newState.own_follows = [...currentState.own_follows];
|
|
4406
4461
|
newState.own_follows[index] = follow;
|
|
4407
4462
|
}
|
|
4408
4463
|
}
|
|
4409
|
-
const index = currentState.followers?.findIndex((f) => f.source_feed.
|
|
4464
|
+
const index = currentState.followers?.findIndex((f) => f.source_feed.feed === follow.source_feed.feed) ?? -1;
|
|
4410
4465
|
if (index >= 0) {
|
|
4411
4466
|
newState.followers = [...newState.followers];
|
|
4412
4467
|
newState.followers[index] = follow;
|
|
@@ -4593,6 +4648,179 @@ function handleFeedMemberRemoved(event) {
|
|
|
4593
4648
|
});
|
|
4594
4649
|
}
|
|
4595
4650
|
|
|
4651
|
+
const sharedUpdateActivity$5 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4652
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4653
|
+
if (eventBelongsToCurrentUser) {
|
|
4654
|
+
newOwnBookmarks = [...newOwnBookmarks, event.bookmark];
|
|
4655
|
+
}
|
|
4656
|
+
return {
|
|
4657
|
+
...event.bookmark.activity,
|
|
4658
|
+
own_bookmarks: newOwnBookmarks,
|
|
4659
|
+
own_reactions: currentActivity.own_reactions,
|
|
4660
|
+
};
|
|
4661
|
+
};
|
|
4662
|
+
const addBookmarkToActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4663
|
+
entities: activities,
|
|
4664
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4665
|
+
updater: (matchedActivity) => sharedUpdateActivity$5({
|
|
4666
|
+
currentActivity: matchedActivity,
|
|
4667
|
+
event,
|
|
4668
|
+
eventBelongsToCurrentUser,
|
|
4669
|
+
}),
|
|
4670
|
+
});
|
|
4671
|
+
const addBookmarkToPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4672
|
+
entities: pinnedActivities,
|
|
4673
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4674
|
+
updater: (matchedPinnedActivity) => {
|
|
4675
|
+
const newActivity = sharedUpdateActivity$5({
|
|
4676
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4677
|
+
event,
|
|
4678
|
+
eventBelongsToCurrentUser,
|
|
4679
|
+
});
|
|
4680
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4681
|
+
return matchedPinnedActivity;
|
|
4682
|
+
}
|
|
4683
|
+
return {
|
|
4684
|
+
...matchedPinnedActivity,
|
|
4685
|
+
activity: newActivity,
|
|
4686
|
+
};
|
|
4687
|
+
},
|
|
4688
|
+
});
|
|
4689
|
+
function handleBookmarkAdded(event) {
|
|
4690
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4691
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4692
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4693
|
+
const [result1, result2] = [
|
|
4694
|
+
addBookmarkToActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4695
|
+
addBookmarkToPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4696
|
+
];
|
|
4697
|
+
if (result1.changed || result2.changed) {
|
|
4698
|
+
this.state.partialNext({
|
|
4699
|
+
activities: result1.entities,
|
|
4700
|
+
pinned_activities: result2.entities,
|
|
4701
|
+
});
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
|
|
4705
|
+
// Helper function to check if two bookmarks are the same
|
|
4706
|
+
// A bookmark is identified by activity_id + folder_id + user_id
|
|
4707
|
+
const isSameBookmark = (bookmark1, bookmark2) => {
|
|
4708
|
+
return (bookmark1.user.id === bookmark2.user.id &&
|
|
4709
|
+
bookmark1.activity.id === bookmark2.activity.id &&
|
|
4710
|
+
bookmark1.folder?.id === bookmark2.folder?.id);
|
|
4711
|
+
};
|
|
4712
|
+
const sharedUpdateActivity$4 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4713
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4714
|
+
if (eventBelongsToCurrentUser) {
|
|
4715
|
+
newOwnBookmarks = currentActivity.own_bookmarks.filter((bookmark) => !isSameBookmark(bookmark, event.bookmark));
|
|
4716
|
+
}
|
|
4717
|
+
return {
|
|
4718
|
+
...event.bookmark.activity,
|
|
4719
|
+
own_bookmarks: newOwnBookmarks,
|
|
4720
|
+
own_reactions: currentActivity.own_reactions,
|
|
4721
|
+
};
|
|
4722
|
+
};
|
|
4723
|
+
const removeBookmarkFromActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4724
|
+
entities: activities,
|
|
4725
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4726
|
+
updater: (matchedActivity) => sharedUpdateActivity$4({
|
|
4727
|
+
currentActivity: matchedActivity,
|
|
4728
|
+
event,
|
|
4729
|
+
eventBelongsToCurrentUser,
|
|
4730
|
+
}),
|
|
4731
|
+
});
|
|
4732
|
+
const removeBookmarkFromPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4733
|
+
entities: pinnedActivities,
|
|
4734
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4735
|
+
updater: (matchedPinnedActivity) => {
|
|
4736
|
+
const newActivity = sharedUpdateActivity$4({
|
|
4737
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4738
|
+
event,
|
|
4739
|
+
eventBelongsToCurrentUser,
|
|
4740
|
+
});
|
|
4741
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4742
|
+
return matchedPinnedActivity;
|
|
4743
|
+
}
|
|
4744
|
+
return {
|
|
4745
|
+
...matchedPinnedActivity,
|
|
4746
|
+
activity: newActivity,
|
|
4747
|
+
};
|
|
4748
|
+
},
|
|
4749
|
+
});
|
|
4750
|
+
function handleBookmarkDeleted(event) {
|
|
4751
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4752
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4753
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4754
|
+
const [result1, result2] = [
|
|
4755
|
+
removeBookmarkFromActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4756
|
+
removeBookmarkFromPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4757
|
+
];
|
|
4758
|
+
if (result1.changed || result2.changed) {
|
|
4759
|
+
this.state.partialNext({
|
|
4760
|
+
activities: result1.entities,
|
|
4761
|
+
pinned_activities: result2.entities,
|
|
4762
|
+
});
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
|
|
4766
|
+
const sharedUpdateActivity$3 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4767
|
+
let newOwnBookmarks = currentActivity.own_bookmarks;
|
|
4768
|
+
if (eventBelongsToCurrentUser) {
|
|
4769
|
+
const bookmarkIndex = newOwnBookmarks.findIndex((bookmark) => isSameBookmark(bookmark, event.bookmark));
|
|
4770
|
+
if (bookmarkIndex !== -1) {
|
|
4771
|
+
newOwnBookmarks = [...newOwnBookmarks];
|
|
4772
|
+
newOwnBookmarks[bookmarkIndex] = event.bookmark;
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
return {
|
|
4776
|
+
...event.bookmark.activity,
|
|
4777
|
+
own_bookmarks: newOwnBookmarks,
|
|
4778
|
+
own_reactions: currentActivity.own_reactions,
|
|
4779
|
+
};
|
|
4780
|
+
};
|
|
4781
|
+
const updateBookmarkInActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4782
|
+
entities: activities,
|
|
4783
|
+
matcher: (activity) => activity.id === event.bookmark.activity.id,
|
|
4784
|
+
updater: (matchedActivity) => sharedUpdateActivity$3({
|
|
4785
|
+
currentActivity: matchedActivity,
|
|
4786
|
+
event,
|
|
4787
|
+
eventBelongsToCurrentUser,
|
|
4788
|
+
}),
|
|
4789
|
+
});
|
|
4790
|
+
const updateBookmarkInPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4791
|
+
entities: pinnedActivities,
|
|
4792
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.bookmark.activity.id,
|
|
4793
|
+
updater: (matchedPinnedActivity) => {
|
|
4794
|
+
const newActivity = sharedUpdateActivity$3({
|
|
4795
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4796
|
+
event,
|
|
4797
|
+
eventBelongsToCurrentUser,
|
|
4798
|
+
});
|
|
4799
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4800
|
+
return matchedPinnedActivity;
|
|
4801
|
+
}
|
|
4802
|
+
return {
|
|
4803
|
+
...matchedPinnedActivity,
|
|
4804
|
+
activity: newActivity,
|
|
4805
|
+
};
|
|
4806
|
+
},
|
|
4807
|
+
});
|
|
4808
|
+
function handleBookmarkUpdated(event) {
|
|
4809
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4810
|
+
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4811
|
+
const eventBelongsToCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4812
|
+
const [result1, result2] = [
|
|
4813
|
+
updateBookmarkInActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
4814
|
+
updateBookmarkInPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
4815
|
+
];
|
|
4816
|
+
if (result1.changed || result2.changed) {
|
|
4817
|
+
this.state.partialNext({
|
|
4818
|
+
activities: result1.entities,
|
|
4819
|
+
pinned_activities: result2.entities,
|
|
4820
|
+
});
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
|
|
4596
4824
|
const addActivitiesToState = (newActivities, activities, position) => {
|
|
4597
4825
|
let result;
|
|
4598
4826
|
if (activities === undefined) {
|
|
@@ -4637,7 +4865,8 @@ function handleActivityAdded(event) {
|
|
|
4637
4865
|
}
|
|
4638
4866
|
|
|
4639
4867
|
const removeActivityFromState = (activityResponse, activities) => {
|
|
4640
|
-
const index = activities
|
|
4868
|
+
const index = activities?.findIndex((activity) => activity.id === activityResponse.id) ??
|
|
4869
|
+
-1;
|
|
4641
4870
|
if (index !== -1) {
|
|
4642
4871
|
const newActivities = [...activities];
|
|
4643
4872
|
newActivities.splice(index, 1);
|
|
@@ -4647,13 +4876,28 @@ const removeActivityFromState = (activityResponse, activities) => {
|
|
|
4647
4876
|
return { changed: false, activities };
|
|
4648
4877
|
}
|
|
4649
4878
|
};
|
|
4879
|
+
const removePinnedActivityFromState = (activityResponse, pinnedActivities) => {
|
|
4880
|
+
const index = pinnedActivities?.findIndex((pinnedActivity) => pinnedActivity.activity.id === activityResponse.id) ?? -1;
|
|
4881
|
+
if (index !== -1) {
|
|
4882
|
+
const newActivities = [...pinnedActivities];
|
|
4883
|
+
newActivities.splice(index, 1);
|
|
4884
|
+
return { changed: true, activities: newActivities };
|
|
4885
|
+
}
|
|
4886
|
+
else {
|
|
4887
|
+
return { changed: false, pinned_activities: pinnedActivities };
|
|
4888
|
+
}
|
|
4889
|
+
};
|
|
4650
4890
|
function handleActivityDeleted(event) {
|
|
4651
|
-
const currentActivities = this.currentState
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4891
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4892
|
+
const [result1, result2] = [
|
|
4893
|
+
removeActivityFromState(event.activity, currentActivities),
|
|
4894
|
+
removePinnedActivityFromState(event.activity, currentPinnedActivities),
|
|
4895
|
+
];
|
|
4896
|
+
if (result1.changed || result2.changed) {
|
|
4897
|
+
this.state.partialNext({
|
|
4898
|
+
activities: result1.activities,
|
|
4899
|
+
pinned_activities: result2.pinned_activities,
|
|
4900
|
+
});
|
|
4657
4901
|
}
|
|
4658
4902
|
}
|
|
4659
4903
|
|
|
@@ -4667,221 +4911,163 @@ function handleActivityRemovedFromFeed(event) {
|
|
|
4667
4911
|
}
|
|
4668
4912
|
}
|
|
4669
4913
|
|
|
4670
|
-
const
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4914
|
+
const sharedUpdateActivity$2 = ({ currentActivity, event, }) => {
|
|
4915
|
+
return {
|
|
4916
|
+
...event.activity,
|
|
4917
|
+
own_reactions: currentActivity.own_reactions,
|
|
4918
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
4919
|
+
};
|
|
4920
|
+
};
|
|
4921
|
+
const updateActivityInState = (event, activities) => updateEntityInArray({
|
|
4922
|
+
entities: activities,
|
|
4923
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
4924
|
+
updater: (matchedActivity) => sharedUpdateActivity$2({
|
|
4925
|
+
currentActivity: matchedActivity,
|
|
4926
|
+
event,
|
|
4927
|
+
}),
|
|
4928
|
+
});
|
|
4929
|
+
const updatePinnedActivityInState = (event, pinnedActivities) => updateEntityInArray({
|
|
4930
|
+
entities: pinnedActivities,
|
|
4931
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
4932
|
+
updater: (matchedPinnedActivity) => {
|
|
4933
|
+
const newActivity = sharedUpdateActivity$2({
|
|
4934
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4935
|
+
event,
|
|
4936
|
+
});
|
|
4937
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4938
|
+
return matchedPinnedActivity;
|
|
4686
4939
|
}
|
|
4687
|
-
return {
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
}
|
|
4692
|
-
};
|
|
4940
|
+
return {
|
|
4941
|
+
...matchedPinnedActivity,
|
|
4942
|
+
activity: newActivity,
|
|
4943
|
+
};
|
|
4944
|
+
},
|
|
4945
|
+
});
|
|
4693
4946
|
function handleActivityUpdated(event) {
|
|
4694
|
-
const currentActivities = this.currentState
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4947
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4948
|
+
const [result1, result2] = [
|
|
4949
|
+
updateActivityInState(event, currentActivities),
|
|
4950
|
+
updatePinnedActivityInState(event, currentPinnedActivities),
|
|
4951
|
+
];
|
|
4952
|
+
if (result1.changed || result2.changed) {
|
|
4953
|
+
this.client.hydratePollCache([event.activity]);
|
|
4954
|
+
this.state.partialNext({
|
|
4955
|
+
activities: result1.entities,
|
|
4956
|
+
pinned_activities: result2.entities,
|
|
4957
|
+
});
|
|
4701
4958
|
}
|
|
4702
4959
|
}
|
|
4703
4960
|
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
if (
|
|
4708
|
-
|
|
4961
|
+
// shared function to update the activity with the new reaction
|
|
4962
|
+
const sharedUpdateActivity$1 = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
4963
|
+
let newOwnReactions = currentActivity.own_reactions;
|
|
4964
|
+
if (eventBelongsToCurrentUser) {
|
|
4965
|
+
newOwnReactions = [...currentActivity.own_reactions, event.reaction];
|
|
4709
4966
|
}
|
|
4710
4967
|
return {
|
|
4711
|
-
...activity,
|
|
4712
|
-
own_reactions:
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4968
|
+
...event.activity,
|
|
4969
|
+
own_reactions: newOwnReactions,
|
|
4970
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
4971
|
+
};
|
|
4972
|
+
};
|
|
4973
|
+
const addReactionToActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4974
|
+
entities: activities,
|
|
4975
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
4976
|
+
updater: (matchedActivity) => sharedUpdateActivity$1({
|
|
4977
|
+
currentActivity: matchedActivity,
|
|
4978
|
+
event,
|
|
4979
|
+
eventBelongsToCurrentUser,
|
|
4980
|
+
}),
|
|
4981
|
+
});
|
|
4982
|
+
const addReactionToPinnedActivities = (event, pinnedActivities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
4983
|
+
entities: pinnedActivities,
|
|
4984
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
4985
|
+
updater: (matchedPinnedActivity) => {
|
|
4986
|
+
const newActivity = sharedUpdateActivity$1({
|
|
4987
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
4988
|
+
event,
|
|
4989
|
+
eventBelongsToCurrentUser,
|
|
4990
|
+
});
|
|
4991
|
+
// this should never happen, but just in case
|
|
4992
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
4993
|
+
return matchedPinnedActivity;
|
|
4994
|
+
}
|
|
4995
|
+
return {
|
|
4996
|
+
...matchedPinnedActivity,
|
|
4997
|
+
activity: newActivity,
|
|
4998
|
+
};
|
|
4999
|
+
},
|
|
5000
|
+
});
|
|
4730
5001
|
function handleActivityReactionAdded(event) {
|
|
4731
|
-
const currentActivities = this.currentState
|
|
5002
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
4732
5003
|
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4733
|
-
const
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
r.user.id === event.reaction.user.id))
|
|
4745
|
-
: activity.own_reactions;
|
|
4746
|
-
return {
|
|
4747
|
-
...activity,
|
|
4748
|
-
own_reactions: ownReactions,
|
|
4749
|
-
latest_reactions: event.activity.latest_reactions,
|
|
4750
|
-
reaction_groups: event.activity.reaction_groups,
|
|
4751
|
-
changed: true,
|
|
4752
|
-
};
|
|
4753
|
-
};
|
|
4754
|
-
const removeReactionFromActivities = (event, activities, isCurrentUser) => {
|
|
4755
|
-
if (!activities) {
|
|
4756
|
-
return { changed: false, activities: [] };
|
|
4757
|
-
}
|
|
4758
|
-
const activityIndex = activities.findIndex((a) => a.id === event.activity.id);
|
|
4759
|
-
if (activityIndex === -1) {
|
|
4760
|
-
return { changed: false, activities };
|
|
4761
|
-
}
|
|
4762
|
-
const activity = activities[activityIndex];
|
|
4763
|
-
const updatedActivity = removeReactionFromActivity(event, activity, isCurrentUser);
|
|
4764
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4765
|
-
};
|
|
4766
|
-
function handleActivityReactionDeleted(event) {
|
|
4767
|
-
const currentActivities = this.currentState.activities;
|
|
4768
|
-
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
4769
|
-
const isCurrentUser = Boolean(connectedUser && event.reaction.user.id === connectedUser.id);
|
|
4770
|
-
const result = removeReactionFromActivities(event, currentActivities, isCurrentUser);
|
|
4771
|
-
if (result.changed) {
|
|
4772
|
-
this.state.partialNext({ activities: result.activities });
|
|
4773
|
-
}
|
|
4774
|
-
}
|
|
4775
|
-
|
|
4776
|
-
const addBookmarkToActivity = (event, activity, isCurrentUser) => {
|
|
4777
|
-
// Update own_bookmarks if the bookmark is from the current user
|
|
4778
|
-
const ownBookmarks = [...(activity.own_bookmarks || [])];
|
|
4779
|
-
if (isCurrentUser) {
|
|
4780
|
-
ownBookmarks.push(event.bookmark);
|
|
4781
|
-
}
|
|
4782
|
-
return {
|
|
4783
|
-
...activity,
|
|
4784
|
-
own_bookmarks: ownBookmarks,
|
|
4785
|
-
changed: true,
|
|
4786
|
-
};
|
|
4787
|
-
};
|
|
4788
|
-
const addBookmarkToActivities = (event, activities, isCurrentUser) => {
|
|
4789
|
-
if (!activities) {
|
|
4790
|
-
return { changed: false, activities: [] };
|
|
4791
|
-
}
|
|
4792
|
-
const activityIndex = activities.findIndex((a) => a.id === event.bookmark.activity.id);
|
|
4793
|
-
if (activityIndex === -1) {
|
|
4794
|
-
return { changed: false, activities };
|
|
4795
|
-
}
|
|
4796
|
-
const activity = activities[activityIndex];
|
|
4797
|
-
const updatedActivity = addBookmarkToActivity(event, activity, isCurrentUser);
|
|
4798
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4799
|
-
};
|
|
4800
|
-
function handleBookmarkAdded(event) {
|
|
4801
|
-
const currentActivities = this.currentState.activities;
|
|
4802
|
-
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4803
|
-
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4804
|
-
const result = addBookmarkToActivities(event, currentActivities, isCurrentUser);
|
|
4805
|
-
if (result.changed) {
|
|
4806
|
-
this.state.partialNext({ activities: result.activities });
|
|
5004
|
+
const eventBelongsToCurrentUser = typeof connectedUser !== 'undefined' &&
|
|
5005
|
+
event.reaction.user.id === connectedUser.id;
|
|
5006
|
+
const [result1, result2] = [
|
|
5007
|
+
addReactionToActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
5008
|
+
addReactionToPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
5009
|
+
];
|
|
5010
|
+
if (result1.changed || result2.changed) {
|
|
5011
|
+
this.state.partialNext({
|
|
5012
|
+
activities: result1.entities,
|
|
5013
|
+
pinned_activities: result2.entities,
|
|
5014
|
+
});
|
|
4807
5015
|
}
|
|
4808
5016
|
}
|
|
4809
5017
|
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
bookmark1.folder?.id === bookmark2.folder?.id);
|
|
4816
|
-
};
|
|
4817
|
-
const removeBookmarkFromActivities = (event, activities, isCurrentUser) => {
|
|
4818
|
-
if (!activities) {
|
|
4819
|
-
return { changed: false, activities: [] };
|
|
4820
|
-
}
|
|
4821
|
-
const activityIndex = activities.findIndex((a) => a.id === event.bookmark.activity.id);
|
|
4822
|
-
if (activityIndex === -1) {
|
|
4823
|
-
return { changed: false, activities };
|
|
5018
|
+
const sharedUpdateActivity = ({ currentActivity, event, eventBelongsToCurrentUser, }) => {
|
|
5019
|
+
let newOwnReactions = currentActivity.own_reactions;
|
|
5020
|
+
if (eventBelongsToCurrentUser) {
|
|
5021
|
+
newOwnReactions = currentActivity.own_reactions.filter((reaction) => !(reaction.type === event.reaction.type &&
|
|
5022
|
+
reaction.user.id === event.reaction.user.id));
|
|
4824
5023
|
}
|
|
4825
|
-
const activity = activities[activityIndex];
|
|
4826
|
-
const updatedActivity = removeBookmarkFromActivity(event, activity, isCurrentUser);
|
|
4827
|
-
return updateActivityInState(updatedActivity, activities, true);
|
|
4828
|
-
};
|
|
4829
|
-
const removeBookmarkFromActivity = (event, activity, isCurrentUser) => {
|
|
4830
|
-
// Update own_bookmarks if the bookmark is from the current user
|
|
4831
|
-
const ownBookmarks = isCurrentUser
|
|
4832
|
-
? (activity.own_bookmarks || []).filter((bookmark) => !isSameBookmark(bookmark, event.bookmark))
|
|
4833
|
-
: activity.own_bookmarks;
|
|
4834
5024
|
return {
|
|
4835
|
-
...activity,
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
};
|
|
4839
|
-
};
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
}
|
|
4848
|
-
}
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
5025
|
+
...event.activity,
|
|
5026
|
+
own_reactions: newOwnReactions,
|
|
5027
|
+
own_bookmarks: currentActivity.own_bookmarks,
|
|
5028
|
+
};
|
|
5029
|
+
};
|
|
5030
|
+
const removeReactionFromActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
5031
|
+
entities: activities,
|
|
5032
|
+
matcher: (activity) => activity.id === event.activity.id,
|
|
5033
|
+
updater: (matchedActivity) => sharedUpdateActivity({
|
|
5034
|
+
currentActivity: matchedActivity,
|
|
5035
|
+
event,
|
|
5036
|
+
eventBelongsToCurrentUser,
|
|
5037
|
+
}),
|
|
5038
|
+
});
|
|
5039
|
+
const removeReactionFromPinnedActivities = (event, activities, eventBelongsToCurrentUser) => updateEntityInArray({
|
|
5040
|
+
entities: activities,
|
|
5041
|
+
matcher: (pinnedActivity) => pinnedActivity.activity.id === event.activity.id,
|
|
5042
|
+
updater: (matchedPinnedActivity) => {
|
|
5043
|
+
const newActivity = sharedUpdateActivity({
|
|
5044
|
+
currentActivity: matchedPinnedActivity.activity,
|
|
5045
|
+
event,
|
|
5046
|
+
eventBelongsToCurrentUser,
|
|
5047
|
+
});
|
|
5048
|
+
if (newActivity === matchedPinnedActivity.activity) {
|
|
5049
|
+
return matchedPinnedActivity;
|
|
4858
5050
|
}
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
const
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
const
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
const currentActivities = this.currentState.activities;
|
|
4880
|
-
const { connected_user: connectedUser } = this.client.state.getLatestValue();
|
|
4881
|
-
const isCurrentUser = event.bookmark.user.id === connectedUser?.id;
|
|
4882
|
-
const result = updateBookmarkInActivities(event, currentActivities, isCurrentUser);
|
|
4883
|
-
if (result.changed) {
|
|
4884
|
-
this.state.partialNext({ activities: result.activities });
|
|
5051
|
+
return {
|
|
5052
|
+
...matchedPinnedActivity,
|
|
5053
|
+
activity: newActivity,
|
|
5054
|
+
};
|
|
5055
|
+
},
|
|
5056
|
+
});
|
|
5057
|
+
function handleActivityReactionDeleted(event) {
|
|
5058
|
+
const { activities: currentActivities, pinned_activities: currentPinnedActivities, } = this.currentState;
|
|
5059
|
+
const connectedUser = this.client.state.getLatestValue().connected_user;
|
|
5060
|
+
const eventBelongsToCurrentUser = typeof connectedUser !== 'undefined' &&
|
|
5061
|
+
event.reaction.user.id === connectedUser.id;
|
|
5062
|
+
const [result1, result2] = [
|
|
5063
|
+
removeReactionFromActivities(event, currentActivities, eventBelongsToCurrentUser),
|
|
5064
|
+
removeReactionFromPinnedActivities(event, currentPinnedActivities, eventBelongsToCurrentUser),
|
|
5065
|
+
];
|
|
5066
|
+
if (result1.changed || result2.changed) {
|
|
5067
|
+
this.state.partialNext({
|
|
5068
|
+
activities: result1.entities,
|
|
5069
|
+
pinned_activities: result2.entities,
|
|
5070
|
+
});
|
|
4885
5071
|
}
|
|
4886
5072
|
}
|
|
4887
5073
|
|
|
@@ -4894,6 +5080,14 @@ function handleNotificationFeedUpdated(event) {
|
|
|
4894
5080
|
// TODO: handle notification feed updates
|
|
4895
5081
|
}
|
|
4896
5082
|
|
|
5083
|
+
function handleWatchStarted() {
|
|
5084
|
+
this.state.partialNext({ watch: true });
|
|
5085
|
+
}
|
|
5086
|
+
|
|
5087
|
+
function handleWatchStopped() {
|
|
5088
|
+
this.state.partialNext({ watch: false });
|
|
5089
|
+
}
|
|
5090
|
+
|
|
4897
5091
|
class Feed extends FeedApi {
|
|
4898
5092
|
constructor(client, groupId, id, data, watch = false) {
|
|
4899
5093
|
super(client, groupId, id);
|
|
@@ -4954,7 +5148,7 @@ class Feed extends FeedApi {
|
|
|
4954
5148
|
this.on = this.eventDispatcher.on;
|
|
4955
5149
|
this.off = this.eventDispatcher.off;
|
|
4956
5150
|
this.state = new StateStore({
|
|
4957
|
-
|
|
5151
|
+
feed: `${groupId}:${id}`,
|
|
4958
5152
|
group_id: groupId,
|
|
4959
5153
|
id,
|
|
4960
5154
|
...(data ?? {}),
|
|
@@ -4965,7 +5159,7 @@ class Feed extends FeedApi {
|
|
|
4965
5159
|
});
|
|
4966
5160
|
this.client = client;
|
|
4967
5161
|
}
|
|
4968
|
-
get
|
|
5162
|
+
get feed() {
|
|
4969
5163
|
return `${this.group}:${this.id}`;
|
|
4970
5164
|
}
|
|
4971
5165
|
get currentState() {
|
|
@@ -5040,22 +5234,6 @@ class Feed extends FeedApi {
|
|
|
5040
5234
|
});
|
|
5041
5235
|
}
|
|
5042
5236
|
}
|
|
5043
|
-
/**
|
|
5044
|
-
* @internal
|
|
5045
|
-
*/
|
|
5046
|
-
handleWatchStopped() {
|
|
5047
|
-
this.state.partialNext({
|
|
5048
|
-
watch: false,
|
|
5049
|
-
});
|
|
5050
|
-
}
|
|
5051
|
-
/**
|
|
5052
|
-
* @internal
|
|
5053
|
-
*/
|
|
5054
|
-
handleWatchStarted() {
|
|
5055
|
-
this.state.partialNext({
|
|
5056
|
-
watch: true,
|
|
5057
|
-
});
|
|
5058
|
-
}
|
|
5059
5237
|
/**
|
|
5060
5238
|
* Returns index of the provided comment object.
|
|
5061
5239
|
*/
|
|
@@ -5215,7 +5393,7 @@ class Feed extends FeedApi {
|
|
|
5215
5393
|
entityId: comment.id,
|
|
5216
5394
|
base: () => this.client.getCommentReplies({
|
|
5217
5395
|
...request,
|
|
5218
|
-
|
|
5396
|
+
id: comment.id,
|
|
5219
5397
|
// use known sort first (prevents broken pagination)
|
|
5220
5398
|
sort,
|
|
5221
5399
|
next: currentNextCursor,
|
|
@@ -5255,7 +5433,7 @@ class Feed extends FeedApi {
|
|
|
5255
5433
|
...currentState,
|
|
5256
5434
|
[type]: currentState[type] === undefined
|
|
5257
5435
|
? follows
|
|
5258
|
-
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.
|
|
5436
|
+
: uniqueArrayMerge(currentState[type], follows, (follow) => `${follow.source_feed.feed}-${follow.target_feed.feed}`),
|
|
5259
5437
|
[paginationKey]: {
|
|
5260
5438
|
...currentState[paginationKey],
|
|
5261
5439
|
next: newNextCursor,
|
|
@@ -5348,7 +5526,7 @@ class Feed extends FeedApi {
|
|
|
5348
5526
|
*/
|
|
5349
5527
|
async queryFollowers(request) {
|
|
5350
5528
|
const filter = {
|
|
5351
|
-
target_feed: this.
|
|
5529
|
+
target_feed: this.feed,
|
|
5352
5530
|
};
|
|
5353
5531
|
const response = await this.client.queryFollows({
|
|
5354
5532
|
filter,
|
|
@@ -5363,7 +5541,7 @@ class Feed extends FeedApi {
|
|
|
5363
5541
|
*/
|
|
5364
5542
|
async queryFollowing(request) {
|
|
5365
5543
|
const filter = {
|
|
5366
|
-
source_feed: this.
|
|
5544
|
+
source_feed: this.feed,
|
|
5367
5545
|
};
|
|
5368
5546
|
const response = await this.client.queryFollows({
|
|
5369
5547
|
filter,
|
|
@@ -5372,18 +5550,18 @@ class Feed extends FeedApi {
|
|
|
5372
5550
|
return response;
|
|
5373
5551
|
}
|
|
5374
5552
|
async follow(feedOrFid, options) {
|
|
5375
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5553
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5376
5554
|
const response = await this.client.follow({
|
|
5377
5555
|
...options,
|
|
5378
|
-
source: this.
|
|
5556
|
+
source: this.feed,
|
|
5379
5557
|
target: fid,
|
|
5380
5558
|
});
|
|
5381
5559
|
return response;
|
|
5382
5560
|
}
|
|
5383
5561
|
async unfollow(feedOrFid) {
|
|
5384
|
-
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.
|
|
5562
|
+
const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
|
|
5385
5563
|
const response = await this.client.unfollow({
|
|
5386
|
-
source: this.
|
|
5564
|
+
source: this.feed,
|
|
5387
5565
|
target: fid,
|
|
5388
5566
|
});
|
|
5389
5567
|
return response;
|
|
@@ -5407,7 +5585,7 @@ class Feed extends FeedApi {
|
|
|
5407
5585
|
addActivity(request) {
|
|
5408
5586
|
return this.feedsApi.addActivity({
|
|
5409
5587
|
...request,
|
|
5410
|
-
|
|
5588
|
+
feeds: [this.feed],
|
|
5411
5589
|
});
|
|
5412
5590
|
}
|
|
5413
5591
|
handleWSEvent(event) {
|
|
@@ -5425,6 +5603,24 @@ class Feed extends FeedApi {
|
|
|
5425
5603
|
}
|
|
5426
5604
|
Feed.noop = () => { };
|
|
5427
5605
|
|
|
5606
|
+
function handleUserUpdated(event) {
|
|
5607
|
+
this.state.next((currentState) => {
|
|
5608
|
+
let newState;
|
|
5609
|
+
const { connected_user } = currentState;
|
|
5610
|
+
if (connected_user && connected_user.id === event.user.id) {
|
|
5611
|
+
newState ?? (newState = {
|
|
5612
|
+
...currentState,
|
|
5613
|
+
});
|
|
5614
|
+
newState.connected_user = {
|
|
5615
|
+
...connected_user,
|
|
5616
|
+
...event.user,
|
|
5617
|
+
};
|
|
5618
|
+
}
|
|
5619
|
+
// TODO: update other users in user map (if/once applicable)
|
|
5620
|
+
return newState ?? currentState;
|
|
5621
|
+
});
|
|
5622
|
+
}
|
|
5623
|
+
|
|
5428
5624
|
class FeedsClient extends FeedsApi {
|
|
5429
5625
|
constructor(apiKey, options) {
|
|
5430
5626
|
const tokenManager = new TokenManager();
|
|
@@ -5532,7 +5728,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5532
5728
|
if (this.activeFeeds[fid]) {
|
|
5533
5729
|
const feed = this.activeFeeds[fid];
|
|
5534
5730
|
if (watch && !feed.currentState.watch) {
|
|
5535
|
-
|
|
5731
|
+
handleWatchStarted.bind(feed)();
|
|
5536
5732
|
}
|
|
5537
5733
|
return feed;
|
|
5538
5734
|
}
|
|
@@ -5568,7 +5764,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5568
5764
|
}
|
|
5569
5765
|
else {
|
|
5570
5766
|
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
5571
|
-
|
|
5767
|
+
handleWatchStopped.bind(activeFeed)();
|
|
5572
5768
|
}
|
|
5573
5769
|
}
|
|
5574
5770
|
break;
|
|
@@ -5648,6 +5844,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5648
5844
|
feeds.forEach((f) => f.handleWSEvent(event));
|
|
5649
5845
|
break;
|
|
5650
5846
|
}
|
|
5847
|
+
case 'user.updated': {
|
|
5848
|
+
handleUserUpdated.call(this, event);
|
|
5849
|
+
break;
|
|
5850
|
+
}
|
|
5651
5851
|
default: {
|
|
5652
5852
|
feed?.handleWSEvent(event);
|
|
5653
5853
|
}
|
|
@@ -5673,7 +5873,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5673
5873
|
}
|
|
5674
5874
|
}
|
|
5675
5875
|
async queryFeeds(request) {
|
|
5676
|
-
const response = await this.
|
|
5876
|
+
const response = await this._queryFeeds(request);
|
|
5677
5877
|
const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
|
|
5678
5878
|
return {
|
|
5679
5879
|
feeds,
|
|
@@ -5685,7 +5885,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5685
5885
|
}
|
|
5686
5886
|
async updateFollow(request) {
|
|
5687
5887
|
const response = await super.updateFollow(request);
|
|
5688
|
-
[
|
|
5888
|
+
[
|
|
5889
|
+
response.follow.source_feed.feed,
|
|
5890
|
+
response.follow.target_feed.feed,
|
|
5891
|
+
].forEach((fid) => {
|
|
5689
5892
|
const feed = this.activeFeeds[fid];
|
|
5690
5893
|
if (feed) {
|
|
5691
5894
|
handleFollowUpdated.bind(feed)(response);
|
|
@@ -5696,7 +5899,10 @@ class FeedsClient extends FeedsApi {
|
|
|
5696
5899
|
// For follow API endpoints we update the state after HTTP response to allow queryFeeds with watch: false
|
|
5697
5900
|
async follow(request) {
|
|
5698
5901
|
const response = await super.follow(request);
|
|
5699
|
-
[
|
|
5902
|
+
[
|
|
5903
|
+
response.follow.source_feed.feed,
|
|
5904
|
+
response.follow.target_feed.feed,
|
|
5905
|
+
].forEach((fid) => {
|
|
5700
5906
|
const feed = this.activeFeeds[fid];
|
|
5701
5907
|
if (feed) {
|
|
5702
5908
|
handleFollowCreated.bind(feed)(response);
|
|
@@ -5707,7 +5913,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5707
5913
|
async followBatch(request) {
|
|
5708
5914
|
const response = await super.followBatch(request);
|
|
5709
5915
|
response.follows.forEach((follow) => {
|
|
5710
|
-
const feed = this.activeFeeds[follow.source_feed.
|
|
5916
|
+
const feed = this.activeFeeds[follow.source_feed.feed];
|
|
5711
5917
|
if (feed) {
|
|
5712
5918
|
handleFollowCreated.bind(feed)({ follow });
|
|
5713
5919
|
}
|
|
@@ -5732,7 +5938,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5732
5938
|
});
|
|
5733
5939
|
const feed = this.activeFeeds[`${request.feed_group_id}:${request.feed_id}`];
|
|
5734
5940
|
if (feed) {
|
|
5735
|
-
|
|
5941
|
+
handleWatchStopped.bind(feed)();
|
|
5736
5942
|
}
|
|
5737
5943
|
return response;
|
|
5738
5944
|
}
|
|
@@ -6126,12 +6332,12 @@ const useReactionActions = ({ entity, type, }) => {
|
|
|
6126
6332
|
const hasOwnReaction = useMemo(() => !!entity.own_reactions?.find((r) => r.type === type), [entity.own_reactions, type]);
|
|
6127
6333
|
const addReaction = useStableCallback(async () => {
|
|
6128
6334
|
await (isComment
|
|
6129
|
-
? client?.addCommentReaction({
|
|
6335
|
+
? client?.addCommentReaction({ id: entity.id, type })
|
|
6130
6336
|
: client?.addReaction({ activity_id: entity.id, type }));
|
|
6131
6337
|
});
|
|
6132
6338
|
const removeReaction = useStableCallback(async () => {
|
|
6133
6339
|
await (isComment
|
|
6134
|
-
? client?.deleteCommentReaction({
|
|
6340
|
+
? client?.deleteCommentReaction({ id: entity.id, type })
|
|
6135
6341
|
: client?.deleteActivityReaction({
|
|
6136
6342
|
activity_id: entity.id,
|
|
6137
6343
|
type,
|