Skip to content

Commit

Permalink
fix: handle empty display_name
Browse files Browse the repository at this point in the history
  • Loading branch information
rosnovsky committed Mar 8, 2024
1 parent 8104b8b commit 30a6d52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/generateMastodonEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const generateMastodonEmbed = async ({

return embedData;
} catch (error) {
console.error("Error fetching Mastodon post", error);
return null;
}
};
10 changes: 8 additions & 2 deletions src/utils/convertors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const convertResponseToData = (
!response.account ||
!response.account.url ||
!response.account.username ||
!response.account.display_name ||
!response.account.avatar ||
!response.created_at
) {
console.error("Invalid Mastodon response", response);
return null;
}

Expand All @@ -34,7 +34,13 @@ export const convertResponseToData = (
card,
emojis,
} = response;
const { url: accountUrl, username, display_name, avatar } = account;
const { url: accountUrl, username, avatar } = account;

// NOTE: sometimes instances return empty display_name, so we use the username as a fallback
let display_name = account.display_name;
if (!account.display_name) {
display_name = username;
}

return {
content,
Expand Down
1 change: 1 addition & 0 deletions src/utils/demoPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const demoPosts = [
"@thisismissem@hachyderm.io:112022457133862143", // with embedded github card
"@rosnovsky@lounge.town:111943084834223099", // with embedded youtube card
"@DrOinFLA@lounge.town:111605128127230772", // with custom emoji
"@AsyncX@mastodon.social:112054527697723909", // Issue #25, emplty display_name returned by mastodon.social
];

0 comments on commit 30a6d52

Please sign in to comment.