diff --git a/api.py b/api.py index 9fd99e4..d10e746 100644 --- a/api.py +++ b/api.py @@ -30,7 +30,7 @@ def CreateChannel(google_user, client, args): token = channel.create_channel( client_id=str(client.key()), duration_minutes=config.CHANNEL_DURATION_SECONDS / 60) - events = [x.ToEvent() for x in client.parent().GetStateEntries()] + events = [] if google_user: events.append({ 'event_type': 'login', @@ -57,37 +57,6 @@ def SendMessage(google_user, client, args): return {} -@db.transactional() -def SetValue(google_user, client, args): - entry_key = args['key'] - entry_value = args['value'] - public = (args['public'] == 'true') - - entries = (models.StateEntry.all() - .ancestor(client.parent_key()) - .filter('entry_key =', entry_key) - .fetch(1)) - if entries: - entry = entries[0] - entry.entry_value = entry_value - entry.public = public - else: - entry = models.StateEntry( - parent=client.parent_key(), - entry_key=entry_key, - entry_value=entry_value, - public=public) - - entry.put() - event = entry.ToEvent() - clients = (models.Client.all() - .ancestor(client.parent_key())) - for client in clients: - client.SendEvent(event) - - return {} - - def Subscribe(google_user, client, args): subject = models.Subject.FindOrCreate(args['subject']) messages = args.get('messages', 0) @@ -115,7 +84,6 @@ class APIWrapper(webapp2.RequestHandler): _COMMANDS = { 'createChannel': CreateChannel, 'sendMessage': SendMessage, - 'setValue': SetValue, 'subscribe': Subscribe, 'unsubscribe': Unsubscribe, } diff --git a/lib/models.py b/lib/models.py index 4d5a30d..d391be1 100644 --- a/lib/models.py +++ b/lib/models.py @@ -24,7 +24,6 @@ import utils # Profile # ↳ Client -# ↳ StateEntry # # Subject # ↳ Message @@ -54,6 +53,7 @@ class Profile(db.Model): def MergeFrom(self, source_profile): # Merge from another profile into this one, using last_set time as the # arbiter. + # TODO: this is totally broken my_states = {} for state_entry in self.GetStateEntries(): my_states[state_entry.entry_key] = state_entry @@ -74,10 +74,6 @@ class Profile(db.Model): entry_value=state_entry.entry_value ).put() - @db.transactional() - def GetStateEntries(self): - return StateEntry.all().ancestor(self) - class Client(db.Model): # parent=Profile @@ -104,24 +100,6 @@ class Client(db.Model): channel.send_message(str(key), json.dumps(msg, default=utils.EncodeJSON)) -class StateEntry(db.Model): - # parent=Profile - - last_set = db.DateTimeProperty(required=True, auto_now=True) - entry_key = db.StringProperty(required=True) - entry_value = db.StringProperty() - public = db.BooleanProperty(required=True, default=False) - - def ToEvent(self): - return { - 'event_type': 'state', - 'key': self.entry_key, - 'value': self.entry_value, - 'last_set': self.last_set, - 'public': self.public, - } - - class Subject(db.Model): # key_name=name diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 5b8326e..8360c24 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -33,7 +33,6 @@ cosmopolite.Client = function(opt_callbacks, opt_urlPrefix, opt_namespace) { this.urlPrefix_ = opt_urlPrefix || '/cosmopolite'; this.namespace_ = opt_namespace || 'cosmopolite'; - this.stateCache_ = {}; this.subscriptions_ = {}; var scriptUrls = [ @@ -49,25 +48,8 @@ cosmopolite.Client = function(opt_callbacks, opt_urlPrefix, opt_namespace) { }, this); }; -cosmopolite.Client.prototype.setValue = function(key, value, is_public) { - this.sendRPC_('setValue', { - 'key': key, - 'value': value, - 'public': is_public, - }); - // Provide immediate feedback without waiting for a round trip. - // We'll also get a response from the server, so this should be eventually - // consistent. - if ('onStateChange' in this.callbacks_) { - this.callbacks_['onStateChange'](key, value); - } -}; - -cosmopolite.Client.prototype.getValue = function(key) { - return this.stateCache_[key]; -}; - -cosmopolite.Client.prototype.subscribe = function(subject, messages) { +cosmopolite.Client.prototype.subscribe = function(subject, messages, keys) { + keys = keys || []; if (subject in this.subscriptions_) { console.log('Not sending duplication subscription request for subject:', subject); return; @@ -78,6 +60,7 @@ cosmopolite.Client.prototype.subscribe = function(subject, messages) { this.sendRPC_('subscribe', { 'subject': subject, 'messages': messages, + 'keys': keys, }); }; @@ -268,24 +251,6 @@ cosmopolite.Client.prototype.onSocketMessage_ = function(msg) { cosmopolite.Client.prototype.onServerEvent_ = function(e) { switch (e.event_type) { - case 'state': - var key = e['key']; - if (this.stateCache_[key] && - this.stateCache_[key]['value'] == e['value'] && - this.stateCache_[key]['last_set'] == e['last_set'] && - this.stateCache_[key]['public'] == e['public']) { - // Duplicate event. - break; - } - this.stateCache_[key] = { - 'value': e['value'], - 'last_set': e['last_set'], - 'public': e['public'], - } - if ('onStateChange' in this.callbacks_) { - this.callbacks_['onStateChange'](key, this.stateCache_[key]); - } - break; case 'login': if ('onLogin' in this.callbacks_) { this.callbacks_['onLogin']( diff --git a/static/debug.html b/static/debug.html index 0454db4..2c93f84 100644 --- a/static/debug.html +++ b/static/debug.html @@ -10,25 +10,6 @@ a {