Skip to content

Commit

Permalink
Improve info tooltip login state and failure handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromakode committed Sep 22, 2009
1 parent cf56410 commit 4270691
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
44 changes: 25 additions & 19 deletions content/reddit/redditSiteInfo.xml
Expand Up @@ -23,12 +23,12 @@
<xul:label anonid="labelMailCount" class="reddit-mail-count">?</xul:label>
</xul:hbox>
</xul:row>
<xul:row>
<xul:row class="reddit-karma-info">
<xul:label>&linkKarma.label;</xul:label>
<xul:spacer flex="1"/>
<xul:label anonid="labelLinkKarma" class="socialite-site-info-data reddit-link-karma">...</xul:label>
</xul:row>
<xul:row>
<xul:row class="reddit-karma-info">
<xul:label>&commentKarma.label;</xul:label>
<xul:spacer flex="1"/>
<xul:label anonid="labelCommentKarma" class="socialite-site-info-data reddit-comment-karma">...</xul:label>
Expand Down Expand Up @@ -59,24 +59,30 @@

this.site.API.auth.getAuthInfo(function(authInfo) {
self.setAttribute("isloggedin", authInfo.isLoggedIn);
setLabel("labelUsername", authInfo.username);
}).perform();

var messageCount = this.site.newMessages.length;
setLabel("labelMailCount", messageCount);
var imageMailIcon = document.getAnonymousElementByAttribute(this, "anonid", "imageMailIcon");
if (messageCount > 0) {
imageMailIcon.src = "chrome://socialite/content/reddit/mail.png";
} else {
imageMailIcon.src = "chrome://socialite/content/reddit/mailgray.png";
}

this.site.cached.myuserinfo(
function success(r, json) {
setLabel("labelLinkKarma", json.data.link_karma);
setLabel("labelCommentKarma", json.data.comment_karma);
if (authInfo.isLoggedIn) {
setLabel("labelUsername", authInfo.username);

var messageCount = self.site.newMessages.length;
setLabel("labelMailCount", messageCount);
var imageMailIcon = document.getAnonymousElementByAttribute(self, "anonid", "imageMailIcon");
if (messageCount > 0) {
imageMailIcon.src = "chrome://socialite/content/reddit/mail.png";
} else {
imageMailIcon.src = "chrome://socialite/content/reddit/mailgray.png";
}

self.site.cached.myuserinfo(
function success(r, json) {
setLabel("labelLinkKarma", json.data.link_karma);
setLabel("labelCommentKarma", json.data.comment_karma);
self.setAttribute("showkarma", true);
},
function failure() {
self.setAttribute("showkarma", false);
}
).perform();
}
).perform();
}).perform();
</body>
</method>
</implementation>
Expand Down
2 changes: 1 addition & 1 deletion modules/reddit/authentication.jsm
Expand Up @@ -101,7 +101,7 @@ function extractAuthInfo(document) {
username: extractUsername(document),
modhash: extractModHash(document)
};
authInfo.isLoggedIn = (authInfo.username != false) && (authInfo.modhash != "");
authInfo.isLoggedIn = (authInfo.username != false) && (authInfo.username != null) && (authInfo.modhash != "");
return authInfo;
}

Expand Down
8 changes: 8 additions & 0 deletions skin/reddit.css
Expand Up @@ -23,4 +23,12 @@

.reddit-subreddit:hover {
text-decoration: underline;
}

.reddit-site-info .socialite-site-info-username {
margin-right: 1em !important;
}

.reddit-site-info[showkarma="false"] .reddit-karma-info {
display:none;
}

0 comments on commit 4270691

Please sign in to comment.