...
 
......@@ -46,7 +46,10 @@ export class FeaturedContentComponent implements OnInit {
async load() {
try {
this.entity = await this.featuredContentService.fetch();
console.log('featuredContentService.fetch() : ' + this.entity.guid);
/** TODO: Remove debug line */
console.log(
'BOOST slot:' + this.slot + ' entity.guid: ' + this.entity.guid
);
} catch (e) {
console.error('FeaturedContentComponent.load', e);
}
......
......@@ -4,31 +4,63 @@ import { FeedsService } from '../../services/feeds.service';
@Injectable()
export class FeaturedContentService {
offset: number = -1;
maximumOffset: number = 0;
offset = -1;
maximumOffset = 0;
maximumEmptyFetch = 5;
emptyFetchCount = 0;
feedLength = 0;
constructor(protected feedsService: FeedsService) {
this.feedsService.feed.subscribe(feed => {
/** TODO: Remove debug line */
console.log('BOOST feed.length: ' + feed.length);
this.feedLength = feed.length;
this.maximumOffset = this.feedLength - 1;
if (this.feedLength > 0) {
this.emptyFetchCount = 0;
}
});
this.feedsService
.setLimit(12)
.setOffset(0)
.setEndpoint('api/v2/boost/feed')
.fetch();
this.feedsService.feed.subscribe(feed => {
this.maximumOffset = feed.length - 1;
});
}
async fetch() {
if (this.feedReset()) {
this.fetchNextFeed();
}
this.retryFetchIfNoFeedData();
return this.entityFromFeed();
}
protected feedReset(): boolean {
if (this.offset++ >= this.maximumOffset) {
this.offset = 0;
this.fetchNextFeed();
return true;
}
return this.entityFromFeed();
return false;
}
protected retryFetchIfNoFeedData() {
while (
this.feedLength === 0 &&
this.emptyFetchCount < this.maximumEmptyFetch
) {
/** TODO: Remove Debug Line */
console.log('BOOST retry fetch - no feed data');
this.emptyFetchCount++;
this.feedsService.fetch();
}
}
protected async entityFromFeed() {
/** TODO: Remove debug line */
console.log('BOOST featuredContentService.offset : ' + this.offset);
return await this.feedsService.feed
.pipe(
filter(item => item.length > 0),
......
......@@ -4,13 +4,6 @@ import { Client } from '../../services/api/client';
import { Session } from '../../services/session';
import { Storage } from '../../services/storage';
import AsyncLock from '../../helpers/async-lock';
import MindsClientHttpAdapter from '../../lib/minds-sync/adapters/MindsClientHttpAdapter.js';
import browserStorageAdapterFactory from '../../helpers/browser-storage-adapter-factory';
import BlockListSync from '../../lib/minds-sync/services/BlockListSync.js';
import AsyncStatus from '../../helpers/async-status';
@Injectable()
export class BlockListService {
blocked: BehaviorSubject<string[]>;
......
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { first, catchError } from 'rxjs/operators';
import { BehaviorSubject } from 'rxjs';
import { first } from 'rxjs/operators';
import { Client } from '../../services/api';
import { BlockListService } from './block-list.service';
import MindsClientHttpAdapter from '../../lib/minds-sync/adapters/MindsClientHttpAdapter.js';
import browserStorageAdapterFactory from '../../helpers/browser-storage-adapter-factory';
import EntitiesSync from '../../lib/minds-sync/services/EntitiesSync.js';
import AsyncStatus from '../../helpers/async-status';
import normalizeUrn from '../../helpers/normalize-urn';
type EntityObservable = BehaviorSubject<Object>;
type EntityObservables = Map<string, EntityObservable>;
......
......@@ -6,40 +6,8 @@ import { Session } from '../../services/session';
import { EntitiesService } from './entities.service';
import { BlockListService } from './block-list.service';
import MindsClientHttpAdapter from '../../lib/minds-sync/adapters/MindsClientHttpAdapter.js';
import browserStorageAdapterFactory from '../../helpers/browser-storage-adapter-factory';
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, combineLatest } from 'rxjs';
import {
take,
switchMap,
map,
tap,
skipWhile,
first,
filter,
} from 'rxjs/operators';
export type FeedsServiceGetParameters = {
endpoint: string;
timebased: boolean;
//
limit: number;
offset?: number;
//
syncPageSize?: number;
forceSync?: boolean;
};
export type FeedsServiceGetResponse = {
entities: any[];
next?: number;
};
import { BehaviorSubject, Observable, combineLatest } from 'rxjs';
import { switchMap, map, tap, first } from 'rxjs/operators';
/**
* Enables the grabbing of data through observable feeds.
......@@ -69,6 +37,7 @@ export class FeedsService {
this.pageSize = this.offset.pipe(
map(offset => this.limit.getValue() + offset)
);
this.feed = this.rawFeed.pipe(
tap(feed => {
if (feed.length) this.inProgress.next(true);
......@@ -87,6 +56,7 @@ export class FeedsService {
this.inProgress.next(false);
})
);
this.hasMore = combineLatest(
this.rawFeed,
this.inProgress,
......