As you can see in the picture above, the plugin doesn't seem to render the pinged users properly even though I have saved the two different pinged users in the database and send it as data to the ajax calls.
// I'm not using the function below:
/*
var saveComment = function (data) {
// Convert pings to human readable format
$(Object.keys(data.pings)).each(function (index, userId) {
var fullname = data.pings[userId];
var pingText = '@' + fullname;
data.content = data.content.replace(new RegExp('@' + userId, 'g'), pingText);
});
return data;
};
*/
$commentsContainer.comments({
// User
currentUserId: 460,
profilePictureURL: 'https://storage.googleapis.com/topanimecharacters.com/validated/images/profile/default',
currentUserIsAdmin: false,
// Functionalities
textareaRows: 1,
highlightColor: '#007bff',
textareaMaxRows: 7,
maxRepliesVisible: 3,
enableDeletingCommentWithReplies: true,
defaultNavigationSortKey: 'newest',
readOnly: false,
enablePinging: true,
enableHashtags: true,
searchUsers: function(term, success, error) {
$.ajax({
type: 'GET',
url: '/character/get_comment_users/pXMqXq/' + pageNumber,
timeout: 0,
success: function(usersArray) {
success(usersArray.filter(function(user) {
var containsSearchTerm = user.fullname.toLowerCase().indexOf(term.toLowerCase()) != -1;
var isNotSelf = user.id != 460;
return containsSearchTerm && isNotSelf;
}));
},
error: function(data) {
alert("Something went wrong while loading users to ping, sorry :(");
return error;
}
});
},
getComments: function(success, error) {
$.ajax({
type: 'GET',
url: '/character/get_comments/pXMqXq/' + pageNumber,
timeout: 0,
success: function(commentsArray) {
if (!commentsArray[1]['more_comments']) {
$loadMore.css('display', 'none');
} else {
$loadMore.css('display', 'block');
$loadMore.removeAttr('disabled', false).html("Load more");
}
success(commentsArray[0]);
},
error: function(data) {
$loadMore.hide();
alert("Something went wrong while loading the comments, sorry :(");
return error;
}
});
},
postComment: function(data, success, error) {
$.ajax({
type: 'POST',
dataType: "json",
contentType: "application/json",
url: '/character/add_comment/pXMqXq',
timeout: 0,
data: JSON.stringify(data),
success: function(comment) {
console.log(comment);
success(comment);
},
error: function(data) {
alert("Couldn't process your request, can't have a comment longer than 10.000 letters/characters and a max of 25 newlines, have you confirmed your email?");
return error;
}
});
},
putComment: function(data, success, error) {
$.ajax({
type: 'PUT',
dataType: "json",
contentType: "application/json",
url: '/character/update_comment/' + data.id,
timeout: 0,
data: JSON.stringify(data),
success: function(comment) {
console.log(comment);
success(comment);
},
error: function(data) {
alert("Couldn't process your request, can't have a comment longer than 10.000 letters/characters and a max of 25 newlines, have you confirmed your email?");
return error;
}
});
},
deleteComment: function(data, success, error) {
$.ajax({
type: 'DELETE',
url: '/character/delete_comment/' + data.id,
success: success,
error: function(data) {
alert("Couldn't process your request, please don't spam the request, have you confirmed your email?");
return error;
}
});
},
upvoteComment: function(data, success, error) {
if (data.user_has_upvoted) {
$.ajax({
type: 'POST',
url: '/character/upvote_comment/' + data.id,
error: function(data) {
alert("Couldn't process your request, please don't spam the button, have you confirmed your email?");
return error;
},
});
} else {
$.ajax({
type: 'POST',
url: '/character/downvote_comment/' + data.id,
error: function(data) {
alert("Couldn't process your request, please don't spam the button, have you confirmed your email?");
return error;
},
});
}
},
timeFormatter: function(time) {
return new Date(time).toLocaleDateString('en-US');
},
hashtagClicked: function(hashtag) {
window.open('https://www.google.com/search?q=' + hashtag);
},
pingClicked: function(ping) {
window.open('https://www.google.com/search?q=' + ping);
},
});
Yes, the reason why I'm not using the saveComment function is that I'm replacing the user ids with the usernames on the server side instead.
As you can see in the picture above, the plugin doesn't seem to render the pinged users properly even though I have saved the two different pinged users in the database and send it as data to the ajax calls.
Yes, the reason why I'm not using the saveComment function is that I'm replacing the user ids with the usernames on the server side instead.