Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Fixed push!
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbaumann committed Apr 11, 2011
1 parent 70c752d commit 8ac1628
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion geocamTalk/management/commands/randomtalk.py
Expand Up @@ -57,7 +57,7 @@ def handle(self, *args, **options):

msg.recipients = recipients

msg.push_to_phone()
msg.push_to_phone(True)

print msg

33 changes: 17 additions & 16 deletions geocamTalk/models.py
Expand Up @@ -115,7 +115,7 @@ def getLargestMessageId():
def has_audio(self):
return bool(self.audio_file != '')

def push_to_phone(self):
def push_to_phone(self, pushToSender = True):
message = self

# NOW SEND THE REQUEST TO GOOGLE SERVERS
Expand All @@ -128,18 +128,19 @@ def push_to_phone(self):

for user in push_recipients:
if(user.profile.registration_id):
# we need the following params set per http://code.google.com/android/c2dm/index.html#push
params = urllib.urlencode({
'registration_id': user.profile.registration_id,
'collapse_key': "message"+str(message.pk),
'data.message_id': str(message.pk),
'delay_when_idle':'TRUE',
})

# need the following headers set per http://code.google.com/android/c2dm/index.html#push
headers = { "Content-Type":"application/x-www-form-urlencoded",
"Content-Length":len(params),
"Authorization":"GoogleLogin auth=" + GOOGLE_TOKEN # TOKEN set manually in authentication.py
}

httpsconnection.request("POST", "/c2dm/send", params, headers)
if(pushToSender or user.pk != message.author.pk):
# we need the following params set per http://code.google.com/android/c2dm/index.html#push
params = urllib.urlencode({
'registration_id': user.profile.registration_id,
'collapse_key': "message"+str(message.pk),
'data.message_id': str(message.pk),
'delay_when_idle':'TRUE',
})

# need the following headers set per http://code.google.com/android/c2dm/index.html#push
headers = { "Content-Type":"application/x-www-form-urlencoded",
"Content-Length":len(params),
"Authorization":"GoogleLogin auth=" + GOOGLE_TOKEN # TOKEN set manually in authentication.py
}

httpsconnection.request("POST", "/c2dm/send", params, headers)
6 changes: 5 additions & 1 deletion geocamTalk/views.py
Expand Up @@ -151,10 +151,14 @@ def create_message_json(request):
file_format = os.path.splitext( request.FILES['audio'].name)[-1]
message.audio_file.save(filename, file_content)
try:
print message
message.save()
message.push_to_phone()
print "SAVED"
message.push_to_phone(False)
print "PUSHED"
return HttpResponse(json.dumps({"messageId":"%s" % message.pk, "authorFullname":message.get_author_string()}), 200)
except:

return HttpResponseServerError() # TODO: change the tests and here to respond with HttpResponseBadRequest
else:
return HttpResponseServerError()
Expand Down

0 comments on commit 8ac1628

Please sign in to comment.