1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Aggregate Differential notifications

Summary:
Just a bunch of copy-pasta from D2884. I suppose this calls for
a refactoring at some point...

Test Plan:
Make a bunch of updates, some from different users; check
notifications dropdown and list.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3361
This commit is contained in:
Alan Huang 2012-08-22 08:19:38 -07:00
parent 71bd8f32e6
commit 1b7f6655c9
3 changed files with 102 additions and 0 deletions

View file

@ -696,6 +696,7 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryCommit' => 'applications/feed/story/PhabricatorFeedStoryCommit.php',
'PhabricatorFeedStoryData' => 'applications/feed/storage/PhabricatorFeedStoryData.php',
'PhabricatorFeedStoryDifferential' => 'applications/feed/story/PhabricatorFeedStoryDifferential.php',
'PhabricatorFeedStoryDifferentialAggregate' => 'applications/feed/story/PhabricatorFeedStoryDifferentialAggregate.php',
'PhabricatorFeedStoryManiphest' => 'applications/feed/story/PhabricatorFeedStoryManiphest.php',
'PhabricatorFeedStoryManiphestAggregate' => 'applications/feed/story/PhabricatorFeedStoryManiphestAggregate.php',
'PhabricatorFeedStoryNotification' => 'applications/notification/storage/PhabricatorFeedStoryNotification.php',
@ -1820,6 +1821,7 @@ phutil_register_library_map(array(
'PhabricatorFeedStoryCommit' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO',
'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryDifferentialAggregate' => 'PhabricatorFeedStoryAggregate',
'PhabricatorFeedStoryManiphest' => 'PhabricatorFeedStory',
'PhabricatorFeedStoryManiphestAggregate' => 'PhabricatorFeedStoryAggregate',
'PhabricatorFeedStoryNotification' => 'PhabricatorFeedDAO',

View file

@ -92,4 +92,18 @@ final class PhabricatorFeedStoryDifferential extends PhabricatorFeedStory {
return $one_line;
}
public function getNotificationAggregations() {
$class = get_class($this);
$phid = $this->getStoryData()->getValue('revision_phid');
$read = (int)$this->getHasViewed();
// Don't aggregate updates separated by more than 2 hours.
$block = (int)($this->getEpoch() / (60 * 60 * 2));
return array(
"{$class}:{$phid}:{$read}:{$block}"
=> 'PhabricatorFeedStoryDifferentialAggregate',
);
}
}

View file

@ -0,0 +1,86 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorFeedStoryDifferentialAggregate
extends PhabricatorFeedStoryAggregate {
public function renderView() {
return null;
}
public function renderNotificationView() {
$data = $this->getStoryData();
$task_link = $this->linkTo($data->getValue('revision_phid'));
$authors = $this->getAuthorPHIDs();
// TODO: These aren't really translatable because linkTo() returns a
// string, not an object with a gender.
switch (count($authors)) {
case 1:
$author = $this->linkTo(array_shift($authors));
$title = pht(
'%s made multiple updates to %s',
$author,
$task_link);
break;
case 2:
$author1 = $this->linkTo(array_shift($authors));
$author2 = $this->linkTo(array_shift($authors));
$title = pht(
'%s and %s made multiple updates to %s',
$author1,
$author2,
$task_link);
break;
case 3:
$author1 = $this->linkTo(array_shift($authors));
$author2 = $this->linkTo(array_shift($authors));
$author3 = $this->linkTo(array_shift($authors));
$title = pht(
'%s, %s, and %s made multiple updates to %s',
$author1,
$author2,
$author3,
$task_link);
break;
default:
$author1 = $this->linkTo(array_shift($authors));
$author2 = $this->linkTo(array_shift($authors));
$others = count($authors);
$title = pht(
'%s, %s, and %d others made multiple updates to %s',
$author1,
$author2,
$others,
$task_link);
break;
}
$view = new PhabricatorNotificationStoryView();
$view->setEpoch($this->getEpoch());
$view->setViewed($this->getHasViewed());
$view->setTitle($title);
return $view;
}
}