guardian/frontend — pull request #1944 by jamesgorrie (2013-10-10 11:23:58+00:00)
Title: Discussion post comment

# Writing comments

*Very sorry for the massive pull request, future discussion PRs will be [MMM](http://stream1.gifsoup.com/view3/1358818/smallest-violin-o.gif "Much More Miniature")*

We can now write comments.

This was more a JS than HTML / CSS task so the there has been minimal refactoring.

The ```modules/discussion.js``` has also been left somewhat alone as it does quite a lot and would bring up major refactorings (which will happen).

To be able to test this locally, it is a bit of a chore. There are two ways:

1. Run pretty much everything locally
2. Run most things off code

No. 1 is particularly challenging with little benefit, so we've left that to lie.

No 2.

* Make sure everything is pointing to code
* This includes your API, so set this in your local settings file
* Make sure you are using the [correct Nginx setup](https://github.com/guardian/frontend/tree/master/nginx)
* Make sure you have the [ID application](https://github.com/guardian/frontend/tree/master/identity) running
* Log in
* Find a article open for comments in code. At time of writing ```/technology/gamesblog/2013/sep/26/game-links-press-start``` was open till 2050 (hopefully we launch prior).

# Notes

* There are a couple of issues with where user data comes from. Luckily, we can grab whether a user is signed in or if the article is closed from the ID cookie and content API respectively. Unluckily, we only know a users status (banned / premed) from the discussion API. For this reason we have this order of checking to lead to the least amount of calls to the server (especially considering most our readers aren't signed in)

* Check if article is commendable (Content API)
* Check if comments are closed (Content API)
* Check if user is signed in (ID cookie)
* Check if user is banned or premodded (Discussion API)

* We are using a [test component JS module](https://github.com/guardian/frontend/blob/discussion-post-comment/common/app/assets/javascripts/modules/component.js). We will be moving this over to other discussion components (i.e. [The current discussion module](https://github.com/guardian/frontend/blob/discussion-post-comment/common/app/assets/javascripts/modules/discussion/discussion.js)). Again, templating, and potentially data-binding (although we see little need at present) will be looked at as part of this, this is merely for a little structure.

* There is also a little hack of building up the comment from a comment below. As interactions become more complex, this really won't do, but we would have some form of templating by then.

* We were bundling up the discussion HTML and postbox HTML into one, but this makes it un-cacheable dependant on user state, so we have separated the calls. It is a challenge with any data that contains user information, but if we make those responses as small as possible, we should be good. We are also going to be looking to move all user data to ID, and once this is done, we should be able to store user's non-private, generic data in local storage or something similar (Something similar to the ID cookie at the moment).