Skip to content

Commit

Permalink
fixed new_count, etc to calculate based on mojo model
Browse files Browse the repository at this point in the history
  • Loading branch information
thynctank committed Mar 28, 2010
1 parent 1edf540 commit cc24f4d
Show file tree
Hide file tree
Showing 4 changed files with 2,201 additions and 2,228 deletions.
51 changes: 10 additions & 41 deletions app/assistants/my-timeline-assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,51 +272,20 @@ MyTimelineAssistant.prototype.initTimeline = function() {
// TODO: Timeline list widget
// remove invalid data, massage into format that works for view interpolation, sort
thisA.renderTimeline();

/*
sort timeline
*/
var before = new Date();

// don't sort if we don't have anything new!
if (no_dupes.length > 0) {
// get first of new times
var new_first_time = no_dupes[0].SC_created_at_unixtime;
// get last of new times
var new_last_time = no_dupes[no_dupes.length-1].SC_created_at_unixtime;
// get first of OLD times
var old_first_time = parseInt($oldFirst.attr('data-timestamp'), 10);

sch.debug('new_first_time:'+new_first_time);
sch.debug('new_last_time:'+new_last_time);
sch.debug('old_first_time:'+old_first_time);

// sort if either first new or last new is OLDER than the first old
if (new_first_time < old_first_time || new_last_time < old_first_time) {
jQuery('#my-timeline div.timeline-entry').tsort({attr:'data-timestamp', place:'orig', order:'desc'});
} else {
sch.debug('Didn\'t resort…');
}

}
var after = new Date();
var total = new Date();
total.setTime(after.getTime() - before.getTime());
sch.debug('Sorting took ' + total.getMilliseconds() + 'ms');

sc.helpers.updateRelativeTimes('#my-timeline div.timeline-entry span.date', 'data-created_at');

/*
re-apply filtering
*/
thisA.filterTimeline();

/*
Get new counts
*/
var new_count = jQuery('#my-timeline div.timeline-entry.new:visible').length;
var new_mention_count = jQuery('#my-timeline div.timeline-entry.new.reply:visible').length;
var new_dm_count = jQuery('#my-timeline div.timeline-entry.new.dm:visible').length;
var new_count = thisA.timelineModel.items.select(function(tweet) {
return !tweet.not_new;
}).length;
var new_mention_count = thisA.timelineModel.items.select(function(tweet) {
return (!tweet.not_new && tweet.SC_is_reply);
}).length;
var new_dm_count = thisA.timelineModel.items.select(function(tweet) {
return (!tweet.not_new && tweet.SC_is_dm);
}).length;

/*
Scroll to the first new if there are new messages
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ scene_helpers.addCommonSceneMethods = function(assistant) {

this.filterState = command;
this.controller.modelChanged(this.timelineModel);
this.scrollToTop();
};

assistant.renderTimeline = function(skipFilter) {
Expand All @@ -298,6 +297,7 @@ scene_helpers.addCommonSceneMethods = function(assistant) {
tweet.status = null;
tweet.status = tweet.not_new ? "" : "new";
tweet.status += tweet.SC_is_reply ? " reply" : "";
tweet.status += tweet.SC_is_dm ? " dm" : "";
tweet.protected_icon = tweet.user["protected"] ? "protected-icon" : "";
tweet.relative_time = sch.getRelativeTime(tweet.created_at);
return tweet;
Expand Down
29 changes: 17 additions & 12 deletions app/views/shared/dm.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<div class="timeline-entry new" data-status-id="#{id}" data-user-id="#{sender.id}" data-user-screen_name="#{sender.screen_name}" data-timestamp="#{created_at_unixtime}">
<div class="user" data-user-id="#{sender.id}" data-user-screen_name="#{sender.screen_name}">
<img src="#{sender.profile_image_url}" title="#{sender.screen_name}" />
</div>
<div class="status">
<div class="screen-name">#{sender.screen_name}</div>
<div class="text">
#{text}
</div>
<div class="meta" data-status-id="#{id}"><span class="date" data-created_at="#{created_at}">#{relative_time}</span> &#x2192;</div>
</div>
<!-- status should be "new" or "" -->
<div class="timeline-entry dm #{status}" data-isdm="true" data-status-id="#{id}" data-user-id="#{sender.id}" data-user-screen_name="#{sender.screen_name}" data-timestamp="#{SC_created_at_unixtime}">
<div class="user" data-user-id="#{sender.id}" data-user-screen_name="#{sender.screen_name}">
<div class="user-img rounded-user-image" style="background-image:url('#{sender.profile_image_url})"></div>
</div>
<div class="status">
<div class="meta-wrapper">
<div class="screen-name">#{sender.screen_name}</div>
<!-- relative_time should be sch.getRelativeTime(d.created_at) -->
<div class="meta" data-status-id="#{id}">
<span class="date" data-created_at="#{created_at}">#{relative_time}</span>
</div>
</div>
<div class="text">
#{text}
</div>
</div>
</div>

Loading

0 comments on commit cc24f4d

Please sign in to comment.