fixed friends and comments (for the most part)

do you ever just...
This commit is contained in:
Pachira 2016-12-06 15:40:12 +01:00
parent 9a0c8a9c78
commit ff422ab7e2
3 changed files with 33 additions and 55 deletions

View file

@ -26,7 +26,7 @@ class CommentsController extends Controller
public function post(string $category = '', int $reply = 0): string
{
// Check if the user can comment
if (session_check()) {
if (!session_check()) {
$error = "Your session expired, refresh the page!";
return $this->json(compact('error'));
}

View file

@ -49,7 +49,7 @@ class FriendsController extends Controller
$user = CurrentSession::$user;
// Check if the user can comment
if (session_check()) {
if (!session_check()) {
$error = "Your session expired, refresh the page!";
return $this->json(compact('error'));
}
@ -110,7 +110,7 @@ class FriendsController extends Controller
$user = CurrentSession::$user;
// Check if the user can comment
if (session_check()) {
if (!session_check()) {
$error = "Your session expired, refresh the page!";
return $this->json(compact('error'));
}

View file

@ -70,100 +70,78 @@
function commentAdd(obj) {
var container = document.createElement('li');
container.id = "comment-" + obj.id;
container.className = 'comment-container';
var inner = document.createElement('div');
inner.className = 'comment';
var avatar = document.createElement('a');
avatar.className = 'comment-avatar clean';
avatar.className = 'avatar avatar--border comment__avatar';
if (!obj.reply) {
avatar.className += ' comment__avatar--big';
}
avatar.href = "{{ route('user.profile', 1) }}".replace(1, obj.user);
avatar.style.backgroundImage = "url('{{ route('user.avatar', 1) }}')".replace(1, obj.user);
inner.appendChild(avatar);
var pointer = document.createElement('div');
pointer.className = 'comment-pointer';
pointer.className = 'comment__pointer';
inner.appendChild(pointer);
var content = document.createElement('div');
content.className = 'comment-content';
content.className = 'comment__content';
var controls = document.createElement('div');
controls.className = 'comment-controls';
controls.className = 'comment__controls';
var controlsInner = document.createElement('ul');
if (Sakura.Cookies.Get(sakuraVars.cookie.prefix + 'id') == obj.user) {
var controlsTrashContainer = document.createElement('li');
var controlsTrash = document.createElement('a');
controlsTrash.href = 'javascript:void(0);';
if (Sakura.Config.LoggedIn && Sakura.Config.UserId === obj.user) {
var controlsTrash = document.createElement('div');
controlsTrash.title = 'Delete';
controlsTrash.className = 'clean fa fa-trash-o';
controlsTrash.className = 'fa fa-trash-o comment__control';
controlsTrash.setAttribute('onclick', 'commentDelete(' + obj.id + ');');
controlsTrashContainer.appendChild(controlsTrash);
controlsInner.appendChild(controlsTrashContainer);
} else {
var controlsReportContainer = document.createElement('li');
var controlsReport = document.createElement('a');
controlsReport.href = '#';
controlsReport.title = 'Report';
controlsReport.className = 'clean fa fa-trash-o';
controlsReportContainer.appendChild(controlsReport);
controlsInner.appendChild(controlsReportContainer);
controls.appendChild(controlsTrash);
}
var controlsReplyContainer = document.createElement('li');
var controlsReply = document.createElement('a');
controlsReply.href = 'javascript:void(0);';
var controlsReply = document.createElement('div');
controlsReply.title = 'Reply';
controlsReply.className = 'clean fa fa-reply';
controlsReply.className = 'fa fa-reply comment__control';
controlsReply.setAttribute('onclick', 'commentReply(' + obj.id + ', "{{ session_id() }}", "{{ route("user.avatar", user.id) }}");');
controlsReplyContainer.appendChild(controlsReply);
controlsInner.appendChild(controlsReplyContainer);
controls.appendChild(controlsReply);
var controlsLikeContainer = document.createElement('li');
controlsLikeContainer.className = 'shown voting like';
var controlsLike = document.createElement('a');
controlsLike.href = 'javascript:void(0);';
var controlsLike = document.createElement('div');
controlsLike.setAttribute('onclick', 'commentVote(' + obj.id + ', 1);');
controlsLike.className = 'clean';
controlsLike.className = 'comment__control comment__control--vote comment__control--vote-up';
var controlsLikeIcon = document.createElement('span');
controlsLikeIcon.className = 'fa fa-thumbs-up';
controlsLikeIcon.className = 'fa fa-chevron-up';
controlsLike.appendChild(controlsLikeIcon);
controlsLike.innerHTML += "\r\n";
var controlsLikeCount = document.createElement('span');
controlsLikeCount.id = 'comment-' + obj.id + '-likes';
controlsLikeCount.innerText = obj.upvotes;
controlsLike.appendChild(controlsLikeCount);
controlsLikeContainer.appendChild(controlsLike);
controlsInner.appendChild(controlsLikeContainer);
controls.appendChild(controlsLike);
var controlsDislikeContainer = document.createElement('li');
controlsDislikeContainer.className = 'shown voting dislike';
var controlsDislike = document.createElement('a');
controlsDislike.href = 'javascript:void(0);';
var controlsDislike = document.createElement('div');
controlsDislike.setAttribute('onclick', 'commentVote(' + obj.id + ', 0);');
controlsDislike.className = 'clean';
controlsDislike.className = 'comment__control comment__control--vote comment__control--vote-down';
var controlsDislikeIcon = document.createElement('span');
controlsDislikeIcon.className = 'fa fa-thumbs-down';
controlsDislikeIcon.className = 'fa fa-chevron-down';
controlsDislike.appendChild(controlsDislikeIcon);
controlsDislike.innerHTML += "\r\n";
var controlsDislikeCount = document.createElement('span');
controlsDislikeCount.id = 'comment-' + obj.id + '-dislikes';
controlsDislikeCount.innerText = obj.upvotes;
controlsDislike.appendChild(controlsDislikeCount);
controlsDislikeContainer.appendChild(controlsDislike);
controlsInner.appendChild(controlsDislikeContainer);
controls.appendChild(controlsInner);
var clear = document.createElement('div');
clear.className = 'clear';
controls.appendChild(clear);
controls.appendChild(controlsDislike);
content.appendChild(controls);
var text = document.createElement('text');
text.className = 'comment-text';
text.className = 'comment__text';
text.innerHTML = obj.text;
content.appendChild(text);
@ -171,7 +149,7 @@
container.appendChild(inner);
var replies = document.createElement('ul');
replies.className = 'comment-replies';
replies.className = 'comment__replies';
container.appendChild(replies);
var discussion = document.getElementById('comments').querySelector('.comments__list');
@ -248,10 +226,10 @@
replyContainer.appendChild(replyDiv);
// Insert the HTML
if (replyingTo.querySelector('.comment-replies').children.length > 0) {
replyingTo.querySelector('.comment-replies').insertBefore(replyContainer, replyingTo.querySelector('.comment-replies').firstChild);
if (replyingTo.querySelector('.comment__replies').children.length > 0) {
replyingTo.querySelector('.comment__replies').insertBefore(replyContainer, replyingTo.querySelector('.comment__replies').firstChild);
} else {
replyingTo.querySelector('.comment-replies').appendChild(replyContainer);
replyingTo.querySelector('.comment__replies').appendChild(replyContainer);
}
}