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