]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Events listing, but the stream will change soon
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 23 Nov 2015 13:40:59 +0000 (14:40 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 23 Nov 2015 13:40:59 +0000 (14:40 +0100)
plugins/Event/EventPlugin.php
plugins/Event/actions/events.php [new file with mode: 0644]
plugins/Event/lib/eventsnoticestream.php [new file with mode: 0644]

index 7f2712b148ea45debbb13263cea78877f099a20a..0c520ddb7a7a916df87f6c33276ad18112cdae3f 100644 (file)
@@ -90,6 +90,10 @@ class EventPlugin extends MicroAppPlugin
                     array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
         $m->connect('main/event/updatetimes',
                     array('action' => 'timelist'));
+
+        $m->connect(':nickname/events',
+                    array('action' => 'events'),
+                    array('nickname' => Nickname::DISPLAY_FMT));
         return true;
     }
 
@@ -516,4 +520,14 @@ class EventPlugin extends MicroAppPlugin
         $out->raw($rsvp->asHTML());
         $out->elementEnd('div');
     }
+
+    function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
+    {
+        $menu->menuItem(common_local_url('events', array('nickname' => $target->getNickname())),
+                          // TRANS: Menu item in sample plugin.
+                          _m('Happenings'),
+                          // TRANS: Menu item title in sample plugin.
+                          _m('A list of your events'), false, 'nav_timeline_events');
+        return true;
+    }
 }
diff --git a/plugins/Event/actions/events.php b/plugins/Event/actions/events.php
new file mode 100644 (file)
index 0000000..1de46a7
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * List events
+ */
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class EventsAction extends ShowstreamAction
+{
+    public function getStream()
+    {
+                                     /* whose events */   /* are these the user's own events? */
+        $stream = new EventsNoticeStream($this->target, $this->scoped);
+        return $stream;
+    }
+
+    function title()
+    {
+        // TRANS: Page title for sample plugin. %s is a user nickname.
+        return sprintf(_m('%s\'s happenings'), $this->target->getNickname());
+    }
+
+    function getFeeds()
+    {
+        return array(
+                    );
+    }
+
+    function showEmptyList() {
+        $message = sprintf(_('This is %1$s\'s event stream, but %1$s hasn\'t received any events yet.'), $this->target->getNickname()) . ' ';
+
+        $this->elementStart('div', 'guide');
+        $this->raw(common_markup_to_html($message));
+        $this->elementEnd('div');
+    }
+
+    /**
+     * Return true if read only.
+     *
+     * Some actions only read from the database; others read and write.
+     * The simple database load-balancer built into StatusNet will
+     * direct read-only actions to database mirrors (if they are configured),
+     * and read-write actions to the master database.
+     *
+     * This defaults to false to avoid data integrity issues, but you
+     * should make sure to overload it for performance gains.
+     *
+     * @param array $args other arguments, if RO/RW status depends on them.
+     *
+     * @return boolean is read only action?
+     */
+    function isReadOnly($args)
+    {
+        return true;
+    }
+}
diff --git a/plugins/Event/lib/eventsnoticestream.php b/plugins/Event/lib/eventsnoticestream.php
new file mode 100644 (file)
index 0000000..1e8c4fe
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+class RawEventsNoticeStream extends NoticeStream
+{
+    protected $target;
+    protected $own;
+
+    function __construct(Profile $target)
+    {
+        $this->target   = $target;
+    }
+
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        $notice = new Notice();
+        $qry = null;
+
+        $qry =  'SELECT notice.* FROM notice ';
+        $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
+        $qry .= 'WHERE happening.profile_id = ' . $this->target->getID() . ' ';
+        $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
+
+        if ($since_id != 0) {
+            $qry .= 'AND notice.id > ' . $since_id . ' ';
+        }
+
+        if ($max_id != 0) {
+            $qry .= 'AND notice.id <= ' . $max_id . ' ';
+        }
+
+        // NOTE: we sort by bookmark time, not by notice time!
+        $qry .= 'ORDER BY created DESC ';
+        if (!is_null($offset)) {
+            $qry .= "LIMIT $limit OFFSET $offset";
+        }
+
+        $notice->query($qry);
+        $ids = array();
+        while ($notice->fetch()) {
+            $ids[] = $notice->id;
+        }
+
+        $notice->free();
+        unset($notice);
+        return $ids;
+    }
+}
+
+class EventsNoticeStream extends ScopingNoticeStream
+{
+    function __construct(Profile $target, Profile $scoped=null)
+    {
+        $stream = new RawEventsNoticeStream($target);
+
+        if ($target->sameAs($scoped)) {
+            $key = 'bookmark:ids_by_user_own:'.$target->getID();
+        } else {
+            $key = 'bookmark:ids_by_user:'.$target->getID();
+        }
+
+        parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
+    }
+}