Konstantine Rybnikov avatar Konstantine Rybnikov committed 22a0136

ok, this considers as v0.1 because subscriptions work) God, I need some rest and refactor))

Comments (0)

Files changed (3)

openju/bl/__init__.py

 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-import user, message
+import user, message, notify

openju/bl/notify.py

 
 from openju.model import Notification
 
+def get_notifications():
+    return Notification.objects
+
 def get_user_notifications(user):
     return Notification.objects(user=user)
 

openju/message_bus.py

     g.auth_user = None
 
 def notify_logic(xmpp_user):
+    from openju import bl
+    
     def filter_empty(l):
         return (x for x in l if x is not None)
+    
+    def process_notification(notification):
+        from openju.controllers import notify
+        action = getattr(notify, notification.action, None)
+        if action is not None:
+            res = action(notification.user, notification.info)
+            notification.delete()
+            if res is not None:
+                return res
+        else:
+            app.logger.exception(
+                Exception(u'Notification action %s not found (not implemented, eh?)' % action))
+    
+    notifications = bl.notify.get_notifications()
+    for notification in notifications:
+        msg = process_notification(notification)
+        if msg:
+            g.xmpp_cli.send(
+                xmpp.Message(
+                    xmpp.JID(notification.user.jid),
+                    msg))
+    
+    # def process_notifications(notifications):
+    #     def process_notification(notification):
+    #         from openju.controllers import notify
+    #         action = getattr(notify, notification.action, None)
+    #         if action is not None:
+    #             res = action(notification.user, notification.info)
+    #             notification.delete()
+    #             if res is not None:
+    #                 return res
+    #         else:
+    #             app.logger.exception(
+    #                 Exception(u'Notification action %s not found' % action))
 
-    def process_notifications(notifications):
-        def process_notification(notification):
-            from openju.controllers import notify
-            action = getattr(notify, notification.action, None)
-            if action is not None:
-                res = action(notification.user, notification.info)
-                notification.delete()
-                if res is not None:
-                    return res
-            else:
-                app.logger.exception(
-                    Exception(u'Notification action %s not found' % action))
+    #     return (process_notification(x) for x in notifications)
 
-        return (process_notification(x) for x in notifications)
-
-    if g.auth_user is not None:
-        notify_text = (
-            u"\n\n"
-            .join(
-                filter_empty(
-                    process_notifications(
-                        g.auth_user.get_notifications()))))
-        if notify_text:
-            g.xmpp_cli.send(xmpp.Message(xmpp_user, unicode(notify_text)))
+    # if g.auth_user is not None:
+    #     notify_text = (
+    #         u"\n\n"
+    #         .join(
+    #             filter_empty(
+    #                 process_notifications(
+    #                     g.auth_user.get_notifications()))))
+    #     if notify_text:
+    #         import ipdb; ipdb.set_trace()
+    #         g.xmpp_cli.send(xmpp.Message(xmpp_user, unicode(notify_text)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.