Permalink
Browse files

share-username feature

  • Loading branch information...
1 parent b854bd6 commit 7dd96861cb63bf1bb6c22458b80517a7d32f1a31 @zackster committed Jun 15, 2012
Showing with 59 additions and 12 deletions.
  1. +29 −8 app.js
  2. +1 −1 static/chat-init.js
  3. +17 −1 static/chat.js
  4. +1 −0 static/comm.js
  5. +5 −1 users/models.js
  6. +6 −1 views/chat.jade
View
37 app.js
@@ -366,11 +366,11 @@ function(err) {
lastMessageReceived = data.n || 0,
userAgent = data.a || null,
referrer = data.r || null;
- var cookies = {
- bb_userid: data.bb_userid,
- bb_sessionhash: data.bb_sessionhash,
- bb_password: data.bb_password
- };
+ // var cookies = {
+ // bb_userid: data.bb_userid,
+ // bb_sessionhash: data.bb_sessionhash,
+ // bb_password: data.bb_password
+ // };
var clientId = client.id;
@@ -387,9 +387,6 @@ function(err) {
user.getIPAddress();
user.referrer = referrer || "";
user.userAgent = userAgent || "";
- authServer.checkLoginWithCookies(cookies, user.getIPAddress(), user.userAgent, function(username) {
- console.log('cookie-login called back with username: ', username);
- });
user.disconnect(function() {
var room = Room.getByUserId(user.id);
if (room) {
@@ -424,6 +421,7 @@ function(err) {
if (username !== false) {
authServer.logged_in_users[user.id] = username;
console.log('checkLogin called back with username: ', username);
+ user.setForumsId(username);
callback([config.version, isNewUser, user.id, user.publicId, user.lastReceivedMessageIndex, username]);
}
else {
@@ -440,6 +438,29 @@ function(err) {
Room.checkQueues();
};
+
+
+ socketHandlers.showUsername = function(client, user, data, callback) {
+ var listenerId = user.id,
+ room = Room.getByUserId(listenerId);
+ if (!room) {
+ return;
+ }
+ var venterId = room.conversation.venter.userId;
+ room.sendToUser(venterId, "forum-username", user.forums_id);
+ };
+ socketHandlers.hideUsername = function(client, user, data, callback) {
+ var listenerId = user.id,
+ room = Room.getByUserId(listenerId);
+ if (!room) {
+ return;
+ }
+ var venterId = room.conversation.venter.userId;
+ room.sendToUser(venterId, "forum-username", false);
+ };
+
+
+
/**
* Request the current position the client is in the queue for
View
2 static/chat-init.js
@@ -17,7 +17,7 @@
$(document).ready(function() {
- $("div#Chatmain, div#loggedInAs, div#reputationLogin, div#listenerFeedback, a#meant_to_login, button#register, li.scoreCard").hide();
+ $("div#Chatmain, div#loggedInAs, input#share_username, div#reputationLogin, div#partnerUsername, div#listenerFeedback, a#meant_to_login, button#register, li.scoreCard").hide();
window.LISTENER_LOGGED_IN = false;
var comm = window.Comm.create();
View
18 static/chat.js
@@ -455,7 +455,15 @@
}
}
-
+ $('#share_username').change(function() {
+ if ($(this).is(':checked')){
+ addMessage('System', 'Your partner can now see when your forums username');
+ comm.request("showUsername");
+ } else {
+ addMessage('System', 'Your partner will no longer be able to see your forums username');
+ comm.request("hideUsername");
+ }
+ });
$('#enable_typing').change(function(){
if ($(this).is(':checked')){
addMessage('System', 'Others can now see when you\'re typing');
@@ -516,6 +524,14 @@
.removeClass("hidden");
}
});
+ comm.handler("forum-username", function(username) {
+ if(username) {
+ $("#partnerUsername").html('<b>' + username + '</b>');
+ }
+ else {
+ $("#partnerUsername").hide();
+ }
+ });
comm.handler("received-feedback", function(message) {
window.comm.request("updateHUD", {}, function(userLeaderboard) {
$('li.scoreCard').show().css('display', 'block !important').css('height', 'auto');
View
1 static/comm.js
@@ -196,6 +196,7 @@
$("span#currentUser").html(forums_username);
$("div#reputationLogin").hide();
$("div#loggedInAs").show();
+ $("div#share_username").show();
window.LISTENER_LOGGED_IN = true;
updateHUD();
}
View
6 users/models.js
@@ -24,7 +24,7 @@
this.join_time = new Date().getTime();
this.partner_list = [];
-
+ this.forums_id = false;
this.socket = require("../app").socket;
this.messageBacklog = [];
this.messageQueue = [];
@@ -243,6 +243,10 @@
}
});
};
+
+ User.prototype.setForumsId = function (username) {
+ this.forums_id = username;
+ };
User.prototype.send = function (message) {
message.n = this.lastSentMessageIndex = this.lastSentMessageIndex + 1;
View
7 views/chat.jade
@@ -55,7 +55,11 @@ div(id="main",style="display:none")
option(value="I don't feel I can help you") I don't feel I can help you
button(id="giveApology") Share reason
li#reportAbuse
- a(href="#") Report abuse?
+ a(href="#") Report abuse?
+ li
+ label
+ input(type="checkbox", id="share_username")
+ #{" Share my forums username"}
li
label
input(type="checkbox", id="enable_sound")
@@ -77,6 +81,7 @@ div(id="main",style="display:none")
button(id="login", class="login") Log In!
br
a(href="javascript:return false;", id="register_account", class="login_mistake") Don't have an account? Register one at the CompassionPit Forums!
+ div#partnerUsername
div#listenerFeedback
p Please give feedback to keep CompassionPit high-quality
button(id="helpful") This person is a good listener! =)

0 comments on commit 7dd9686

Please sign in to comment.