Ejemplo n.º 1
0
 /**
  *  Dequeues notification queue and enqueues email queue
  *  Table codo_notify
  *  type           id data              is_read
  *  new_reply      1  {tid: 4, pid: 5}  0      --> depends on subscription
  *  new_topic      2  {tid: 4}          1      --> depends on subscription
  *  new_badge      2  {bid: 3}          0      --> system notification
  *  vote_up        2  {pid: 5}          1      --> depend on user settings
  *  new_like       1  {pid: 7}          1      --> depend on user settings
  *  mention        4  {pid: 3}          0      --> depends on subscription
  */
 public function dequeueNotify()
 {
     $qry = 'SELECT q.id,q.type,q.nid,t.data FROM ' . PREFIX . 'codo_notify_queue AS q' . ' INNER JOIN codo_notify_text AS t ON q.nid=t.id';
     $res = $this->db->query($qry);
     if (!$res) {
         return false;
     }
     $maxID = 0;
     $queue = $res->fetchAll();
     $subscriber = new Subscriber();
     $user = \CODOF\User\User::get();
     $frequency = $user->prefers('notification_frequency');
     foreach ($queue as $queuedNotification) {
         $maxID = max($queuedNotification['id'], $maxID);
         $type = $queuedNotification['type'];
         $nid = $queuedNotification['nid'];
         $data = json_decode($queuedNotification['data']);
         $mentions = $data->mentions;
         $cid = $data->cid;
         $tid = $data->tid;
         $pid = $data->pid;
         if (!empty($mentions)) {
             $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $mentions);
             $notMuted = array_diff($mentions, $mutedIds);
             $this->notify($notMuted, 'mention', $nid);
         }
         $offset = 0;
         //get all types of subscribers of this category/topic
         while ($subscribers = $subscriber->of($type, $cid, $tid, $offset)) {
             //we do not need anyone subscribed to this topic since it
             //is a new topic and so the creator will be the first subscriber
             //segregate subscribers into different groups based on type
             $idTypes = $subscriber->groupBySubscriptionType($subscribers);
             //add notifications for FOLLOWING & NOTIFIED that a new topic is created
             $this->notify(array_merge($idTypes['FOLLOWING'], $idTypes['NOTIFIED']), $type, $nid);
             $offset += Subscriber::$maxRows;
         }
         //if ($frequency == 'immediate') {
         //queue all emails which will be sent in different cron run
         \CODOF\Hook::call('after_notify_insert', array("cid" => $cid, "tid" => $tid, "pid" => $pid, "type" => $type));
         //}
     }
     //delete old queued notifications
     $qry = 'DELETE FROM ' . PREFIX . 'codo_notify_queue WHERE id <= ' . $maxID;
     $this->db->query($qry);
 }