示例#1
0
 /**
  * Mark single notification as seen
  */
 public function markNotificationAsSeen($notice_id, $to_profile_id, $ntype)
 {
     $notification_to_mark_as_seen = QvitterNotification::pkeyGet(array('is_seen' => 0, 'notice_id' => $notice_id, 'to_profile_id' => $to_profile_id, 'ntype' => $ntype));
     if ($notification_to_mark_as_seen instanceof QvitterNotification) {
         $orig = clone $notification_to_mark_as_seen;
         $notification_to_mark_as_seen->is_seen = 1;
         $notification_to_mark_as_seen->update($orig);
     }
 }
示例#2
0
 /**
  * Insert notifications for replies, mentions and repeats
  *
  * @return boolean hook flag
  */
 function onStartNoticeDistribute($notice)
 {
     assert($notice->id > 0);
     // since we removed tests below
     // don't add notifications for activity type notices
     if ($notice->object_type == 'activity') {
         return true;
     }
     // mark reply/mention-notifications as read if we're replying to a notice we're notified about
     if ($notice->reply_to) {
         $notification_to_mark_as_seen = QvitterNotification::pkeyGet(array('is_seen' => 0, 'notice_id' => $notice->reply_to, 'to_profile_id' => $notice->profile_id));
         if ($notification_to_mark_as_seen instanceof QvitterNotification && ($notification_to_mark_as_seen->ntype == 'mention' || $notification_to_mark_as_seen->ntype == 'reply')) {
             $orig = clone $notification_to_mark_as_seen;
             $notification_to_mark_as_seen->is_seen = 1;
             $notification_to_mark_as_seen->update($orig);
         }
     }
     // repeats
     if ($notice->isRepeat()) {
         $repeated_notice = Notice::getKV('id', $notice->repeat_of);
         if ($repeated_notice instanceof Notice) {
             $this->insertNotification($repeated_notice->profile_id, $notice->profile_id, 'repeat', $repeated_notice->id);
         }
     } else {
         $reply_notification_to = false;
         // check for reply to insert in notifications
         if ($notice->reply_to) {
             try {
                 $replyauthor = $notice->getParent()->getProfile();
                 $reply_notification_to = $replyauthor->id;
                 $this->insertNotification($replyauthor->id, $notice->profile_id, 'reply', $notice->id);
                 //} catch (NoParentNoticeException $e) {	// TODO: catch this when everyone runs latest GNU social!
                 // This is not a reply to something (has no parent)
             } catch (NoResultException $e) {
                 // Parent author's profile not found! Complain louder?
                 common_log(LOG_ERR, "Parent notice's author not found: " . $e->getMessage());
             }
         }
         // check for mentions to insert in notifications
         $mentions = $notice->getReplies();
         $sender = Profile::getKV($notice->profile_id);
         $all_mentioned_user_ids = array();
         foreach ($mentions as $mentioned) {
             // no duplicate mentions
             if (in_array($mentioned, $all_mentioned_user_ids)) {
                 continue;
             }
             $all_mentioned_user_ids[] = $mentioned;
             // only notify if mentioned user is not already notified for reply
             if ($reply_notification_to != $mentioned) {
                 $this->insertNotification($mentioned, $notice->profile_id, 'mention', $notice->id);
             }
         }
     }
     return true;
 }