Skip to content

Commit 27b6499

Browse files
authored
MMI-2997 Turn off sentiment in Alerts (#2402)
- updated UI user settings vacation mode styles - added UI user settings Report Sentiment - updated notifications to enable/disable the report sentiment - added db migration to update basic alert template
1 parent 5000452 commit 27b6499

File tree

13 files changed

+7737
-41
lines changed

13 files changed

+7737
-41
lines changed

api/net/Areas/Helpers/INotificationHelper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ public interface INotificationHelper
2525
/// </summary>
2626
/// <param name="model"></param>
2727
/// <param name="isPreview"></param>
28+
/// <param name="enableReportSentiment"></param>
2829
/// <returns></returns>
2930
/// <exception cref="ArgumentException"></exception>
3031
/// <exception cref="InvalidOperationException"></exception>
3132
Task<NotificationResultModel> GenerateNotificationAsync(
3233
Areas.Services.Models.NotificationInstance.NotificationInstanceModel model,
33-
bool isPreview = false);
34+
bool isPreview = false,
35+
bool enableReportSentiment = false);
3436

3537
/// <summary>
3638
/// Execute the notification template to generate the subject and body.
@@ -54,10 +56,12 @@ Task<IEnumerable<NotificationResultModel>> GenerateNotificationsAsync(
5456
/// <param name="notification"></param>
5557
/// <param name="content"></param>
5658
/// <param name="isPreview"></param>
59+
/// <param name="enableReportSentiment"></param>
5760
/// <returns></returns>
5861
/// <exception cref="InvalidOperationException"></exception>
5962
Task<NotificationResultModel> GenerateNotificationAsync(
6063
Areas.Services.Models.Notification.NotificationModel notification,
6164
ContentModel content,
62-
bool isPreview = false);
65+
bool isPreview = false,
66+
bool enableReportSentiment = false);
6367
}

