From 6a7469e1aaee7c1ba4ec29541325ab7440fa67d4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 Jan 2015 09:43:33 -0800 Subject: [PATCH] Don't show notifications about your own actions Summary: Ref T6559. See discussion in D11143. At least locally, WebSockets are too fast and create immediate local notifications on page submit. To mitigate this, don't notify about your own actions. This isn't perfect (we get the other-copies-of-the-window-open-in-other-tabs case wrong) but I think the case we get wrong is rare / not very important. Test Plan: Submitted stuff, saw other users get notifications but not me. Reviewers: btrahan, joshuaspence Reviewed By: joshuaspence Subscribers: epriestley Maniphest Tasks: T6559 Differential Revision: https://secure.phabricator.com/D11275 --- ...icatorNotificationIndividualController.php | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php index 0024b09b1a..684d83c274 100644 --- a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php +++ b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php @@ -5,30 +5,49 @@ final class PhabricatorNotificationIndividualController public function processRequest() { $request = $this->getRequest(); - $user = $request->getUser(); + $viewer = $request->getUser(); $stories = id(new PhabricatorNotificationQuery()) - ->setViewer($user) - ->withUserPHIDs(array($user->getPHID())) + ->setViewer($viewer) + ->withUserPHIDs(array($viewer->getPHID())) ->withKeys(array($request->getStr('key'))) ->execute(); if (!$stories) { - return id(new AphrontAjaxResponse())->setContent( - array( - 'pertinent' => false, - )); + return $this->buildEmptyResponse(); } - $builder = new PhabricatorNotificationBuilder($stories); + $story = head($stories); + if ($story->getAuthorPHID() === $viewer->getPHID()) { + // Don't show the user individual notifications about their own + // actions. Primarily, this stops pages from showing notifications + // immediately after you click "Submit" on a comment form if the + // notification server returns faster than the web server. + + // TODO: It would be nice to retain the "page updated" bubble on copies + // of the page that are open in other tabs, but there isn't an obvious + // way to do this easily. + + return $this->buildEmptyResponse(); + } + + $builder = new PhabricatorNotificationBuilder(array($story)); $content = $builder->buildView()->render(); $response = array( 'pertinent' => true, - 'primaryObjectPHID' => head($stories)->getPrimaryObjectPHID(), + 'primaryObjectPHID' => $story->getPrimaryObjectPHID(), 'content' => hsprintf('%s', $content), ); return id(new AphrontAjaxResponse())->setContent($response); } + + private function buildEmptyResponse() { + return id(new AphrontAjaxResponse())->setContent( + array( + 'pertinent' => false, + )); + } + }