Closed ansonphong closed 11 years ago
Phong, is the tree parameter in pw_get_comments working? i am only getting flat set of comments currently without children.
Yes it is currently working. I will find a good example of a post with hierarchical comments and an input / output for that...
Try post_id : 166220 -- this has lots of comments and several which are hierarchical. I'm testing locally now.
Perhaps if you try this:
echo json_encode(pw_get_comments(array("post_id"=>166220)));
You will see that some posts contain an object called 'children' which contains an array of child posts. This goes on recursively to however many levels deep the comments go.
i was trying post 40519, which i know it has many comments, but i only get the first level. i tried 166220, same thing. i am trying to trace it in php, it gets way too many comments, but when the tree is created, it seem to return first level only. i already set the tree parameter to true. i will give it more troubleshooting, maybe i can find something..
this is my code
$query = array(
'post_id' => 166220,
);
$results = pw_get_comments ($query,'all',true);
i also noticed something strange, and i asked Ashraf to look into it, that comment_parent is usually a small number, that doesnt seem like a real comment_id, and mostly it is a number between 1 and 10, which would make it almost impossible to find a parent for any of these 5 digit comment_ids. would it be a script thing? maybe i should get a fresh copy of the migrated database from you?
Oh yes I know this issue - we fixed it a while ago. You need to run the most recent migration script on it. We fixed this at least a week ago, whereby the comment parent IDs weren't migrating, although Ashraf has already fixed this. The most recent migration script needs to be run.
confirmed and fixed. one more thing, user ids in wp_comments are not migrated, since they do not have associated roles. I discovered these as they were throwing warnings when getting comments. i will log that separately, but this is just a heads up, i guess it would need to revisit our migration script logic. this is not stopping me anyway, low priority for my work, but not sure of its priority in the db migration.
The user_id field in my wp_comments table has been migrated. When you ran the most recent migration script, did it not migrate the user_id?
On Wed, Oct 23, 2013 at 11:31 AM, michelhabib notifications@github.comwrote:
confirmed and fixed. one more thing, user ids in wp_comments are not migrated, since they do not have associated roles. I discovered these as they were throwing warnings when getting comments. i will log that separately, but this is just a heads up, i guess it would need to revisit our migration script logic. this is not stopping me anyway, low priority for my work, but not sure of its priority in the db migration.
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-26931510 .
I guess i described it wrong. Yes, The user ids are migrated in wp comments and yes, i ran the most recent script. The problem is that there are user ids in wp comments that do not have records in wp users, and the reason is that they do not have any roles associated to them. I will send you an example when i am on a computer.
Best Regards, Michel.
On Oct 23, 2013, at 11:51 PM, phong notifications@github.com wrote:
The user_id field in my wp_comments table has been migrated. When you ran the most recent migration script, did it not migrate the user_id?
On Wed, Oct 23, 2013 at 11:31 AM, michelhabib notifications@github.comwrote:
confirmed and fixed. one more thing, user ids in wp_comments are not migrated, since they do not have associated roles. I discovered these as they were throwing warnings when getting comments. i will log that separately, but this is just a heads up, i guess it would need to revisit our migration script logic. this is not stopping me anyway, low priority for my work, but not sure of its priority in the db migration.
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-26931510 .
— Reply to this email directly or view it on GitHub.
ok thanks...
On Wed, Oct 23, 2013 at 3:15 PM, michelhabib notifications@github.comwrote:
I guess i described it wrong. Yes, The user ids are migrated in wp comments and yes, i ran the most recent script. The problem is that there are user ids in wp comments that do not have records in wp users, and the reason is that they do not have any roles associated to them. I will send you an example when i am on a computer.
Best Regards, Michel.
On Oct 23, 2013, at 11:51 PM, phong notifications@github.com wrote:
The user_id field in my wp_comments table has been migrated. When you ran the most recent migration script, did it not migrate the user_id?
On Wed, Oct 23, 2013 at 11:31 AM, michelhabib notifications@github.comwrote:
confirmed and fixed. one more thing, user ids in wp_comments are not migrated, since they do not have associated roles. I discovered these as they were throwing warnings when getting comments. i will log that separately, but this is just a heads up, i guess it would need to revisit our migration script logic. this is not stopping me anyway, low priority for my work, but not sure of its priority in the db migration.
— Reply to this email directly or view it on GitHub< https://github.com/phongmedia/postworld/issues/41#issuecomment-26931510> .
— Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-26950922 .
user id 21314 appears in wp comments, however it doesn't appear in wp users. if you check back in drupal, user 21314 exists, however it is not tied to any role, hence not migrated. Can you please check this one and let us know if that scenario is acceptable? no rush from my side anyways.
Interesting, I will look into that. That's a very good observation, I'm glad you noticed that. I will look into that as far as data migration is concerned.
On Wed, Oct 23, 2013 at 4:34 PM, michelhabib notifications@github.comwrote:
user id 21314 appears in wp comments, however it doesn't appear in wp users. if you check back in drupal, user 21314 exists, however it is not tied to any role, hence not migrated. Can you please check this one and let us know if that scenario is acceptable? no rush from my side anyways.
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-26955445 .
Phong, if i should use edit-field with comment editing and sorting, is it ready for such use? and would you recommend using it in this case, or use regular fields for this special case?
Hi Michel I have archived and disabled the edit-field directive, as I found the built-in Angular directives and controllers to be sufficient. You can use ng-options for dropdown select items, and regular fields with ng-model.
On Thursday, October 24, 2013, michelhabib wrote:
Phong, if i should use edit-field with comment editing and sorting, is it ready for such use? and would you recommend using it in this case, or use regular fields for this special case?
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-26995462 .
oh that's ok, i am about to finish and publish most of the load-comments component.
the wordpress comments do not have the option to flag a comment by a regular user, as far as i understand. i see the flagging option in your mockup above, is that something in scope?
you're right, comment flagging isn't in scope. Although the ability to delete a comment should be.
On Thu, Oct 24, 2013 at 2:53 PM, michelhabib notifications@github.comwrote:
the wordpress comments do not have the option to flag a comment by a regular user, as far as i understand. i see the flagging option in your mockup above, is that something in scope?
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-27034543 .
Phong, now load-comments directive is ready and committed into github. Here are my comments inline in the js file, showing what is completed and the leftovers/questions that i am finalizing now. i am expecting that you will work on the UI, but at the same time i made an effort to make it look as clean as possible - there is still some ui work to be done that i listed below.
/*
* Tasks
* Get Comments Service [OK]
* Create Recursive Comment Structure [OK]
* - with Maximimze/minimize [OK]
* - +/- Karma Points [OK - just add ajax Functions]
* Create Comment Tempalte [OK]
* Add Comment/Reply [OK]
* Edit Comment [OK]
* Delete Comment [OK]
* Toggle Reply/Delete/Edit [OK]
* Flag comment [Doesn't exist]
* Remove ngAnimate to enhance performance! [OK]
* Bind HTML/Sanitize Content/Format Content [OK]
* NOTE: Karma points are always zero, even if updated in the wp_comments table, it seems they need to be updated somewhere else
* - Maximize/Minimize based on Points [OK] = Note that we are currently using a random function to generate points - for testing purposes
* performance Tuning of initial loading time [OK] [using chrome timeline - less than 1 second to render - after loading data from server]
* Create a Comment on the Top Level [OK]
* OrderBy is moved to query field and underscore is removed, just to match the arguments format of the get_comments function
* Sort Options and refresh based on sorting [OK]
* Show as Tree or linear [OK]
* Show Loading Icon while loading data [OK]
* Permissions, you can only edit and delete your own comments [OK]
*
* - show control bar on hover only
* - show icons for control bar
* - highlight selected function of the control bar [reply, edit, delete, etc...]
*
* - Show More [in progress]
* add Timezone to date
* encapsulate in a simple directive
*
* when adding new comments they should be open by default?
* Can we use the html returned directly?
* Cleanup UI
* Refactor a bit
* Cleanup CSS
* Animation? Performance Limitations
* If we can show the comments with tree=false, what happens when users reply? it will become a tree? no?
*/
Here are some screenshots, illustrating the different functions, loading, viewing nested comments, edit comment, delete comment, reply to comment
Great, that looks good. I'll have a look at it today.
On Sat, Oct 26, 2013 at 6:37 AM, michelhabib notifications@github.comwrote:
Here are some screenshots, illustrating the different functions, loading, viewing nested comments, edit comment, delete comment, reply to comment
[image: loading]https://f.cloud.github.com/assets/296637/1413638/9fb33462-3e43-11e3-9625-b03029e3d4e8.jpg [image: nestedcomments]https://f.cloud.github.com/assets/296637/1413637/9fae93f8-3e43-11e3-9113-605f9931e964.jpg [image: editcomment]https://f.cloud.github.com/assets/296637/1413634/9ee8d55a-3e43-11e3-983f-ae911b6a2446.jpg [image: delete]https://f.cloud.github.com/assets/296637/1413635/9f683098-3e43-11e3-8577-ff25b5612dbb.jpg [image: reply]https://f.cloud.github.com/assets/296637/1413636/9fa63cf8-3e43-11e3-9a40-04323f187331.jpg
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-27146386 .
thanks, i made a bit of refactoring and cleaning, and hiding part of long comments [show more], the css is a bit messy. just let me know where to stop. i am just investigating a small issue related to the comment date and user timezone, they are not quire aligned.
ok good idea ---
I have found working with dates, to stick with reading and writing _date_gmt
, and then convert to the user display, and the back to GMT/UTC when writing to the DB. This way it doesn't matter if they've set their Wordpress timezone settings, it will use the offset of their current computer.
This is helpful: http://docs.angularjs.org/api/ng.filter:date
i am using the same way that wordpress is writing it to the database and that is exactly as you suggested, thanks for the tip. my problem was related to the AngularJS interpretation, it does not use the standard date format, which adds a Z to indicate that the date needs to be converted to local time. so , i just added the Z and it works now. the reason i could reproduce the issue is that i am using a server with a different timezone settings that the client. as for the date filters, i am using a custom filter called TimeAgo, which gives the relative time, and it looks good so far.
Thanks
Yes understood - the date often ends up taking longer than I expect, due to the various object formatting and time zone conversion.
By first testing, the load-comments
system appears to be working very effectively. It's by far the most sophisticated rendering of comments I've seen done for Wordpress before. Good thing the system is open source.
I have a question - you may tell me if it's very easy to implement or outside of our current budget scope. What would it take to make a polling function with the following parameters?
live_poll: 60, // in seconds
live_poll_while_writing: false, // boolean
live_poll : integer
live_poll_while_writing : boolean
load_comments['post_single'] = {
// LIVE POLL PARAMETERS //
live_poll: 60,
live_poll_while_writing: false,
query : {
post_id : 133925, // 21853, // 133925, // 166220, // 21853, // 166220,
status: 'approve',
orderby : 'comment_date',
},
fields : 'all',
tree : true,
order_options : {
'comment_points' : 'Points',
'comment_date' : 'Date'
},
min_points : 0,
};
I can give it a try. The way it is designed, it might make this implementation fairly simple. The way i understand it is that every x seconds, the client will ping the server with the same get_comments function, retrieve all the results again, extract the difference and update its tree structure. unless you have a magical function that will return to the client all the adds, edits and deletes during the past period.
Theoritically, to do this, i need to:-
about live poll while writing, do you mean preventing the poll when the user is writing a comment?
and Thanks, it is all your idea, i just hope my implementation is close enough :)
Just a note here, AngularJS gets slower as we add new comments. I ran my test with the largest amount of comments available on the old site, that is 250 comments in a tree with 150 comments on the first level. and i guess the loading time is not that bad. However, if you do thousands of comments, this approach might not be the best. it would be crazy to have thousands of dynamic elements, because of all the checks that Angular needs to run.
Let me know if that would be a concern, as it is the only limitation i can find so far with our design.
I can understand about the possible performance issues with polling. The approach you suggested is good, by walking the comments tree twice, once to remove and once to add new comments, then re-render seamlessly.
You can give that a test and see how it goes. If it becomes overly complex or very slow on performance, then we can remove it from current scope.
Ok then. If i understand correctly, i will just give it lower priority than the rest of the remaining directives, i think we're very close - at least from my perspective here.
Yes, that polling can be lower priority. As you said that, I just noticed that GitHub did a polling an updated our comments in real-time, which was interesting. I was also writing a post while that happened and my post writing was not interrupted, so perhaps there would be no need to prevent polling while writing a comment.
I have 2 other questions which you may be able to help with.
I tried a number of things, and wasn't able to get it to work - it seems like it would be straightforward.
So I'm using load-comments
inside another template, where I have the ID of the post in scope as post.ID
.
So I want to load the directive into this template, referencing the post.ID
like this:
load_comments['post_single'] = {
query : {
post_id : post.ID, // This doesn't seem to work. Any ideas?
status: 'approve',
orderby : 'comment_date',
},
min_points : 20,
};
The parameter min_points : 20
doesn't seem to be working. I'd expect it would only have posts 'expanded' which have minimum of 20 karma points. This could also help improve performance and usability, since the user would have to 'dig' if they want to keep reading down a thread, so we would only have to render the header of the comment, and not the comment body.
Was this min_points
parameter implemented yet, or am I missing something?
I'm generally quite happy with how load-comments
is working. Bravo.
Thanks Phong, I will get back to polling comments when i start with my trial, the test will help reveal more about the usability.
for Question 1, let me help troubleshoot it, if you replace post.ID with a number does it work? if no, then it is something with the template, it should be compared against the running environment in postworld-theme. if yes, then when exactly do you set post.ID value? is it before load_comments['post_single'] is defined or after? if before, then try to console.log('check',load_comments['post_single'].query.post_id) if after, this is not possible, the array must be fully defined before calling the directive. At least we have to think of how this should be addressed, not a big deal though.
for Question 2, Re-reading this, i guess i might have misinterpreted the requirement. The way i implemented it, is,
child.karmaPoints = child.comment_karma = Math.floor(Math.random() * 100) + 1;
i was thinking that you want the user to have all comments but have important ones only visible, the invisible ones can be seen if the selects to do so.
now, i guess you mean that you need
Sorry i am getting into tiny details, but that will help me better understand the requirements. and sorry if there is a misunderstanding here, i am sure i can cover it up quickly with the current design.
ReferenceError: post is not defined
Yes you understand exactly what is implied in the min_points
parameter.
To clarify Question 1 : I can print out post.ID and it works in HTML. Like {{post.ID}}
since that post
object is present with ID as a value. What I'm trying to do is essentially this :
load_comments['post_single'] = {
query : {
post_id : {{post.ID}}, // << How to get the literal value of post.ID
status: 'approve',
orderby : 'comment_date',
},
min_points : 20,
};
If there's no obvious solution to #1 then I'll try and setup an environment where you can see what's happening.
if you can setup some environment that would be good, i think the mystery here is all about when/where is post.ID defined?
but i guess i know what the problem is, i think it is all about the order of execution - it's the major thing i keep learning about in angular. so here is my thought about it. first the browser reads your html page and runs the script that defines the array, even before it gets to the controller that defines post.ID, and then it saves the load_commets array with empty value. then at the point where you define post.ID, whether it is in a controller or anywhere else, it is not linked in any way to load_comments array. if that is really the problem, the solution is easy, it's one of 2 things. either you modify load_comments array in the same area that defines post.ID or we can set a dynamic field in the load-comments directive like this:
<div load-comments="post_single" post-id={{post.ID}}></div>
this is not implemented yet, but can be easily added, it could be only a couple of lines of code. and it will override whatever post_id is defined in load-comments. however, you still need to make sure that post.ID is defined before load-comments is executed, let me know if that solution maybe feasible, i can send you a quick update to use it.
and for Q2, when you say i understand it exactly, you mean the way i implemented it or the way i described it now in the second paragraph?
Yes, that may help to implement that attribute into load-comments. I'll try and illustrate the context first.
Now that I re-read your paragraphs on question 2, I can't tell a difference between the methods. They both seem correct, and the same.
Both of these seem like the same solution, and both seem correct:
for Question 2, Re-reading this, i guess i might have misinterpreted the requirement. The way i implemented it, is,
i receive all comments from wordpress, i render all comments, i minimize the comments that have less than min_points [as if you clicked the minimize button on the left of the comment], and it will minimize the content of this comment [but will leave the author, points, date] and all of the comments below it [regardless of their points] i added the following line to line 150 of loadComments.js, to help me simulate points, but you may comment it if you have real data. js child.karmaPoints = child.comment_karma = Math.floor(Math.random() * 100) + 1; i was thinking that you want the user to have all comments but have important ones only visible, the invisible ones can be seen if the selects to do so. now, i guess you mean that you need
The comments to be all received [min_points doesn't affect the wordpress query as far as i understand] Render all comments on the first level For first level comments that have less than min_points, they will only have the header rendered with an expand button [the regular + button] upon pushing + [maximizing], the rest of the comment hierarchy will be grabbed and rendered [grabbed from the object tree, not from the database]
What was the difference between the two methods? When I read them they're both the same and correct.
for Q2. Option 1 [implemented already] - all comments are retrieved from server and rendered in the UI, only the comments less than min_points are just collapsed [they are rendered by collapsted], you have to expand them to see them. Isn't that the behavior you are seeing right now?
It would be easier if we restart the conversation from here, can you tell me how isn't min_points working right now? the image below [default from my template sample], shows some comments are expanded, and some are collapsed, depending on the number of points set in sample [50 i guess]
Also, note the random function i used for setting random values for points for each comment, these might be confusing you - as i mentioned in my earlier comment. Let me know if we need to skype for this one.
Got it - YES this is the correct method. this is how it is meant to work.
On Mon, Oct 28, 2013 at 9:56 AM, michelhabib notifications@github.comwrote:
for Q2. Option 1 [implemented already] - all comments are retrieved from server and rendered in the UI, only the comments less than min_points are just collapsed [they are rendered by collapsted], you have to expand them to see them. Isn't that the behavior you are seeing right now?
It would be easier if we restart the conversation from here, can you tell me how isn't min_points working right now? the image below [default from my template sample], shows some comments are expanded, and some are collapsed, depending on the number of points set in sample [50 i guess] [image: min_points]https://f.cloud.github.com/assets/296637/1421746/4568d098-3ff1-11e3-8b62-9d8f50ca5b20.png
Also, note the random function i used for setting random values for points for each comment, these might be confusing you - as i mentioned in my earlier comment. Let me know if we need to skype for this one.
— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/41#issuecomment-27230873 .
ok great
Hi Michel, so I have created an environment for you to see how the load-comments directive is being used in a modal window.
/themes/postworld-theme
/themes/postworld-theme/sandbox.php
You can create a new page with this as the template to see the demo, it's called "Sandbox".
/#/media-modal
/themes/postworld-theme/sandbox.php
, you will see a working-example of how the data is being passed to the modal window in which the load-comments
directive is located. This is a demo example - it's actually being passed by launching it with the post
object attributed by the ng-repeat in the feed, though this is a functional example of the method. The real-world method looks like : ng-click="openMediaModal(post)"
which works fine, except for allowing load-comments
to use post.ID
/plugins/postworld/
and look at /templates/panels/media_modal.html
. You will see the reason the comments are working in the modal window, is because the post.ID
is hard-wired to it. Here you can experiment with getting it to work by using the post.ID
passed to it through the media modal launch.<div ng-controller="mediaModalCtrl">
<button ng-click="openMediaModal({ID:'133925',post_title:'Post Title',post_format:'video',link_url:'http://www.youtube.com/watch?v=38peWm76l-U'})">Launch Media Modal</button>
</div>
<div ng-controller="mediaModalCtrl">
<button ng-click="openMediaModal(post)">Launch Media Modal</button>
</div>
load-comments
to take the post.ID
value (passed when opening the modal) to query and load the right comments./#/media-modal/
without having to use a separate sandbox.php
i will try to be brief, since i have few minutes left on my laptop battery [forgot charger at work] get the latest, and check the sandbox, it is working now. use this for load-comments.
<div streeview load-comments="post_single" post="post"></div>
whenever a post object exists in scope, the load-comments will try to retrieve the post id from that post object post.ID instead of whatever value you put in the Githubissues.
Hi Michel, I have added a directive called load-comments which basically does what the name says. It loads comments. Here is the documentation for that.
load-comments [ directive ] https://github.com/phongmedia/postworld/tree/master/js#load-comments--directive-
Two things I have done to get the process going:
pw_get_comments()
: https://github.com/phongmedia/postworld/tree/master/php#pw_get_comments--query-fields-tree-templates/comments/comments-header.html
templates/comments/comment-single.html
Mind you, whatever is in the templates is very rough right now, and it is structurally incomplete, although it's a starting point which you can work from - please feel free to re-arrange the templates in any way you see fit.
The comments are meant to work in the same way as the comments on Reddit.
Let me know if you have any questions, and we can talk on Skype this week if you like to clarify any issues.