Commit 29c961bac237eca5990994ed1705d925c4d0036f
1 parent
49791358
Exists in
master
and in
2 other branches
Adding mural notifications to app
Showing
2 changed files
with
30 additions
and
7 deletions
Show diff stats
api/utils.py
... | ... | @@ -8,7 +8,7 @@ from fcm_django.fcm import fcm_send_message |
8 | 8 | |
9 | 9 | from chat.serializers import ChatSerializer |
10 | 10 | |
11 | -def sendChatPushNotification(user, message): | |
11 | +def sendChatPushNotification(user, message): | |
12 | 12 | device = FCMDevice.objects.filter(user = user, active = True).first() |
13 | 13 | |
14 | 14 | if not device is None: |
... | ... | @@ -39,4 +39,10 @@ def sendChatPushNotification(user, message): |
39 | 39 | if message.image: |
40 | 40 | simple_notify += " ".join(_("[Photo]")) |
41 | 41 | |
42 | - 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}) | |
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, "type": chat}) | |
44 | + | |
45 | +def sendMuralPushNotification(user, user_action, message): | |
46 | + device = FCMDevice.objects.filter(user = user, active = True).first() | |
47 | + | |
48 | + if not device is None: | |
49 | + device.send_message(data = {"title": "Mural", "body": message, "user_img": user_action.image_url, "type": "mural"}) | |
44 | 50 | \ No newline at end of file | ... | ... |
mural/views.py
... | ... | @@ -25,6 +25,8 @@ from log.decorators import log_decorator, log_decorator_ajax |
25 | 25 | import time |
26 | 26 | from datetime import datetime |
27 | 27 | |
28 | +from api.utils import sendMuralPushNotification | |
29 | + | |
28 | 30 | from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites, Comment |
29 | 31 | from .forms import GeneralPostForm, CategoryPostForm, SubjectPostForm, ResourcePostForm, CommentForm |
30 | 32 | from .utils import getSpaceUsers |
... | ... | @@ -146,12 +148,14 @@ class GeneralCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
146 | 148 | |
147 | 149 | paths = [reverse("mural:manage_general")] |
148 | 150 | |
151 | + simple_notify = _("%s has made a post in General")%(str(self.object.user)) | |
152 | + | |
149 | 153 | notification = { |
150 | 154 | "type": "mural", |
151 | 155 | "subtype": "post", |
152 | 156 | "paths": paths, |
153 | 157 | "user_icon": self.object.user.image_url, |
154 | - "simple_notify": _("%s has made a post in General")%(str(self.object.user)), | |
158 | + "simple_notify": simple_notify, | |
155 | 159 | "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), |
156 | 160 | "container": ".post", |
157 | 161 | "accordion": False, |
... | ... | @@ -162,6 +166,7 @@ class GeneralCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
162 | 166 | |
163 | 167 | for user in users: |
164 | 168 | entries.append(MuralVisualizations(viewed = False, user = user, post = self.object)) |
169 | + sendMuralPushNotification(user, self.object.user, simple_notify) | |
165 | 170 | Group("user-%s" % user.id).send({'text': notification}) |
166 | 171 | |
167 | 172 | MuralVisualizations.objects.bulk_create(entries) |
... | ... | @@ -403,12 +408,14 @@ class CategoryCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
403 | 408 | |
404 | 409 | paths = [reverse("mural:manage_category")] |
405 | 410 | |
411 | + simple_notify = _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)) | |
412 | + | |
406 | 413 | notification = { |
407 | 414 | "type": "mural", |
408 | 415 | "subtype": "post", |
409 | 416 | "paths": paths, |
410 | 417 | "user_icon": self.object.user.image_url, |
411 | - "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)), | |
418 | + "simple_notify": simple_notify, | |
412 | 419 | "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), |
413 | 420 | "container": "#" + slug, |
414 | 421 | "accordion": True, |
... | ... | @@ -419,6 +426,7 @@ class CategoryCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
419 | 426 | |
420 | 427 | for user in users: |
421 | 428 | entries.append(MuralVisualizations(viewed = False, user = user, post = self.object)) |
429 | + sendMuralPushNotification(user, self.object.user, simple_notify) | |
422 | 430 | Group("user-%s" % user.id).send({'text': notification}) |
423 | 431 | |
424 | 432 | MuralVisualizations.objects.bulk_create(entries) |
... | ... | @@ -709,12 +717,14 @@ class SubjectCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
709 | 717 | if self.object.resource: |
710 | 718 | paths.append(reverse("mural:resource_view", args = (), kwargs = {'slug': self.object.resource.slug})) |
711 | 719 | |
720 | + simple_notify = _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)) | |
721 | + | |
712 | 722 | notification = { |
713 | 723 | "type": "mural", |
714 | 724 | "subtype": "post", |
715 | 725 | "paths": paths, |
716 | 726 | "user_icon": self.object.user.image_url, |
717 | - "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)), | |
727 | + "simple_notify": simple_notify, | |
718 | 728 | "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), |
719 | 729 | "container": "#" + slug, |
720 | 730 | "accordion": True, |
... | ... | @@ -725,6 +735,7 @@ class SubjectCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
725 | 735 | |
726 | 736 | for user in users: |
727 | 737 | entries.append(MuralVisualizations(viewed = False, user = user, post = self.object)) |
738 | + sendMuralPushNotification(user, self.object.user, simple_notify) | |
728 | 739 | Group("user-%s" % user.id).send({'text': notification}) |
729 | 740 | |
730 | 741 | MuralVisualizations.objects.bulk_create(entries) |
... | ... | @@ -1144,12 +1155,14 @@ class ResourceCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
1144 | 1155 | if self.object.resource: |
1145 | 1156 | paths.append(reverse("mural:resource_view", args = (), kwargs = {'slug': self.object.resource.slug})) |
1146 | 1157 | |
1158 | + simple_notify = _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)) | |
1159 | + | |
1147 | 1160 | notification = { |
1148 | 1161 | "type": "mural", |
1149 | 1162 | "subtype": "post", |
1150 | 1163 | "paths": paths, |
1151 | 1164 | "user_icon": self.object.user.image_url, |
1152 | - "simple_notify": _("%s has made a post in %s")%(str(self.object.user), str(self.object.space)), | |
1165 | + "simple_notify": simple_notify, | |
1153 | 1166 | "complete": render_to_string("mural/_view.html", {"post": self.object}, self.request), |
1154 | 1167 | "container": "#" + slug, |
1155 | 1168 | "accordion": True, |
... | ... | @@ -1160,6 +1173,7 @@ class ResourceCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
1160 | 1173 | |
1161 | 1174 | for user in users: |
1162 | 1175 | entries.append(MuralVisualizations(viewed = False, user = user, post = self.object)) |
1176 | + sendMuralPushNotification(user, self.object.user, simple_notify) | |
1163 | 1177 | Group("user-%s" % user.id).send({'text': notification}) |
1164 | 1178 | |
1165 | 1179 | MuralVisualizations.objects.bulk_create(entries) |
... | ... | @@ -1276,12 +1290,14 @@ class CommentCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
1276 | 1290 | if post.subjectpost.resource: |
1277 | 1291 | paths.append(reverse("mural:resource_view", args = (), kwargs = {'slug': post.subjectpost.resource.slug})) |
1278 | 1292 | |
1293 | + simple_notify = _("%s has commented in a post")%(str(self.object.user)) | |
1294 | + | |
1279 | 1295 | notification = { |
1280 | 1296 | "type": "mural", |
1281 | 1297 | "subtype": "comment", |
1282 | 1298 | "paths": paths, |
1283 | 1299 | "user_icon": self.object.user.image_url, |
1284 | - "simple_notify": _("%s has commented in a post")%(str(self.object.user)), | |
1300 | + "simple_notify": simple_notify, | |
1285 | 1301 | "complete": render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request), |
1286 | 1302 | "container": "#post-" + str(post.get_id()), |
1287 | 1303 | "post_type": post._my_subclass, |
... | ... | @@ -1292,6 +1308,7 @@ class CommentCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
1292 | 1308 | |
1293 | 1309 | for user in users: |
1294 | 1310 | entries.append(MuralVisualizations(viewed = False, user = user, comment = self.object)) |
1311 | + sendMuralPushNotification(user, self.object.user, simple_notify) | |
1295 | 1312 | Group("user-%s" % user.id).send({'text': notification}) |
1296 | 1313 | |
1297 | 1314 | MuralVisualizations.objects.bulk_create(entries) | ... | ... |