Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Frontend
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
825
Issues
825
List
Boards
Labels
Service Desk
Milestones
Merge Requests
68
Merge Requests
68
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Frontend
Commits
ce7d236f
Commit
ce7d236f
authored
1 hour ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(fix): working with production data
parent
6e082b1f
refactor/es-feeds
1 merge request
!373
Refactor/es feeds
Pipeline
#67714157
passed with stage
in 7 minutes and 43 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
25 deletions
+80
-25
entities.service.ts
src/app/common/services/entities.service.ts
+15
-6
feeds.service.ts
src/app/common/services/feeds.service.ts
+29
-7
sorted.component.ts
src/app/modules/newsfeed/feeds/sorted.component.ts
+9
-3
subscribed.component.ts
src/app/modules/newsfeed/feeds/subscribed.component.ts
+27
-9
No files found.
src/app/common/services/entities.service.ts
View file @
ce7d236f
...
...
@@ -31,15 +31,20 @@ export class EntitiesService {
const
entities
=
[];
for
(
const
feedItem
of
feed
)
{
if
(
!
this
.
entities
[
feed
.
urn
])
{
urnsToFetch
.
push
(
feed
.
urn
);
if
(
feedItem
.
entity
)
{
this
.
entities
[
feedItem
.
urn
]
=
feedItem
.
entity
;
}
if
(
!
this
.
entities
[
feedItem
.
urn
])
{
urnsToFetch
.
push
(
feedItem
.
urn
);
}
}
await
this
.
fetch
(
urnsToFetch
);
if
(
urnsToFetch
.
length
)
{
await
this
.
fetch
(
urnsToFetch
);
}
for
(
const
feedItem
of
feed
)
{
entities
.
push
(
this
.
entities
[
feed
.
urn
]);
entities
.
push
(
this
.
entities
[
feed
Item
.
urn
]);
}
return
entities
;
...
...
@@ -51,6 +56,10 @@ export class EntitiesService {
* @return Object
*/
async
single
(
urn
:
string
):
Promise
<
Object
|
false
>
{
if
(
urn
.
indexOf
(
'urn:'
)
<
0
)
{
// not a urn, so treat as a guid
urn
=
`urn:activity:
${
urn
}
`
;
// and assume activity
}
if
(
!
this
.
entities
[
urn
])
{
await
this
.
fetch
([
urn
]);
}
...
...
@@ -59,9 +68,9 @@ export class EntitiesService {
async
fetch
(
urns
:
string
[]):
Promise
<
Array
<
Object
>>
{
const
response
:
any
=
this
.
client
.
get
(
'api/v2/entities/'
,
{
urns
});
const
response
:
any
=
await
this
.
client
.
get
(
'api/v2/entities/'
,
{
urns
});
for
(
le
t
entity
of
response
.
entities
)
{
for
(
cons
t
entity
of
response
.
entities
)
{
this
.
entities
[
entity
.
urn
]
=
entity
;
}
...
...
This diff is collapsed.
Click to expand it.
src/app/common/services/feeds.service.ts
View file @
ce7d236f
...
...
@@ -13,7 +13,7 @@ import FeedsSync from '../../lib/minds-sync/services/FeedsSync.js';
import
hashCode
from
"../../helpers/hash-code"
;
import
AsyncStatus
from
"../../helpers/async-status"
;
import
{
BehaviorSubject
,
Observable
,
of
,
forkJoin
}
from
"rxjs"
;
import
{
take
,
switchMap
,
map
}
from
"rxjs/operators"
;
import
{
take
,
switchMap
,
map
,
tap
}
from
"rxjs/operators"
;
export
type
FeedsServiceGetParameters
=
{
endpoint
:
string
;
...
...
@@ -43,10 +43,11 @@ export class FeedsService {
limit
:
BehaviorSubject
<
number
>
=
new
BehaviorSubject
(
12
);
offset
:
BehaviorSubject
<
number
>
=
new
BehaviorSubject
(
0
);
endpoint
:
string
=
''
;
params
:
any
=
{
sync
:
1
};
rawFeed
:
BehaviorSubject
<
Object
[]
>
=
new
BehaviorSubject
([]);
feed
:
Observable
<
Object
[]
>
;
inProgress
:
BehaviorSubject
<
boolean
>
=
new
BehaviorSubject
(
fals
e
);
inProgress
:
BehaviorSubject
<
boolean
>
=
new
BehaviorSubject
(
tru
e
);
hasMore
:
Observable
<
boolean
>
;
constructor
(
...
...
@@ -56,12 +57,20 @@ export class FeedsService {
protected
blockListService
:
BlockListService
,
)
{
this
.
feed
=
this
.
rawFeed
.
pipe
(
take
(
this
.
limit
.
getValue
()
+
this
.
offset
.
getValue
()),
tap
(()
=>
{
this
.
inProgress
.
next
(
true
);
}),
map
(
feed
=>
feed
.
slice
(
0
,
this
.
limit
.
getValue
()
+
this
.
offset
.
getValue
())),
switchMap
(
feed
=>
this
.
entitiesService
.
getFromFeed
(
feed
)),
tap
(()
=>
{
if
(
this
.
offset
.
getValue
()
>
0
)
{
this
.
inProgress
.
next
(
false
);
}
}),
);
this
.
hasMore
=
this
.
rawFeed
.
pipe
(
map
(
feed
=>
{
return
(
this
.
limit
.
getValue
()
+
this
.
offset
.
getValue
())
<
feed
.
length
;
return
this
.
inProgress
.
getValue
()
||
(
this
.
limit
.
getValue
()
+
this
.
offset
.
getValue
())
<
feed
.
length
;
}),
);
}
...
...
@@ -76,6 +85,14 @@ export class FeedsService {
return
this
;
}
setParams
(
params
):
FeedsService
{
this
.
params
=
params
;
if
(
!
params
.
sync
)
{
this
.
params
.
sync
=
1
;
}
return
this
;
}
setOffset
(
offset
:
number
):
FeedsService
{
this
.
offset
.
next
(
offset
);
return
this
;
...
...
@@ -83,19 +100,24 @@ export class FeedsService {
fetch
():
FeedsService
{
this
.
inProgress
.
next
(
true
);
this
.
client
.
get
(
this
.
endpoint
)
this
.
client
.
get
(
this
.
endpoint
,
{...
this
.
params
,
...{
limit
:
150
}})
// Over 12 scrolls
.
then
((
response
:
any
)
=>
{
this
.
inProgress
.
next
(
false
);
this
.
rawFeed
.
next
(
response
.
entities
);
})
.
catch
(
err
=>
{
this
.
inProgress
.
next
(
false
);
});
return
this
;
}
loadMore
():
FeedsService
{
this
.
setOffset
(
this
.
limit
.
getValue
()
+
this
.
offset
.
getValue
());
this
.
rawFeed
.
next
(
this
.
rawFeed
.
getValue
());
return
this
;
}
clear
():
FeedsService
{
this
.
offset
.
next
(
0
);
this
.
inProgress
.
next
(
true
);
this
.
rawFeed
.
next
([]);
return
this
;
}
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/newsfeed/feeds/sorted.component.ts
View file @
ce7d236f
...
...
@@ -205,7 +205,14 @@ export class NewsfeedSortedComponent implements OnInit, OnDestroy {
const
nsfw
=
(
this
.
newsfeedService
.
nsfw
||
[]).
join
(
','
);
this
.
feedsService
.
setEndpoint
(
`api/v2/feeds/global/
${
this
.
algorithm
}
/
${
this
.
customType
}
?hashtags=
${
hashtags
}
&period=
${
period
}
&all=
${
all
}
&query=
${
query
}
&nsfw=
${
nsfw
}
`
)
.
setEndpoint
(
`api/v2/feeds/global/
${
this
.
algorithm
}
/
${
this
.
customType
}
`
)
.
setParams
({
hashtags
,
period
,
all
,
query
,
nsfw
,
})
.
setLimit
(
12
)
.
fetch
();
...
...
@@ -217,8 +224,7 @@ export class NewsfeedSortedComponent implements OnInit, OnDestroy {
}
loadMore
()
{
console
.
log
(
'loading more'
);
//this.feedsService.setOffset(this.feedsService.offset.getValue() + 12);
this
.
feedsService
.
loadMore
();
}
delete
(
activity
)
{
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/newsfeed/feeds/subscribed.component.ts
View file @
ce7d236f
...
...
@@ -120,7 +120,7 @@ export class NewsfeedSubscribedComponent {
loadNext
()
{
if
(
this
.
featuresService
.
has
(
'es-feeds'
))
{
this
.
feedsService
.
setOffset
(
this
.
feedsService
.
offset
.
getValue
()
+
12
);
this
.
feedsService
.
loadMore
(
);
}
else
{
this
.
loadLegacy
();
}
...
...
@@ -142,7 +142,7 @@ export class NewsfeedSubscribedComponent {
try
{
this
.
feedsService
.
setEndpoint
(
`api/v2/feeds/
container/
subscribed/activities`
)
.
setEndpoint
(
`api/v2/feeds/subscribed/activities`
)
.
setLimit
(
12
)
.
fetch
();
...
...
@@ -156,14 +156,17 @@ export class NewsfeedSubscribedComponent {
* Load newsfeed
*/
loadLegacy
(
refresh
:
boolean
=
false
)
{
if
(
this
.
feedsService
.
inProgress
.
getValue
())
return
false
;
if
(
this
.
inProgress
)
return
;
if
(
refresh
)
{
this
.
offset
=
''
;
this
.
feedsService
.
clear
();
}
this
.
feedsService
.
inProgress
.
next
(
true
);
this
.
inProgress
=
true
;
this
.
client
.
get
(
'api/v1/newsfeed'
,
{
limit
:
12
,
offset
:
this
.
offset
},
{
cache
:
true
})
.
then
((
data
:
MindsActivityObject
)
=>
{
...
...
@@ -172,16 +175,31 @@ export class NewsfeedSubscribedComponent {
this
.
feedsService
.
inProgress
.
next
(
false
);
return
false
;
}
if
(
this
.
newsfeed
&&
!
refresh
)
{
this
.
feedsService
.
rawFeed
.
next
([...
this
.
feedsService
.
rawFeed
.
getValue
(),
...
data
.
activity
]);
const
feedItems
=
[];
for
(
const
entity
of
data
.
activity
)
{
feedItems
.
push
({
urn
:
entity
.
urn
,
guid
:
entity
.
guid
,
owner_guid
:
entity
.
owner_guid
,
entity
:
entity
,
});
}
this
.
feedsService
.
setOffset
(
this
.
feedsService
.
offset
.
getValue
()
+
12
);
// Hacky!
if
(
this
.
feedsService
.
rawFeed
.
getValue
()
&&
!
refresh
)
{
this
.
feedsService
.
rawFeed
.
next
([...
this
.
feedsService
.
rawFeed
.
getValue
(),
...
feedItems
]);
}
else
{
this
.
feedsService
.
rawFeed
.
next
(
data
.
activity
);
this
.
feedsService
.
rawFeed
.
next
(
feedItems
);
}
this
.
offset
=
data
[
'load-next'
];
this
.
feedsService
.
inProgress
.
next
(
false
)
;
this
.
inProgress
=
false
;
})
.
catch
((
e
)
=>
{
this
.
feedsService
.
inProgress
.
next
(
false
);
console
.
error
(
e
);
this
.
inProgress
=
false
;
});
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment