Switch to using Instance key as the channel_id, since there seems to be an undocumented length limit.
This commit is contained in:
4
api.py
4
api.py
@@ -28,8 +28,10 @@ import config
|
||||
|
||||
|
||||
def CreateChannel(google_user, client, instance_id, args):
|
||||
instance = models.Instance.FindOrCreate(instance_id, client)
|
||||
|
||||
token = channel.create_channel(
|
||||
client_id=str(client.key()) + '/' + instance_id,
|
||||
client_id=str(instance),
|
||||
duration_minutes=config.CHANNEL_DURATION_SECONDS / 60)
|
||||
events = []
|
||||
if google_user:
|
||||
|
||||
14
channel.py
14
channel.py
@@ -25,23 +25,23 @@ class OnChannelConnect(webapp2.RequestHandler):
|
||||
@utils.local_namespace
|
||||
@db.transactional()
|
||||
def post(self):
|
||||
client_key, instance_id = self.request.get('from').split('/', 1)
|
||||
client = models.Client.get(client_key)
|
||||
instance = models.Instance.FindOrCreate(instance_id, client)
|
||||
instance_key = self.request.get('from')
|
||||
instance = models.Instance.get(instance_key)
|
||||
instance.active = True
|
||||
instance.put()
|
||||
|
||||
|
||||
class OnChannelDisconnect(webapp2.RequestHandler):
|
||||
@utils.local_namespace
|
||||
def post(self):
|
||||
client_key, instance_id = self.request.get('from').split('/', 1)
|
||||
client = models.Client.get(client_key)
|
||||
instance = models.Instance.FindOrCreate(instance_id, client)
|
||||
instance_key = self.request.get('from')
|
||||
instance = models.Instance.get(instance_key)
|
||||
|
||||
subscriptions = models.Subscription.all().filter('instance =', instance)
|
||||
for subscription in subscriptions:
|
||||
subscription.delete()
|
||||
|
||||
models.Instance.get(instance).delete()
|
||||
instance.delete()
|
||||
|
||||
|
||||
app = webapp2.WSGIApplication([
|
||||
|
||||
@@ -89,6 +89,7 @@ class Instance(db.Model):
|
||||
# parent=Client
|
||||
|
||||
id_ = db.StringProperty(required=True)
|
||||
active = db.BooleanProperty(required=True, default=False)
|
||||
|
||||
@classmethod
|
||||
@db.transactional()
|
||||
@@ -112,11 +113,6 @@ class Instance(db.Model):
|
||||
else:
|
||||
return cls(parent=client, id_=instance_id).put()
|
||||
|
||||
def SendMessage(self, msg):
|
||||
channel.send_message(
|
||||
str(self.parent_key()) + '/' + self.id_,
|
||||
json.dumps(msg, default=utils.EncodeJSON))
|
||||
|
||||
|
||||
class Subject(db.Model):
|
||||
|
||||
@@ -231,7 +227,7 @@ class Subject(db.Model):
|
||||
obj, subscriptions = self.PutMessage(message, sender, sender_message_id, key)
|
||||
event = obj.ToEvent()
|
||||
for subscription in subscriptions:
|
||||
subscription.instance.SendMessage(event)
|
||||
subscription.SendMessage(event)
|
||||
|
||||
def ToDict(self):
|
||||
ret = {
|
||||
@@ -284,6 +280,12 @@ class Subscription(db.Model):
|
||||
for subscription in subscriptions:
|
||||
subscription.delete()
|
||||
|
||||
def SendMessage(self, msg):
|
||||
instance_key = Subscription.instance.get_value_for_datastore(self)
|
||||
channel.send_message(
|
||||
str(instance_key),
|
||||
json.dumps(msg, default=utils.EncodeJSON))
|
||||
|
||||
|
||||
class Message(db.Model):
|
||||
# parent=Subject
|
||||
|
||||
Reference in New Issue
Block a user