Skip to content

Commit

Permalink
Push post
Browse files Browse the repository at this point in the history
  • Loading branch information
yukozh committed Nov 9, 2015
1 parent 1c8caf1 commit bba9491
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/CodeComb.vNextChina/Controllers/ForumController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,15 @@ public IActionResult Post(long id, Guid? pid, string content)
DB.Posts.Add(p);
DB.SaveChanges();
if (pid.HasValue)
{
vNextChinaHub.Clients.Group("Thread-" + thread.Id).OnPostChanged(p.ParentId);
return Content(p.ParentId.ToString());
}
else
{
vNextChinaHub.Clients.Group("Thread-" + thread.Id).OnPostChanged(p.Id);
return Content(p.Id.ToString());
}
}

[HttpPost]
Expand Down Expand Up @@ -276,6 +282,7 @@ public string RemovePost(Guid id)
return "权限不足";
DB.Posts.Remove(post);
DB.SaveChanges();
vNextChinaHub.Clients.Group("Thread-" + post.ThreadId).OnPostRemoved(post.Id);
return "回复已成功删除";
}

Expand Down Expand Up @@ -304,6 +311,7 @@ public IActionResult EditThread(long id, string content)
});
thread.Content = content;
DB.SaveChanges();
vNextChinaHub.Clients.Group("Thread-" + thread.Id).OnThreadEdited(thread.Id);
return Content(Marked.Marked.Parse(content));
}

Expand Down Expand Up @@ -342,6 +350,7 @@ public IActionResult EditPost(long id, Guid pid, string content)
});
post.Content = content;
DB.SaveChanges();
vNextChinaHub.Clients.Group("Thread-" + thread.Id).OnPostChanged(post.Id);
return Content(Marked.Marked.Parse(content));
}

Expand Down
12 changes: 12 additions & 0 deletions src/CodeComb.vNextChina/Controllers/RenderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public IActionResult Thread(long id)
return Content("");
return View(thread);
}

public IActionResult ThreadContent(long id)
{
var thread = DB.Threads
.Where(x => x.Id == id)
.Select(x => x.Content)
.SingleOrDefault();
if (thread == null)
return Content("");
else
return Content(Marked.Marked.Parse(thread));
}
#endregion
#region Status
public IActionResult Status(long id)
Expand Down
Binary file modified src/CodeComb.vNextChina/Database/vec.db
Binary file not shown.
6 changes: 5 additions & 1 deletion src/CodeComb.vNextChina/Views/Forum/Thread.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,8 @@
});
}
</script>
}
}

<script>
var id = '@Thread.Id';
</script>
4 changes: 2 additions & 2 deletions src/CodeComb.vNextChina/Views/Render/Thread.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
@if (x.LastPost != null)
{
<img src="@Url.Action("Avatar", "Account", new { id = x.LastPost.UserId })" class="table-forums-avatar" />
<a asp-action="Thread" asp-controller="Forum" asp-route-id="@x.LastPost.Id"><span class="table-forums-micro-title gray">@x.LastPost.FiltedContent</span></a>
<div class="table-forums-micro-title"><a asp-action="Show" asp-controller="Account" asp-route-id="@x.LastPost.UserId">@await Html.ColorUserNameAsync(x.LastPost.User)</a> <span class="table-forums-lastrep-time">@@@x.LastPost.Time.ToString("yyyy:MM:dd HH:mm")</span></div>
<a asp-action="Thread" asp-controller="Forum" asp-route-id="@x.LastPost.Id"><span class="table-forums-micro-title gray">@x.LastPost.FiltedContent</span></a>
<div class="table-forums-micro-title"><a asp-action="Show" asp-controller="Account" asp-route-id="@x.LastPost.UserId">@await Html.ColorUserNameAsync(x.LastPost.User)</a> <span class="table-forums-lastrep-time">@@@x.LastPost.Time.ToString("yyyy:MM:dd HH:mm")</span></div>
}
else
{
Expand Down
23 changes: 23 additions & 0 deletions src/CodeComb.vNextChina/wwwroot/scripts/vnextcn.signalr.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ hub.client.onThreadChanged = function (id) {
});
}

hub.client.onThreadEdited = function (id) {
$.get('/render/threadcontent/' + id, {}, function (data) {
$('.thread-content').html(data);
});
}

hub.client.onPostRemoved = function (id) {
if ($('[data-id="' + id + '"]').length > 0)
$('[data-id="' + id + '"]').remove();
}

hub.client.onPostChanged = function (id) {
$.get('/render/post/' + id, {}, function (data) {
if ($('[data-id="' + id + '"]').length == 0)
$('.lst-posts').append(data);
else
$('[data-id="' + id + '"]').html($(data).html());
});
}

$.connection.hub.start(null, function () {
if ($('.lst-statuses').length > 0) {
hub.server.joinGroup("StatusList");
Expand All @@ -62,4 +82,7 @@ $.connection.hub.start(null, function () {
if ($('.thread-announcements').length > 0) {
hub.server.joinGroup('Forum-' + id);
}
if ($('.thread-content').length > 0) {
hub.server.joinGroup('Thread-' + id);
}
});

0 comments on commit bba9491

Please sign in to comment.