Created
April 12, 2016 15:09
-
-
Save LosantGists/46bbb145f2d7ee6fab95024004079387 to your computer and use it in GitHub Desktop.
how-to-connect-discourse-to-slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var result = { | |
| newPost: null, | |
| newPostId: null | |
| }; | |
| // If this is the first time through, lastID will be undefined. | |
| // Set it to the most recent post and return. | |
| if(!payload.data.lastId) { | |
| if(payload.data.latest.body.latest_posts.length) { | |
| result.newPostId = payload.data.latest.body.latest_posts[0].id; | |
| return result; | |
| } | |
| } | |
| result.newPostId = Number.MAX_VALUE; | |
| // Find the oldest post that is still newer than lastId. | |
| payload.data.latest.body.latest_posts.forEach(function(post) { | |
| if(post.id > payload.data.lastId) { | |
| if(post.id < result.newPostId) { | |
| result.newPost = post; | |
| result.newPostId = post.id; | |
| } | |
| } | |
| }); | |
| // If it didn't find one newer, set it back to lastId. | |
| result.newPostId = result.newPost ? result.newPost.id : payload.data.lastId; | |
| return result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment