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