Skip to content

Commit

Permalink
Updating shared story comments, displaying multiple comments for test…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
samuelclay committed Dec 17, 2011
1 parent b94d48b commit b166d37
Show file tree
Hide file tree
Showing 6 changed files with 640 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/social/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

urlpatterns = patterns('',
url(r'^share_story/?$', views.mark_story_as_shared, name='mark-story-as-shared'),
url(r'^(?P<user_id>\d+)/(?P<username>\w+)/?$', views.shared_story_feed, name='shared-story-feed'),
url(r'^(?P<username>\w+)/?$', views.shared_stories_public, name='shared-stories-public'),
)
64 changes: 61 additions & 3 deletions apps/social/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import datetime
import zlib
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseRedirect, Http404
from apps.rss_feeds.models import MStory
from apps.social.models import MSharedStory
from utils import json_functions as json
from utils.user_functions import ajax_login_required
from utils import log as logging
from utils import PyRSS2Gen as RSS


@ajax_login_required
@json.json_view
Expand All @@ -14,14 +20,66 @@ def mark_story_as_shared(request):
comments = request.POST.get('comments', '')

story = MStory.objects(story_feed_id=feed_id, story_guid=story_id).limit(1)
if story:
if not story:
return {'code': -1, 'message': 'Story not found.'}

shared_story = MSharedStory.objects.filter(user_id=request.user.pk, story_feed_id=feed_id, story_guid=story_id)
if not shared_story:
story_db = dict([(k, v) for k, v in story[0]._data.items()
if k is not None and v is not None])
now = datetime.datetime.now()
story_values = dict(user_id=request.user.pk, shared_date=now, comments=comments, **story_db)
MSharedStory.objects.create(**story_values)
logging.user(request, "~FCSharing: ~SB~FM%s (~FB%s~FM)" % (story[0].story_title[:50], comments[:100]))
else:
code = -1
shared_story = shared_story[0]
shared_story.comments = comments
shared_story.save()
logging.user(request, "~FCUpdating shared story: ~SB~FM%s (~FB%s~FM)" % (story[0].story_title[:50], comments[:100]))


return {'code': code}

return {'code': code}
def shared_story_feed(request, user_id, username):
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
raise Http404

if user.username != username:
return HttpResponseRedirect(reverse('shared-story-feed', kwargs={'username': user.username, 'user_id': user.pk}))

data = {}
data['title'] = "%s - Shared Stories" % user.username
link = reverse('shared-stories-public', kwargs={'username': user.username})
data['link'] = "http://www.newsblur.com/%s" % link
data['description'] = "Stories shared by %s on NewsBlur." % user.username
data['lastBuildDate'] = datetime.datetime.utcnow()
data['items'] = []
data['generator'] = 'NewsBlur'
data['docs'] = None

shared_stories = MSharedStory.objects.filter(user_id=user.pk)[:30]
for shared_story in shared_stories:
story_data = {
'title': shared_story.story_title,
'link': shared_story.story_permalink,
'description': zlib.decompress(shared_story.story_content_z),
'guid': shared_story.story_guid,
'pubDate': shared_story.story_date,
}
data['items'].append(RSS.RSSItem(**story_data))

rss = RSS.RSS2(**data)

return HttpResponse(rss.to_xml())

def shared_stories_public(request, username):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise Http404

shared_stories = MSharedStory.objects.filter(user_id=user.pk)

return HttpResponse("There are %s stories shared by %s." % (shared_stories.count(), username))
73 changes: 73 additions & 0 deletions media/css/reader.css
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,80 @@ background: transparent;
max-width: 700px;
min-height: 66px;
}
#story_pane .NB-feed-story-comments {
margin: -24px 200px 32px 28px;
padding: 1px 0 0;
max-width: 700px;
border-top: 2px solid #353535;
border-bottom: 1px solid #353535;
}
#story_pane .NB-story-comment {
border-top: 1px solid #A6A6A6;
background-color: #FCFCFC;
position: relative;
padding: 0 12px 0 54px;
line-height: 20px;
overflow: hidden;
}
#story_pane .NB-story-comment .NB-user-avatar {
position: absolute;
left: 6px;
top: 6px;
}
#story_pane .NB-story-comment .NB-user-avatar img {
border: 1px solid #A6A6A6;
width: 36px;
height: 36px;
}
#story_pane .NB-story-comment .NB-story-comment-author-container {
overflow: hidden;
margin: 6px 0 0;
}
#story_pane .NB-story-comment .NB-story-comment-username {
float: left;
font-size: 11px;
color: #1D4BA6;
font-weight: bold;
margin: 0 10px 0 0;
text-shadow: 0 -1px 0 #F0F0F0;
}
#story_pane .NB-story-comment .NB-story-comment-date {
text-transform: uppercase;
font-size: 10px;
color: #9D9D9D;
font-weight: bold;
text-shadow: 0 -1px 0 #F0F0F0;
}
#story_pane .NB-story-comment .NB-story-comment-content {
float: left;
color: #505050;
}
#story_pane .NB-story-comments-public-teaser-wrapper {
border-top: 1px solid #353535;
padding: 1px 0;
cursor: pointer;
}
#story_pane .NB-story-comments-public-teaser {
background-color: #B1B6B4;
color: white;
text-shadow: 0 1px 0 black;
text-transform: uppercase;
font-size: 10px;
padding: 2px 12px;
-webkit-transition: all .12s ease-out;
-moz-transition: all .12s ease-out;
-o-transition: all .12s ease-out;
-ms-transition: all .12s ease-out;
}

