Fix payload behaviour for empty strings / 0 values. (#16)
This commit is contained in:
committed by
Sergey Petrov
parent
2b8bbced17
commit
c51aceb64e
+8
-7
@@ -43,8 +43,9 @@ class PayloadAlert(object):
|
||||
|
||||
|
||||
class Payload(object):
|
||||
def __init__(self, alert=None, badge=None, sound=None, content_available=None,
|
||||
mutable_content=False, category=None, custom=None):
|
||||
def __init__(self, alert=None, badge=None, sound=None,
|
||||
content_available=False, mutable_content=False,
|
||||
category=None, custom=None):
|
||||
self.alert = alert
|
||||
self.badge = badge
|
||||
self.sound = sound
|
||||
@@ -57,22 +58,22 @@ class Payload(object):
|
||||
result = {
|
||||
'aps': {}
|
||||
}
|
||||
if self.alert:
|
||||
if self.alert is not None:
|
||||
if isinstance(self.alert, PayloadAlert):
|
||||
result['aps']['alert'] = self.alert.dict()
|
||||
else:
|
||||
result['aps']['alert'] = self.alert
|
||||
if self.badge:
|
||||
if self.badge is not None:
|
||||
result['aps']['badge'] = self.badge
|
||||
if self.sound:
|
||||
if self.sound is not None:
|
||||
result['aps']['sound'] = self.sound
|
||||
if self.content_available:
|
||||
result['aps']['content-available'] = 1
|
||||
if self.mutable_content:
|
||||
result['aps']['mutable-content'] = 1
|
||||
if self.category:
|
||||
if self.category is not None:
|
||||
result['aps']['category'] = self.category
|
||||
if self.custom:
|
||||
if self.custom is not None:
|
||||
result.update(self.custom)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user