Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Highlight OP in post
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed May 5, 2021
1 parent 74ce82b commit 2eaa6ce
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/Reddit2Kindle.Functions/Functions/DebugFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<HttpResponseData> PostDebugAsync([HttpTrigger(AuthorizationLev
var postRequest = await req.ReadFromJsonAsync<PostRequest>();
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/html; charset=utf-8");
await response.WriteStringAsync(await _reddit2KindleService.RenderPost(postRequest));
await response.WriteStringAsync(await _reddit2KindleService.RenderPostAsync(postRequest));
return response;
}

Expand All @@ -37,7 +37,7 @@ public async Task<HttpResponseData> SubredditDebugAsync([HttpTrigger(Authorizati
var subredditRequest = await req.ReadFromJsonAsync<SubredditRequest>();
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/html; charset=utf-8");
await response.WriteStringAsync(await _reddit2KindleService.RenderSubreddit(subredditRequest));
await response.WriteStringAsync(await _reddit2KindleService.RenderSubredditAsync(subredditRequest));
return response;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Reddit2Kindle.Functions/Functions/QueueFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public QueueFunction(ILogger<QueueFunction> logger, Reddit2KindleService reddit2
public async Task PostAsync([QueueTrigger(PostQueue)] PostRequest request)
{
_logger.LogInformation(JsonSerializer.Serialize(request));
await _reddit2KindleService.SendPost(request);
await _reddit2KindleService.SendPostAsync(request);
}

[Function("SubredditQueue")]
public async Task SubredditAsync([QueueTrigger(SubredditQueue)] SubredditRequest request)
{
_logger.LogInformation(JsonSerializer.Serialize(request));
await _reddit2KindleService.SendSubreddit(request);
await _reddit2KindleService.SendSubredditAsync(request);
}
}
}
2 changes: 1 addition & 1 deletion src/Reddit2Kindle.Functions/Services/ReadabilityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ReadabilityService(ILogger<ReadabilityService> logger)
_logger = logger;
}

public async Task<string> GetArticle(string uri)
public async Task<string> GetArticleAsync(string uri)
{
var reader = new Reader(uri);
try
Expand Down
20 changes: 10 additions & 10 deletions src/Reddit2Kindle.Functions/Services/Reddit2KindleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,44 @@ public Reddit2KindleService(ILogger<Reddit2KindleService> logger, RazorService r
_sendGridService = sendGridService;
}

public async Task SendPost(PostRequest request)
public async Task SendPostAsync(PostRequest request)
{
var post = _redditService.GetPost(request.Post.ToString());
var template = await GetPostTemplate(post);
var template = await GetPostTemplateAsync(post);
var attachmentContent = await _razorService.RenderTemplateAsync(template);
await _sendGridService.SendEmailAsync(request.Email, post.Title, attachmentContent);
}

public async Task SendSubreddit(SubredditRequest request)
public async Task SendSubredditAsync(SubredditRequest request)
{
var posts = _redditService.GetSubredditPosts(request.Subreddit, request.TimePeriod);
var postTemplates = await Task.WhenAll(posts.Select(GetPostTemplate));
var postTemplates = await Task.WhenAll(posts.Select(GetPostTemplateAsync));
var subredditTemplate = new SubredditTemplate(postTemplates);
var attachmentContent = await _razorService.RenderTemplateAsync(subredditTemplate);
await _sendGridService.SendEmailAsync(request.Email, GenerateTitle(request), attachmentContent);
}

internal async Task<string> RenderPost(PostRequest request)
internal async Task<string> RenderPostAsync(PostRequest request)
{
var post = _redditService.GetPost(request.Post.ToString());
var template = await GetPostTemplate(post);
var template = await GetPostTemplateAsync(post);
return await _razorService.RenderTemplateAsync(template);
}

internal async Task<string> RenderSubreddit(SubredditRequest request)
internal async Task<string> RenderSubredditAsync(SubredditRequest request)
{
var posts = _redditService.GetSubredditPosts(request.Subreddit, request.TimePeriod);
var postTemplates = await Task.WhenAll(posts.Select(GetPostTemplate));
var postTemplates = await Task.WhenAll(posts.Select(GetPostTemplateAsync));
var subredditTemplate = new SubredditTemplate(postTemplates);
return await _razorService.RenderTemplateAsync(subredditTemplate);
}

private async Task<PostTemplate> GetPostTemplate(Post post)
private async Task<PostTemplate> GetPostTemplateAsync(Post post)
{
return post switch
{
SelfPost selfPost => new SelfPostTemplate(selfPost),
LinkPost linkPost => new LinkPostTemplate(linkPost, await _readabilityService.GetArticle(linkPost.URL))
LinkPost linkPost => new LinkPostTemplate(linkPost, await _readabilityService.GetArticleAsync(linkPost.URL))
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Reddit2Kindle.Functions/Templates/LinkPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
@Raw(Model.Article)
</div>
}
@foreach (var comment in Model.Post.Comments.GetComments("top"))
@foreach (var comment in Model.Post.Comments.GetTop(showMore: false))
{
await IncludeAsync("Templates.Partials.QuoteComments", comment);
await IncludeAsync("Templates.Partials.QuoteComments", (Model.Post.Author, comment));
}
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@using Reddit.Controllers
@inherits RazorLight.TemplatePage<Reddit.Controllers.Comment>
@inherits RazorLight.TemplatePage<(string op, Reddit.Controllers.Comment comment)>

<li>
@Raw(Model.BodyHTML)
<footer>@Model.Author</footer>
@Raw(Model.comment.BodyHTML)
<footer class="@(Model.comment.Author == Model.op ? "op" : "")">@Model.comment.Author</footer>
<ol>
@foreach (var reply in Model.replies?.Where(reply => reply is not null) ?? Enumerable.Empty<Comment>())
@foreach (var reply in Model.comment.replies?.Where(reply => reply is not null) ?? Enumerable.Empty<Comment>())
{
await IncludeAsync("Templates.Partials.NumberComments", reply);
await IncludeAsync("Templates.Partials.NumberComments", (Model.op, reply));
}
</ol>
</li>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@using Reddit.Controllers
@inherits RazorLight.TemplatePage<Reddit.Controllers.Comment>
@inherits RazorLight.TemplatePage<(string op, Reddit.Controllers.Comment comment)>

<blockquote>
@Raw(Model.BodyHTML)
<footer>@Model.Author</footer>
@foreach (var reply in Model.replies?.Where(reply => reply is not null) ?? Enumerable.Empty<Comment>())
@Raw(Model.comment.BodyHTML)
<footer class="@(Model.comment.Author == Model.op ? "op" : "")">@Model.comment.Author</footer>
@foreach (var reply in Model.comment.replies?.Where(reply => reply is not null) ?? Enumerable.Empty<Comment>())
{
await IncludeAsync("Templates.Partials.QuoteComments", reply);
await IncludeAsync("Templates.Partials.QuoteComments", (Model.op, reply));
}
</blockquote>
4 changes: 2 additions & 2 deletions src/Reddit2Kindle.Functions/Templates/SelfPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
@Raw(Model.Post.SelfTextHTML)
</div>
}
@foreach (var comment in Model.Post.Comments.GetComments("top"))
@foreach (var comment in Model.Post.Comments.GetTop(showMore: false))
{
await IncludeAsync("Templates.Partials.QuoteComments", comment);
await IncludeAsync("Templates.Partials.QuoteComments", (Model.Post.Author, comment));
}
</div>
</body>
Expand Down

0 comments on commit 2eaa6ce

Please sign in to comment.