Skip to content

Commit f8664f0

Browse files
authored
Merge pull request #516 from topcoder-platform/issue-506
Issues-506: Removed excerpt and fixed styles for notification popup
2 parents d4793c6 + ca5007f commit f8664f0

File tree

4 files changed

+1640
-2
lines changed

4 files changed

+1640
-2
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Creates and sends notifications to user.
4+
*
5+
* @copyright 2009-2019 Vanilla Forums Inc.
6+
* @license GPL-2.0-only
7+
* @package Dashboard
8+
* @since 2.0
9+
*/
10+
11+
use Vanilla\Formatting\Formats\HtmlFormat;
12+
13+
/**
14+
* Handle /notifications endpoint.
15+
*/
16+
class NotificationsController extends Gdn_Controller {
17+
18+
/**
19+
* CSS, JS and module includes.
20+
*/
21+
public function initialize() {
22+
$this->Head = new HeadModule($this);
23+
$this->addJsFile('jquery.js');
24+
$this->addJsFile('jquery.form.js');
25+
$this->addJsFile('jquery.popup.js');
26+
$this->addJsFile('jquery.gardenhandleajaxform.js');
27+
$this->addJsFile('global.js');
28+
$this->addCssFile('style.css');
29+
$this->addCssFile('vanillicon.css', 'static');
30+
$this->addModule('GuestModule');
31+
parent::initialize();
32+
}
33+
34+
/**
35+
* Adds inform messages to response for inclusion in pages dynamically.
36+
*
37+
* @since 2.0.18
38+
* @access public
39+
*/
40+
public function inform() {
41+
$this->deliveryType(DELIVERY_TYPE_BOOL);
42+
$this->deliveryMethod(DELIVERY_METHOD_JSON);
43+
44+
// Retrieve all notifications and inform them.
45+
NotificationsController::informNotifications($this);
46+
$this->fireEvent('BeforeInformNotifications');
47+
48+
$this->render();
49+
}
50+
51+
/**
52+
* Grabs all new notifications and adds them to the sender's inform queue.
53+
*
54+
* This method gets called by dashboard's hooks file to display new
55+
* notifications on every pageload.
56+
*
57+
* @since 2.0.18
58+
* @access public
59+
*
60+
* @param Gdn_Controller $sender The object calling this method.
61+
*/
62+
public static function informNotifications($sender) {
63+
$session = Gdn::session();
64+
if (!$session->isValid()) {
65+
return;
66+
}
67+
68+
$activityModel = new ActivityModel();
69+
// Get five pending notifications.
70+
$where = [
71+
'NotifyUserID' => Gdn::session()->UserID,
72+
'Notified' => ActivityModel::SENT_PENDING];
73+
74+
// If we're in the middle of a visit only get very recent notifications.
75+
$where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
76+
77+
$activities = $activityModel->getWhere($where, '', '', 5, 0)->resultArray();
78+
79+
$activityIDs = array_column($activities, 'ActivityID');
80+
$activityModel->setNotified($activityIDs);
81+
82+
$sender->EventArguments['Activities'] = &$activities;
83+
$sender->fireEvent('InformNotifications');
84+
85+
foreach ($activities as $activity) {
86+
if ($activity['Photo']) {
87+
$userPhoto = anchor(
88+
img($activity['Photo'], ['class' => 'ProfilePhotoMedium']),
89+
$activity['Url'],
90+
'Icon'
91+
);
92+
} else {
93+
$userPhoto = '';
94+
}
95+
96+
$excerpt = '';
97+
$story = $activity['Story'] ?? null;
98+
$format = $activity['Format'] ?? HtmlFormat::FORMAT_KEY;
99+
$excerpt = htmlspecialchars($story ? Gdn::formatService()->renderExcerpt($story, $format) : $excerpt);
100+
$activityClass = ' Activity-'.$activity['ActivityType'];
101+
102+
// FIX: https://github.com/topcoder-platform/forums/issues/506
103+
$sender->informMessage(
104+
$userPhoto
105+
.wrap($activity['Headline'], 'div', ['class' => 'Title'])
106+
//.wrap($excerpt, 'div', ['class' => 'Excerpt'])
107+
,'Dismissable AutoDismiss'.$activityClass.($userPhoto == '' ? '' : ' HasIcon')
108+
);
109+
}
110+
}
111+
}

vanilla/applications/vanilla/views/categories/helper_functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function writeListItem($category, $depth) {
221221
t('%s discussions')
222222
), bigPlural(val('CountAllDiscussions', $category), '%s discussion')) ?>
223223
</span>
224-
<span class="MiddleDot">&#183;</span>
224+
<span class="MItem MiddleDot">&#183;</span>
225225
<span class="MItem CommentCount">
226226
<?php echo sprintf(
227227
pluralTranslate(

vanilla/applications/vanilla/views/discussions/helper_functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function writeDiscussion($discussion, $sender, $session) {
220220
'%s comment html', '%s comments html', t('%s comment'), t('%s comments')),
221221
bigPlural($discussion->CountComments, '%s comment'));
222222
?></span>
223-
<span class="MiddleDot">&#183;</span>
223+
<span class="MItem MiddleDot">&#183;</span>
224224
<span class="MItem MCount ViewCount"><?php
225225
printf(pluralTranslate($discussion->CountViews,
226226
'%s view html', '%s views html', t('%s view'), t('%s views')),

0 commit comments

Comments
 (0)