PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/public/javascripts/app/models/stream.js

http://github.com/diaspora/diaspora
JavaScript | 57 lines | 43 code | 11 blank | 3 comment | 6 complexity | e0c1828a842991c46f10df3aa641cfbb MD5 | raw file
Possible License(s): AGPL-1.0, AGPL-3.0, JSON
  1. app.models.Stream = Backbone.Collection.extend({
  2. initialize : function(){
  3. this.posts = new app.collections.Posts();
  4. },
  5. url : function(){
  6. return _.any(this.posts.models) ? this.timeFilteredPath() : this.basePath()
  7. },
  8. _fetching : false,
  9. fetch: function() {
  10. if(this._fetching) { return false; }
  11. var self = this
  12. // we're fetching the collection... there is probably a better way to do this
  13. self._fetching = true;
  14. this.posts
  15. .fetch({
  16. add : true,
  17. url : self.url()
  18. })
  19. .done(
  20. function(resp){
  21. // we're done fetching... there is probably a better way to handle this
  22. self._fetching = false;
  23. self.trigger("fetched", self);
  24. // all loaded?
  25. if(resp.posts && (resp.posts.author || resp.posts.length == 0)) {
  26. self.trigger("allPostsLoaded", self);
  27. }
  28. }
  29. )
  30. return this;
  31. },
  32. basePath : function(){
  33. return document.location.pathname;
  34. },
  35. timeFilteredPath : function(){
  36. return this.basePath() + "?max_time=" + this.maxTime();
  37. },
  38. maxTime: function(){
  39. var lastPost = _.last(this.posts.models);
  40. var isOnParticipateStream = this.basePath().match(/participate/);
  41. return (isOnParticipateStream == null) ? lastPost.createdAt() : lastPost.interactedAt();
  42. },
  43. add : function(models){
  44. this.posts.add(models)
  45. }
  46. })