Commit d1a21020ebac1b601c9a3cfa63d41d6b4bec2571
1 parent
4624161e
Exists in
master
and in
2 other branches
Changing chat push notification function
Showing
2 changed files
with
13 additions
and
6 deletions
Show diff stats
api/utils.py
... | ... | @@ -32,11 +32,11 @@ def sendChatPushNotification(user, message): |
32 | 32 | |
33 | 33 | response = json.dumps(info) |
34 | 34 | |
35 | - title = str(user).join(_(" sent a message")) | |
35 | + title = str(message.user).join(_(" sent a message")) | |
36 | 36 | |
37 | 37 | simple_notify = textwrap.shorten(strip_tags(message.text), width = 30, placeholder = "...") |
38 | 38 | |
39 | 39 | if message.image: |
40 | 40 | simple_notify += " ".join(_("[Photo]")) |
41 | 41 | |
42 | - device.send_message(title = title, body = simple_notify, data = {"response": response}) | |
43 | 42 | \ No newline at end of file |
43 | + device.send_message(data = {"response": response, "title": title, "body": simple_notify, "user_from": message.user.email, "user_name": str(message.user), "user_img": message.user.image_url}) | |
44 | 44 | \ No newline at end of file | ... | ... |
api/views.py
... | ... | @@ -305,7 +305,14 @@ class ChatViewset(viewsets.ModelViewSet): |
305 | 305 | |
306 | 306 | talk.save() |
307 | 307 | |
308 | - subject = Subject.objects.get(slug = subject) | |
308 | + if subject != "": | |
309 | + subject = Subject.objects.get(slug = subject) | |
310 | + space = subject.slug | |
311 | + space_type = "subject" | |
312 | + else: | |
313 | + subject = None | |
314 | + space = 0 | |
315 | + space_type = "general" | |
309 | 316 | |
310 | 317 | message = TalkMessages() |
311 | 318 | message.text = "<p>" + msg_text + "</p>" |
... | ... | @@ -320,11 +327,11 @@ class ChatViewset(viewsets.ModelViewSet): |
320 | 327 | |
321 | 328 | if not message.pk is None: |
322 | 329 | simple_notify = textwrap.shorten(strip_tags(message.text), width = 30, placeholder = "...") |
323 | - | |
330 | + | |
324 | 331 | notification = { |
325 | 332 | "type": "chat", |
326 | - "subtype": "subject", | |
327 | - "space": subject.slug, | |
333 | + "subtype": space_type, | |
334 | + "space": space, | |
328 | 335 | "user_icon": message.user.image_url, |
329 | 336 | "notify_title": str(message.user), |
330 | 337 | "simple_notify": simple_notify, | ... | ... |