Skip to content

Commit

Permalink
fix: use user's avatar in posts
Browse files Browse the repository at this point in the history
  • Loading branch information
manekenpix committed Oct 10, 2022
1 parent f612437 commit 3026cef
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 8,216 deletions.
16 changes: 13 additions & 3 deletions src/api/parser/src/data/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { deletePost } = require('../utils/indexer');
const urlToId = (url) => hash(normalizeUrl(url));

class Feed {
constructor(author, url, user, link, etag, lastModified) {
constructor(author, url, user, link, etag, lastModified, githubUsername) {
if (!url) {
throw new Error('missing url for feed');
}
Expand All @@ -43,6 +43,7 @@ class Feed {
// We may or may not have these cache values when we create a feed.
this.etag = etag === '' ? null : etag;
this.lastModified = lastModified === '' ? null : lastModified;
this.githubUsername = githubUsername || null;
}

/**
Expand Down Expand Up @@ -144,7 +145,8 @@ class Feed {
feedData.user,
feedData.link,
feedData.etag,
feedData.lastModified
feedData.lastModified,
feedData.githubUsername
);
await feed.save();
return feed.id;
Expand All @@ -161,7 +163,15 @@ class Feed {
if (!(data && data.id)) {
return null;
}
return new Feed(data.author, data.url, data.user, data.link, data.etag, data.lastModified);
return new Feed(
data.author,
data.url,
data.user,
data.link,
data.etag,
data.lastModified,
data.githubUsername
);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/api/parser/src/utils/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ module.exports = {
'etag',
feed.etag,
'lastModified',
feed.lastModified
feed.lastModified,
'githubUsername',
feed.githubUsername
)
.sadd(feedsKey, feed.id)
.exec();
Expand Down Expand Up @@ -99,7 +101,7 @@ module.exports = {
try {
await redis
.multi()
.hdel(key, 'id', 'author', 'url', 'user', 'link', 'etag', 'lastModified')
.hdel(key, 'id', 'author', 'url', 'user', 'link', 'etag', 'lastModified', 'githubUsername')
.srem(feedsKey, id)
.exec();
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/parser/src/utils/supabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
async getAllFeeds() {
const { data, error } = await supabase
.from('feeds')
.select('wiki_author_name, url, telescope_profiles (display_name)');
.select('wiki_author_name, url, telescope_profiles (display_name, github_username)');

if (error) {
logger.error({ error });
Expand All @@ -27,6 +27,7 @@ module.exports = {
// Prefer the a user's display name if present, fallback to wiki name otherwise
author: feed.telescope_profiles?.display_name || feed.wiki_author_name,
url: feed.url,
githubUsername: feed.telescope_profiles?.github_username,
}));
},

Expand Down
28 changes: 25 additions & 3 deletions src/api/parser/test/feed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Post data class tests', () => {
link: 'https://user.feed.com/',
etag: null,
lastModified: null,
githubUsername: 'github User 1',
};

const data2 = {
Expand All @@ -27,6 +28,7 @@ describe('Post data class tests', () => {
link: 'https://user2.feed.com/',
etag: null,
lastModified: null,
githubUsername: 'github User 2',
};

const data3 = {
Expand All @@ -36,9 +38,11 @@ describe('Post data class tests', () => {
link: 'https://user3.feed.com/',
etag: null,
lastModified: null,
githubUsername: 'github User 3',
};

const createFeed = () => new Feed(data.author, data.url, data.user, data.link, null, null);
const createFeed = () =>
new Feed(data.author, data.url, data.user, data.link, null, null, data.githubUsername);

const articleData1 = {
guid: 'http://dev.telescope.cdot.systems',
Expand Down Expand Up @@ -80,7 +84,15 @@ describe('Post data class tests', () => {

describe('Get and Set Feed objects from database', () => {
beforeAll(async () => {
const feed = new Feed(data.author, data.url, data.user, data.link, null, null);
const feed = new Feed(
data.author,
data.url,
data.user,
data.link,
null,
null,
data.githubUsername
);
__setMockFeeds([feed]);
await feed.save();
});
Expand All @@ -93,6 +105,7 @@ describe('Post data class tests', () => {
expect(feed.id).toEqual(data.id);
expect(feed.link).toEqual(data.link);
expect(feed.user).toEqual(data.user);
expect(feed.githubUsername).toEqual(data.githubUsername);
});

test('Feed.byId() for an invalid id should return null', async () => {
Expand All @@ -108,6 +121,7 @@ describe('Post data class tests', () => {
expect(feed.id).toEqual(data.id);
expect(feed.link).toEqual(data.link);
expect(feed.user).toEqual(data.user);
expect(feed.githubUsername).toEqual(data.githubUsername);
});

test('Feed.byUrl() for an invalid url should return null', async () => {
Expand Down Expand Up @@ -147,7 +161,15 @@ describe('Post data class tests', () => {
});

test('Updated feed should be different from data', async () => {
const feed = new Feed(data.author, data.url, data.user, data.link, null, null);
const feed = new Feed(
data.author,
data.url,
data.user,
data.link,
null,
null,
data.githubUsername
);
feed.author = 'Author Post';
feed.url = 'https://modified.user.feed.com/feed.rss';
__setMockFeeds([feed]);
Expand Down
16 changes: 13 additions & 3 deletions src/api/posts/src/data/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {
const urlToId = (url) => hash(normalizeUrl(url));

class Feed {
constructor(author, url, user, link, etag, lastModified) {
constructor(author, url, user, link, etag, lastModified, githubUsername) {
if (!url) {
throw new Error('missing url for feed');
}
Expand All @@ -38,6 +38,7 @@ class Feed {
// We may or may not have these cache values when we create a feed.
this.etag = etag === '' ? null : etag;
this.lastModified = lastModified === '' ? null : lastModified;
this.githubUsername = githubUsername || null;
}

/**
Expand Down Expand Up @@ -134,7 +135,8 @@ class Feed {
feedData.user,
feedData.link,
feedData.etag,
feedData.lastModified
feedData.lastModified,
feedData.githubUsername
);
await feed.save();
return feed.id;
Expand All @@ -151,7 +153,15 @@ class Feed {
if (!(data && data.id)) {
return null;
}
return new Feed(data.author, data.url, data.user, data.link, data.etag, data.lastModified);
return new Feed(
data.author,
data.url,
data.user,
data.link,
data.etag,
data.lastModified,
data.githubUsername
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/posts/src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports = {
try {
await redis
.multi()
.hdel(key, 'id', 'author', 'url', 'user', 'link', 'etag', 'lastModified')
.hdel(key, 'id', 'author', 'url', 'user', 'link', 'etag', 'lastModified', 'githubUsername')
.srem(redisKey, id)
.exec();
} catch (error) {
Expand Down
Loading

0 comments on commit 3026cef

Please sign in to comment.