api/net/Areas/Helpers/NotificationHelper.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ public NotificationHelper(
8383
/// </summary>
8484
/// <param name="model"></param>
8585
/// <param name="isPreview"></param>
86+
/// <param name="enableReportSentiment"></param>
8687
/// <returns></returns>
8788
/// <exception cref="ArgumentException"></exception>
8889
/// <exception cref="InvalidOperationException"></exception>
8990
public async Task<NotificationResultModel> GenerateNotificationAsync(
9091
Areas.Services.Models.NotificationInstance.NotificationInstanceModel model,
91-
bool isPreview = false)
92+
bool isPreview = false,
93+
bool enableReportSentiment = false)
9294
{
9395
var notification = _notificationService.FindById(model.NotificationId) ?? throw new ArgumentException("Parameter 'model.NotificationId' did not return a notification.");
9496
if (notification.Template == null) throw new InvalidOperationException("Parameter 'Notification.Template' is required");
@@ -138,14 +140,16 @@ public async Task<IEnumerable<NotificationResultModel>> GenerateNotificationsAsy
138140
/// <param name="notification"></param>
139141
/// <param name="content"></param>
140142
/// <param name="isPreview"></param>
143+
/// <param name="enableReportSentiment"></param>
141144
/// <returns></returns>
142145
/// <exception cref="InvalidOperationException"></exception>
143146
public async Task<NotificationResultModel> GenerateNotificationAsync(
144147
Areas.Services.Models.Notification.NotificationModel notification,
145148
ContentModel content,
146-
bool isPreview = false)
149+
bool isPreview = false,
150+
bool enableReportSentiment = false)
147151
{
148-
var subject = await _notificationEngine.GenerateNotificationSubjectAsync(notification, content, isPreview);
152+
var subject = await _notificationEngine.GenerateNotificationSubjectAsync(notification, content, isPreview, enableReportSentiment);
149153
var body = await _notificationEngine.GenerateNotificationBodyAsync(notification, content, _storageOptions.GetUploadPath(), isPreview);
150154

151155
return new NotificationResultModel(subject, body);

app/subscriber/src/features/settings/MyAccountSettings.tsx

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { FaEnvelope, FaToggleOff, FaToggleOn, FaUmbrellaBeach } from 'react-icons/fa';
2+
import { FaEnvelope, FaSmile, FaToggleOff, FaToggleOn } from 'react-icons/fa';
33
import { toast } from 'react-toastify';
44
import { useUsers } from 'store/hooks';
55
import { useProfileStore } from 'store/slices';
@@ -13,6 +13,9 @@ const MyAccountSettings = () => {
1313
const isVacationMode: boolean = !!impersonate
1414
? impersonate?.preferences?.isVacationMode ?? false
1515
: profile?.preferences?.isVacationMode ?? false;
16+
const enableReportSentiment: boolean = !!impersonate
17+
? impersonate?.preferences?.enableReportSentiment ?? false
18+
: profile?.preferences?.enableReportSentiment ?? false;
1619

1720
const toggleVacationMode = React.useCallback(
1821
async (
@@ -48,6 +51,40 @@ const MyAccountSettings = () => {
4851
[updateUser],
4952
);
5053

54+
const toggleReportSentiment = React.useCallback(
55+
async (
56+
profile: ISubscriberUserModel | undefined,
57+
impersonate: ISubscriberUserModel | undefined,
58+
enableReportSentiment: boolean,
59+
) => {
60+
if (!profile) {
61+
toast.error('User information is missing. Please try again later');
62+
return;
63+
}
64+
const baseProfile = impersonate ?? profile;
65+
const createUser = (): ISubscriberUserModel => {
66+
// use impersonate if it exists, otherwise use profile
67+
return {
68+
...baseProfile,
69+
preferences: {
70+
...baseProfile.preferences,
71+
enableReportSentiment: enableReportSentiment,
72+
},
73+
};
74+
};
75+
const user = createUser();
76+
77+
try {
78+
await updateUser(user, !!impersonate);
79+
toast.success('Report sentiment has successfully been updated.');
80+
} catch (error) {
81+
// Handle the error, if needed
82+
console.error('Failed to update user:', error);
83+
}
84+
},
85+
[updateUser],
86+
);
87+
5188
return (
5289
<styled.MyAccountSettings>
5390
<div className="header-row">
@@ -59,22 +96,37 @@ const MyAccountSettings = () => {
5996
disable vacation mode. This will include subscriptions to MMI Products, Alerts and Reports.
6097
</p>
6198
<div className="toggleContainer">
99+
<span className="vacation-mode-label">Vacation Mode</span>
62100
<ToggleButton
63101
on={<FaToggleOn />}
64102
off={<FaToggleOff />}
65103
onClick={() => toggleVacationMode(profile, impersonate, !isVacationMode)}
66104
width="25px"
67105
height="25px"
68-
color="#008000"
69-
label={
70-
<span className="vacation-mode-label">
71-
<FaUmbrellaBeach className="icon" />
72-
Vacation Mode
73-
</span>
74-
}
106+
label=""
75107
value={isVacationMode}
76108
/>
77109
</div>
110+
<div className="header-row">
111+
<FaSmile className="icon" />
112+
<span className="header-text">Report sentiment</span>
113+
</div>
114+
<p className="description">
115+
Enables display of sentiment in the reports you receive. Sentiment reflects the tone of
116+
media articles towards government and appears in reports and alerts as emoticons.
117+
</p>
118+
<div className="toggleContainer">
119+
<span className="vacation-mode-label">Report sentiment</span>
120+
<ToggleButton
121+
on={<FaToggleOn />}
122+
off={<FaToggleOff />}
123+
onClick={() => toggleReportSentiment(profile, impersonate, !enableReportSentiment)}
124+
width="25px"
125+
height="25px"
126+
label=""
127+
value={enableReportSentiment}
128+
/>
129+
</div>
78130
</styled.MyAccountSettings>
79131
);
80132
};

app/subscriber/src/features/settings/styled/MyAccountSettings.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ export const MyAccountSettings = styled(Col)`
3232
.toggleContainer {
3333
display: flex;
3434
align-items: center;
35-
margin-left: 3rem;
35+
margin-left: 2.8rem;
3636
3737
.vacation-mode-label {
38-
color: #008000;
3938
display: flex;
40-
align-items: center;
41-
}
42-
43-
.icon {
44-
margin-right: 5px;
39+
align-items: left;
40+
margin-right: 1rem;
4541
}
4642
}
4743
`;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
DO $$
2+
BEGIN
3+
4+
-- Update custom chart with latest template.
5+
UPDATE public."notification_template" SET
6+
"subject" = '@inherits RazorEngineCore.RazorEngineTemplateBase<TNO.Services.Notification.Models.TemplateModel>
7+
@using System.Linq
8+
@{
9+
var isAV = @Content.ContentType == TNO.Entities.ContentType.AudioVideo;
10+
var isTranscriptAvailable = isAV && !string.IsNullOrWhiteSpace(@Content.Body) && @Content.IsApproved;
11+
var sourceCode = !string.IsNullOrEmpty(@Content.Source?.Code) ? @Content.Source.Code : @Content.OtherSource;
12+
var body = isTranscriptAvailable ? @Content.Body : (isAV ? @Content.Summary : @Content.Body);
13+
var transcriptIcon = isTranscriptAvailable ? "▶️📄" : (isAV ? "▶️" : "");
14+
var toneIcon = "";
15+
switch (@Content.TonePools.FirstOrDefault()?.Value)
16+
{
17+
case 0:
18+
toneIcon = "😐 ";
19+
break;
20+
case -3:
21+
case -4:
22+
case -5:
23+
toneIcon = "☹️ ";
24+
break;
25+
case 3:
26+
case 4:
27+
case 5:
28+
toneIcon = "🙂 ";
29+
break;
30+
}
31+
}@toneIcon@sourceCode: @Content.Headline @transcriptIcon'
32+
WHERE "id" = cast((SELECT value FROM setting
33+
WHERE name = 'BasicAlertTemplateId') as integer);
34+
35+
END $$;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
DO $$
2+
BEGIN
3+
4+
-- Update custom chart with latest template.
5+
UPDATE public."notification_template" SET
6+
"subject" = '@inherits RazorEngineCore.RazorEngineTemplateBase<TNO.Services.Notification.Models.TemplateModel>
7+
@using System.Linq
8+
@{
9+
var isAV = @Content.ContentType == TNO.Entities.ContentType.AudioVideo;
10+
var isTranscriptAvailable = isAV && !string.IsNullOrWhiteSpace(@Content.Body) && @Content.IsApproved;
11+
var sourceCode = !string.IsNullOrEmpty(@Content.Source?.Code) ? @Content.Source.Code : @Content.OtherSource;
12+
var body = isTranscriptAvailable ? @Content.Body : (isAV ? @Content.Summary : @Content.Body);
13+
var transcriptIcon = isTranscriptAvailable ? "▶️📄" : (isAV ? "▶️" : "");
14+
var toneIcon = "";
15+
if (@EnableReportSentiment)
16+
{
17+
switch (@Content.TonePools.FirstOrDefault()?.Value)
18+
{
19+
case 0:
20+
toneIcon = "😐 ";
21+
break;
22+
case -3:
23+
case -4:
24+
case -5:
25+
toneIcon = "☹️ ";
26+
break;
27+
case 3:
28+
case 4:
29+
case 5:
30+
toneIcon = "🙂 ";
31+
break;
32+
}
33+
}
34+
}@toneIcon@sourceCode: @Content.Headline @transcriptIcon'
35+
WHERE "id" = cast((SELECT value FROM setting
36+
WHERE name = 'BasicAlertTemplateId') as integer);
37+
38+
END $$;

0 commit comments

Comments
 (0)