Add a way to fetch our current profile ID.
This commit is contained in:
2
api.py
2
api.py
@@ -35,11 +35,13 @@ def CreateChannel(google_user, client, args):
|
|||||||
if google_user:
|
if google_user:
|
||||||
events.append({
|
events.append({
|
||||||
'event_type': 'login',
|
'event_type': 'login',
|
||||||
|
'profile': str(client.parent_key()),
|
||||||
'google_user': google_user.email(),
|
'google_user': google_user.email(),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
events.append({
|
events.append({
|
||||||
'event_type': 'logout',
|
'event_type': 'logout',
|
||||||
|
'profile': str(client.parent_key()),
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ Cosmopolite = function(callbacks, urlPrefix, namespace) {
|
|||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown this instance.
|
||||||
|
*
|
||||||
|
* No callbacks will fire after this returns.
|
||||||
|
*/
|
||||||
Cosmopolite.prototype.shutdown = function() {
|
Cosmopolite.prototype.shutdown = function() {
|
||||||
console.log(this.loggingPrefix_(), 'shutdown');
|
console.log(this.loggingPrefix_(), 'shutdown');
|
||||||
this.shutdown_ = true;
|
this.shutdown_ = true;
|
||||||
@@ -164,6 +169,22 @@ Cosmopolite.prototype.getKeyMessage = function(subject, key) {
|
|||||||
return this.subscriptions_[subject].keys[key];
|
return this.subscriptions_[subject].keys[key];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return our current profile ID, if known.
|
||||||
|
*
|
||||||
|
* @return {?string} Profile ID.
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
|
Cosmopolite.prototype.profile = function() {
|
||||||
|
return this.profile_ || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a string identifying us to be included in log messages.
|
||||||
|
*
|
||||||
|
* @return {string} Log line prefix.
|
||||||
|
* @const
|
||||||
|
*/
|
||||||
Cosmopolite.prototype.loggingPrefix_ = function() {
|
Cosmopolite.prototype.loggingPrefix_ = function() {
|
||||||
return 'cosmopolite (' + this.namespace_ + '):';
|
return 'cosmopolite (' + this.namespace_ + '):';
|
||||||
};
|
};
|
||||||
@@ -417,6 +438,9 @@ Cosmopolite.prototype.onServerEvent_ = function(e) {
|
|||||||
if (this.shutdown_) {
|
if (this.shutdown_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (e['profile']) {
|
||||||
|
this.profile_ = e['profile'];
|
||||||
|
}
|
||||||
switch (e['event_type']) {
|
switch (e['event_type']) {
|
||||||
case 'login':
|
case 'login':
|
||||||
if ('onLogin' in this.callbacks_) {
|
if ('onLogin' in this.callbacks_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user