#story_pane .NB-story-comments-public-teaser-wrapper:hover .NB-story-comments-public-teaser {
background-color: #2B478C;
background-image: none;
}
#story_pane .NB-story-comment .NB-story-comment-content {
clear: both;
padding: 0 0 6px 0;
}
#story_pane .NB-feed-story-sideoptions-container {
position: absolute;
right: 12px;
Expand Down
23 changes: 21 additions & 2 deletions media/iphone/Classes/NewsBlurViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ - (IBAction)doSwitchSitesUnread {
// [self.sitesButton setTitle:@"All Sites"];
}

NSIndexPath *topIndexPath = [[self.feedTitlesTable indexPathsForVisibleRows] objectAtIndex:0];
NSString *topFolderName = [appDelegate.dictFoldersArray objectAtIndex:topIndexPath.section];
NSArray *feeds = [appDelegate.dictFolders objectForKey:topFolderName];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:topFolderName];
int location = [[activeFolderFeeds objectAtIndex:topIndexPath.row] intValue];
id topFeedId = [feeds objectAtIndex:location];

NSInteger intelligenceLevel = [appDelegate selectedIntelligence];
NSMutableArray *indexPaths = [NSMutableArray array];

Expand Down Expand Up @@ -369,8 +376,20 @@ - (IBAction)doSwitchSitesUnread {
}
[self.feedTitlesTable endUpdates];

CGPoint offset = CGPointMake(0, 0);
[self.feedTitlesTable setContentOffset:offset animated:YES];
// Find the top feed and scroll to it
NSArray *topActiveFolderFeeds = [self.activeFeedLocations objectForKey:topFolderName];
for (int i=0; i < [topActiveFolderFeeds count]; i++) {
int location = [[topActiveFolderFeeds objectAtIndex:i] intValue];
id feedId = [feeds objectAtIndex:location];
if (feedId == topFeedId) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i
inSection:topIndexPath.section];
CGRect rowFrame = [self.feedTitlesTable rectForRowAtIndexPath:indexPath];
CGPoint origin = rowFrame.origin;
[self.feedTitlesTable setContentOffset:origin animated:YES];
break;
}
}

// Forget still visible feeds, since they won't be populated when
// all feeds are showing, and shouldn't be populated after this
Expand Down
40 changes: 40 additions & 0 deletions media/js/newsblur/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,7 @@
])
]),
$.make('div', { className: 'NB-feed-story-content' }, this.make_story_content(story.story_content)),
$.make('div', { className: 'NB-feed-story-comments' }, this.make_story_share_comments(story)),
$.make('div', { className: 'NB-feed-story-sideoptions-container' }, [
$.make('div', { className: 'NB-sideoption NB-feed-story-train' }, [
$.make('div', { className: 'NB-sideoption-icon'}, '&nbsp;'),
Expand Down Expand Up @@ -3730,6 +3731,45 @@
return $story_content;
},

make_story_share_comments: function(story) {
var $comments = $([]);

var $share = $.make('div', { className: 'NB-story-comments-sharers' }, 'Shared by: ');
var $comment = this.make_story_share_comment({'content': 'Pour some sugar on this comment form. It\'s done.'});
var $comment2 = this.make_story_share_comment({'content': 'These are all AWESOME changes and things we wished we\'d had when we were doing our campaign! Good job, guys. Go go gadget team!'});
var $comment3 = this.make_story_share_comment({'content': 'So cool to get a glimpse of the NewsBlur team and offices! (Love the farm table and tin wainscotting). Thanks for sharing the love with my baby girl! And never apologize for delicious sandwiches. ;)'});

var $public_teaser = $.make('div', { className: 'NB-story-comments-public-teaser-wrapper' }, [
$.make('div', { className: 'NB-story-comments-public-teaser' }, [
'There are ',
$.make('b', { style: 'padding: 0 1px' }, '3'),
' public comments'
])
]);

Math.random() < .35 && $comments.push($comment);
Math.random() < .45 && $comments.push($comment2);
Math.random() < .35 && $comments.push($comment3);
Math.random() < .45 && $comments.push($public_teaser);

return $comments;
},

make_story_share_comment: function(comment) {
var $comment = $.make('div', { className: 'NB-story-comment' }, [
$.make('div', { className: 'NB-user-avatar' }, [
$.make('img', { src: '/media/img/reader/account_standard_3.jpg' })
]),
$.make('div', { className: 'NB-story-comment-author-container' }, [
$.make('div', { className: 'NB-story-comment-username' }, 'samuelclay'),
$.make('div', { className: 'NB-story-comment-date' }, '2 hours ago')
]),
$.make('div', { className: 'NB-story-comment-content' }, comment.content)
]);

return $comment;
},

make_story_feed_title: function(story) {
var title = story.story_title;
var feed_titles = this.model.classifiers[story.story_feed_id] &&
Expand Down
Loading

0 comments on commit b166d37

Please sign in to comment.