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):
|
def CreateChannel(google_user, client, instance_id, args):
|
||||||
|
instance = models.Instance.FindOrCreate(instance_id, client)
|
||||||
|
|
||||||
token = channel.create_channel(
|
token = channel.create_channel(
|
||||||
client_id=str(client.key()) + '/' + instance_id,
|
client_id=str(instance),
|
||||||
duration_minutes=config.CHANNEL_DURATION_SECONDS / 60)
|
duration_minutes=config.CHANNEL_DURATION_SECONDS / 60)
|
||||||
events = []
|
events = []
|
||||||
if google_user:
|
if google_user:
|
||||||
|
|||||||
14
channel.py
14
channel.py
@@ -25,23 +25,23 @@ class OnChannelConnect(webapp2.RequestHandler):
|
|||||||
@utils.local_namespace
|
@utils.local_namespace
|
||||||
@db.transactional()
|
@db.transactional()
|
||||||
def post(self):
|
def post(self):
|
||||||
client_key, instance_id = self.request.get('from').split('/', 1)
|
instance_key = self.request.get('from')
|
||||||
client = models.Client.get(client_key)
|
instance = models.Instance.get(instance_key)
|
||||||
instance = models.Instance.FindOrCreate(instance_id, client)
|
instance.active = True
|
||||||
|
instance.put()
|
||||||
|
|
||||||
|
|
||||||
class OnChannelDisconnect(webapp2.RequestHandler):
|
class OnChannelDisconnect(webapp2.RequestHandler):
|
||||||
@utils.local_namespace
|
@utils.local_namespace
|
||||||
def post(self):
|
def post(self):
|
||||||
client_key, instance_id = self.request.get('from').split('/', 1)
|
instance_key = self.request.get('from')
|
||||||
client = models.Client.get(client_key)
|
instance = models.Instance.get(instance_key)
|
||||||
instance = models.Instance.FindOrCreate(instance_id, client)
|
|
||||||
|
|
||||||
subscriptions = models.Subscription.all().filter('instance =', instance)
|
subscriptions = models.Subscription.all().filter('instance =', instance)
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
subscription.delete()
|
subscription.delete()
|
||||||
|
|
||||||
models.Instance.get(instance).delete()
|
instance.delete()
|
||||||
|
|
||||||
|
|
||||||
app = webapp2.WSGIApplication([
|
app = webapp2.WSGIApplication([
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class Instance(db.Model):
|
|||||||
# parent=Client
|
# parent=Client
|
||||||
|
|
||||||
id_ = db.StringProperty(required=True)
|
id_ = db.StringProperty(required=True)
|
||||||
|
active = db.BooleanProperty(required=True, default=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@db.transactional()
|
@db.transactional()
|
||||||
@@ -112,11 +113,6 @@ class Instance(db.Model):
|
|||||||
else:
|
else:
|
||||||
return cls(parent=client, id_=instance_id).put()
|
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):
|
class Subject(db.Model):
|
||||||
|
|
||||||
@@ -231,7 +227,7 @@ class Subject(db.Model):
|
|||||||
obj, subscriptions = self.PutMessage(message, sender, sender_message_id, key)
|
obj, subscriptions = self.PutMessage(message, sender, sender_message_id, key)
|
||||||
event = obj.ToEvent()
|
event = obj.ToEvent()
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
subscription.instance.SendMessage(event)
|
subscription.SendMessage(event)
|
||||||
|
|
||||||
def ToDict(self):
|
def ToDict(self):
|
||||||
ret = {
|
ret = {
|
||||||
@@ -284,6 +280,12 @@ class Subscription(db.Model):
|
|||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
subscription.delete()
|
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):
|
class Message(db.Model):
|
||||||
# parent=Subject
|
# parent=Subject
|
||||||
|
|||||||
Reference in New Issue
Block a user