@@ -86,9 +86,10 @@ $(document).ready(function() {
8686} ) ;
8787
8888
89+ var chatDisplayName = null ; // sign in with Google account to get your real chat name
90+
8991// for Google+ Web signin:
9092// https://developers.google.com/+/web/signin/add-button
91-
9293function signinCallback ( authResult ) {
9394 if ( authResult ) {
9495 if ( authResult [ 'error' ] == undefined ) {
@@ -117,21 +118,19 @@ function signinCallback(authResult) {
117118 // if we can actually grab the display name (e.g., from a
118119 // Google+ account), then use it
119120 if ( resp . displayName ) {
120- $ ( "#loggedInNameDisplay" ) . html ( "Hello, " + resp . displayName ) ;
121+ chatDisplayName = resp . displayName ;
122+ showChatName ( ) ;
121123 }
122124
123125 // otherwise try to look up the email address on the server to
124126 // find a real name mapping on the server
125- else if ( email ) {
127+ else if ( email ) {
126128 $ . get ( 'name_lookup.py' ,
127129 { email : email } ,
128130 function ( data ) {
129- if ( data . name ) {
130- $ ( "#loggedInNameDisplay" ) . html ( "Hello, " + data . name ) ;
131- }
132- else {
133- $ ( "#loggedInNameDisplay" ) . html ( "Hello, " + email ) ;
134- }
131+ // fall back on email address
132+ chatDisplayName = data . name ? data . name : email ;
133+ showChatName ( ) ;
135134 } ,
136135 "json" ) ;
137136 }
@@ -146,6 +145,10 @@ function signinCallback(authResult) {
146145 }
147146}
148147
148+ function showChatName ( ) {
149+ $ ( "#loggedInNameDisplay" ) . html ( "Welcome, " + chatDisplayName ) ;
150+ }
151+
149152// adapted from https://developers.google.com/+/quickstart/javascript
150153/**
151154 * Calls the OAuth2 endpoint to disconnect the app for the user.
@@ -171,7 +174,6 @@ function signout() {
171174 } ) ;
172175 }
173176 else {
174- $ ( '#signinButton' ) . show ( ) ;
175- $ ( '#loggedInDiv' ) . hide ( ) ;
177+ console . log ( 'signout failed :(' ) ;
176178 }
177179}
0 commit comments