Skip to content

Commit

Permalink
fix: compute restricted types in statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
sky3d authored and AVVS committed Jan 17, 2023
1 parent 097afeb commit 7380931
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
10 changes: 1 addition & 9 deletions src/services/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,10 @@ class Feed {
throw new HttpStatusError(400, 'the "account" parameter must be a string or an array');
}

let restrictedTypes;
try {
restrictedTypes = this.service('twitter').statusesRestrictedTypes();
} catch (e) {
this.logger.info(e);
restrictedTypes = [];
}

return this
.service('storage')
.twitterStatuses()
.list(data, restrictedTypes);
.list(data);
}

async remove(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const instagramMedia = new WeakMap();
const twitterStatuses = new WeakMap();

class Storage {
constructor(knex) {
constructor(knex, config) {
this.client = knex;

facebookMedia.set(this, new FacebookMedia(knex, 'facebook_media'));
feeds.set(this, new Feeds(knex, 'feeds'));
instagramMedia.set(this, new InstagramMedia(knex, 'instagram_media'));
twitterStatuses.set(this, new TwitterStatuses(knex, 'statuses'));
twitterStatuses.set(this, new TwitterStatuses(knex, 'statuses', config.twitter));
}

facebookMedia() {
Expand Down
14 changes: 10 additions & 4 deletions src/services/storage/twitter-statuses.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
const { TweetTypeByName } = require('../twitter/tweet-types');

class TwitterStatuses {
constructor(knex, table) {
constructor(knex, table, config) {
this.knex = knex;
this.table = table;

const { restrictedTypes: names = [] } = config.requests || {};

this.restrictedTypes = names.map((name) => TweetTypeByName[name]);
}

save(data) {
return this.knex.upsertItem(this.table, 'id', data);
}

list(data, restrictedTypes = []) {
list(data) {
const {
page,
pageSize,
Expand All @@ -30,8 +36,8 @@ class TwitterStatuses {
.select()
.whereRaw(rawQuery, [account]);

if (restrictedTypes.length) {
query.whereNotIn('type', restrictedTypes);
if (this.restrictedTypes.length) {
query.whereNotIn('type', this.restrictedTypes);
}

query
Expand Down
2 changes: 1 addition & 1 deletion src/social.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Social extends Microfleet {
}

initStorage() {
this.service(Social.SERVICE_STORAGE, new Storage(this.knex));
this.service(Social.SERVICE_STORAGE, new Storage(this.knex, this.config));
}

initFeed() {
Expand Down

0 comments on commit 7380931

Please sign in to comment.