Skip to content

Commit

Permalink
fix: Use email as default name (#107)
Browse files Browse the repository at this point in the history
Quick workaround for missing names and broken redirect

Refs GH-101
  • Loading branch information
dcramer committed Feb 9, 2023
1 parent 2155e7e commit 0e79b13
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true
},
"files.associations": {
"*.yaml": "home-assistant"
}
}
4 changes: 3 additions & 1 deletion app/components/clustered-post-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export default ({ category, posts, reactions, commentCounts }) => {
<Avatar size="24px" user={post.author} />

<Name>
<Link to={`/u/${post.author.email}`}>{post.author.name}</Link>
<Link to={`/u/${post.author.email}`}>
{post.author.name || post.author.email}
</Link>
</Name>
<Meta>
<Middot />
Expand Down
5 changes: 4 additions & 1 deletion app/components/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const ParentComment = ({
<ParentCommentContainer>
<input type="hidden" name="parentId" value={comment.id} />
<p>
Replying to <a href={`#c_${comment.id}`}>{comment.author.name}</a>
Replying to{" "}
<a href={`#c_${comment.id}`}>
{comment.author.name || comment.author.email}
</a>
</p>
<Button size="xs" baseStyle="link" onClick={() => onClear()}>
<Cross1Icon />
Expand Down
2 changes: 1 addition & 1 deletion app/components/post-comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const Comment = ({
<Avatar user={comment.author} size="24px" />
<Name>
<Link to={`/u/${comment.author.email}`}>
{comment.author.name}
{comment.author.name || comment.author.email}
</Link>
</Name>
<Middot />
Expand Down
4 changes: 3 additions & 1 deletion app/components/post-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export default function PostList({ postList }) {
</PostAvatar>
<PostCredits>
<PostAuthor>
<Link to={`/u/${post.author.email}`}>{post.author.name}</Link>
<Link to={`/u/${post.author.email}`}>
{post.author.name || post.author.email}
</Link>
</PostAuthor>
<PostDate>{moment(post.publishedAt).fromNow()}</PostDate>
</PostCredits>
Expand Down
4 changes: 3 additions & 1 deletion app/components/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export default function Post({
<Avatar user={post.author} />
<Byline>
<Name>
<Link to={`/u/${post.author.email}`}>{post.author.name}</Link>
<Link to={`/u/${post.author.email}`}>
{post.author.name || post.authorId.email}
</Link>
</Name>
<Meta>
<Date>{moment(post.publishedAt || post.createdAt).fromNow()}</Date>
Expand Down
18 changes: 13 additions & 5 deletions app/lib/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export const notify = async ({
}

const postUrl = `${process.env.BASE_URL}/p/${post.id}`;
const sender = `"${post.author.name}" <${post.author.email}>`;
const sender = `"${post.author.name || post.author.email}" <${
post.author.email
}>`;
const subject = config.subjectPrefix
? `${config.subjectPrefix} ${post.title}`
: post.title;
Expand Down Expand Up @@ -120,7 +122,7 @@ const buildPostEmail = (post: PostQueryType): string => {
<tr>
<td>
<b style="color:${lightTheme.textColor};">${escapeHtml(
post.author.name
post.author.name || post.author.email
)}</b>
</td>
</tr>
Expand Down Expand Up @@ -157,7 +159,9 @@ export const notifyComment = async ({
}

const commentUrl = `${process.env.BASE_URL}/p/${post.id}#c_${comment.id}`;
const sender = `"${comment.author.name}" <${comment.author.email}>`;
const sender = `"${comment.author.name || comment.author.email}" <${
comment.author.email
}>`;
const subject = `Re: ${post.title}`;

const subscriptions: User[] = await getSubscriptions({ postId: post.id });
Expand Down Expand Up @@ -206,8 +210,12 @@ const buildCommentHtml = (

const isInReplyTo = parent && parent.authorId === toUser.id;
const titleLine = isInReplyTo
? `${escapeHtml(comment.author.name)} just replied to your comment`
: `${escapeHtml(comment.author.name)} left a new comment`;
? `${escapeHtml(
comment.author.name || comment.author.email
)} just replied to your comment`
: `${escapeHtml(
comment.author.name || comment.author.email
)} left a new comment`;
const reasonLine = isInReplyTo
? `You are being notified because you have notification replies enabled. <a href="${settingsUrl}">Account Settings</a>`
: `You are being notified because you are subscribed to this post. <a href="${postUrl}">Post Settings</a>`;
Expand Down
4 changes: 3 additions & 1 deletion app/routes/feeds/$feedId[.]xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const loader: LoaderFunction = async ({ request, params }) => {
baseUrl: process.env.BASE_URL,
})
)}]]></content:encoded>
<author>${escapeHtml(post.author.name)}</author>
<author>${escapeHtml(
post.author.name || post.author.email
)}</author>
<pubDate>${post.publishedAt.toUTCString()}</pubDate>
<link>${buildUrl(getPostLink(post), request)}</link>
Expand Down

0 comments on commit 0e79b13

Please sign in to comment.