Skip to content

Commit

Permalink
Prefer twitterSecurityService to springSecurityService.
Browse files Browse the repository at this point in the history
Simplify TimelineService.getTimelineForUser.
Add titles to gravatar images.
  • Loading branch information
fantastic-penguin committed Jan 4, 2017
1 parent f583e1b commit 41f58e3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
18 changes: 11 additions & 7 deletions grails-app/controllers/org/grails/twitter/StatusController.groovy
Expand Up @@ -8,26 +8,30 @@ class StatusController {

def statusService
def timelineService
def springSecurityService
def twitterSecurityService

def index() {
def messages = timelineService.getTimelineForUser()
def username = springSecurityService.principal.username
def messages = timelineService.timelineForUser
def username = twitterSecurityService.currentUsername
def person = Person.findByUserName(username)
def tweetCount = Status.where { author.userName == username }.count()
def totalStatusCount = Status.where { author.userName == username }.count()

def following = person.followed
def followers = Person.where { followed.userName == username }.list()
def otherUsers = Person.list() - following - followers - person

[statusMessages: messages, person: person, tweetCount: tweetCount,
following: following, followers: followers, otherUsers: otherUsers]
[statusMessages: messages,
person: person,
totalStatusCount: totalStatusCount,
following: following,
followers: followers,
otherUsers: otherUsers]
}

def updateStatus(String message) {
statusService.updateStatus message
def messages = timelineService.getTimelineForUser()

def messages = timelineService.timelineForUser
def content = twitter.renderMessages messages: messages
render content
}
Expand Down
26 changes: 10 additions & 16 deletions grails-app/services/org/grails/twitter/TimelineService.groovy
Expand Up @@ -6,24 +6,18 @@ class TimelineService {

static transactional = false

def springSecurityService
def twitterSecurityService

void clearTimelineCacheForUser(String username) {}
void clearTimelineCacheForUser(String username) { }

def getTimelineForUser(String username = springSecurityService.principal.username) {
def per = Person.where {
userName == username
}.find()

def query = Status.whereAny {
author {
userName == per.userName
def getTimelineForUser(String username = twitterSecurityService.currentUsername) {
def person = Person.findByUserName(username)
if (person) {
def query = Status.whereAny {
author == person
author in person.followed
}
if(per.followed) author in per.followed
}.order 'dateCreated', 'desc'

def messages = query.list(max: 10)

messages
query.list(max: 10, sort: 'dateCreated', order: 'desc')
}
}
}
5 changes: 3 additions & 2 deletions grails-app/views/status/_peopleList.gsp
@@ -1,8 +1,9 @@
<ul class="personList">
<g:each in="${people}" var="p">
<li>
<gravatar:image email="${p.email ?: p.displayName}" defaultGravatarUrl="retro" />
${p.displayName}
<gravatar:image email="${p.email ?: p.displayName}" title="${p.displayName}"
defaultGravatarUrl="retro" />
${p.displayName} <span class="byline"> @${p.userName}</span>
</li>
</g:each>
</ul>
1 change: 1 addition & 0 deletions grails-app/views/status/_statusMessage.gsp
@@ -1,5 +1,6 @@
<div class="statusMessage" id="message_${statusMessage.id}">
<gravatar:image email="${statusMessage.author.email ?: statusMessage.author.displayName}"
title="${statusMessage.author.displayName}"
defaultGravatarUrl="retro" />
<div>
<div class="byline">
Expand Down
5 changes: 3 additions & 2 deletions grails-app/views/status/index.gsp
Expand Up @@ -12,12 +12,13 @@
<div class="column sideboard">
<div id="profile" class="panel">
<div>
<gravatar:image email="${person.email ?: person.displayName}" defaultGravatarUrl="retro" />
<gravatar:image email="${person.email ?: person.displayName}" title="${person.displayName}"
defaultGravatarUrl="retro" />
<h2>${displayName}</h2>
</div>
<div id="userStats">
<dl>
<dt><g:message code="status.updateCount.label" /></dt><dd>${tweetCount}</dd>
<dt><g:message code="status.updateCount.label" /></dt><dd>${totalStatusCount}</dd>
<dt><g:message code="status.followingCount.label" /></dt><dd>${following.size()}</dd>
<dt><g:message code="status.followersCount.label" /></dt><dd>${followers.size()}</dd>
</dl>
Expand Down

0 comments on commit 41f58e3

Please sign in to comment.