Skip to content

Commit bac23b7

Browse files
author
Chris Schuhmacher
authored
Merge pull request #425 from Wikia/cake-6064
CAKE-6064 | Add Message Wall Content Types to On-Site Notifications
2 parents 3175611 + f16d3f3 commit bac23b7

File tree

19 files changed

+189
-25
lines changed

19 files changed

+189
-25
lines changed

app/components/on-site-notifications/notification-card.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default Component.extend(
2727
case notificationTypes.discussionReply:
2828
case notificationTypes.postAtMention:
2929
case notificationTypes.threadAtMention:
30+
case notificationTypes.messageWallPost:
31+
case notificationTypes.messageWallReply:
3032
return 'wds-icons-comment-small';
3133
case notificationTypes.announcement:
3234
return 'wds-icons-flag-small';
@@ -86,6 +88,12 @@ export default Component.extend(
8688
return this.getArticleCommentAtMentionMessageBody(this.model);
8789
case notificationTypes.articleCommentReplyAtMention:
8890
return this.getArticleCommentReplyAtMentionMessageBody(this.model);
91+
case notificationTypes.messageWallPost:
92+
return this.getMessageWallPostBody(this.model);
93+
case notificationTypes.messageWallReply:
94+
return this.getMessageWallReplyBody(this.model);
95+
case notificationTypes.messageWallPostRemoved:
96+
return this.getMessageWallPostRemovedBody(this.model);
8997
default:
9098
return null;
9199
}
@@ -295,6 +303,98 @@ export default Component.extend(
295303
});
296304
},
297305

306+
getMessageWallPostBody(model) {
307+
let wallOwner = model.get('metadata.wallOwnerName');
308+
const currentUsername = this.wdsOnSiteNotifications.currentUser.name;
309+
310+
if (!wallOwner) {
311+
wallOwner = this.getMessageWallOwner(model.get('uri'));
312+
}
313+
314+
const isOwnWall = wallOwner === currentUsername;
315+
const args = {
316+
postTitle: model.get('title'),
317+
wallOwner,
318+
};
319+
320+
if (isOwnWall) {
321+
args.user = this.getPossiblyAnonActorName(model);
322+
return this.getTranslatedMessage('notifications-own-wall-post', args);
323+
}
324+
325+
args.firstUser = this.getPossiblyAnonActorName(model);
326+
return this.getTranslatedMessage('notifications-wall-post', args);
327+
},
328+
329+
getMessageWallReplyBody(model) {
330+
let wallOwner = model.get('metadata.wallOwnerName');
331+
const currentUsername = this.wdsOnSiteNotifications.currentUser.name;
332+
333+
if (!wallOwner) {
334+
wallOwner = this.getMessageWallOwner(model.get('uri'));
335+
}
336+
337+
const isOwnWall = wallOwner === currentUsername;
338+
const args = {
339+
postTitle: model.get('title'),
340+
wallOwner,
341+
};
342+
343+
if (model.get('totalUniqueActors') > 1) {
344+
args.number = model.get('totalUniqueActors') - 1;
345+
346+
if (isOwnWall) {
347+
args.user = this.getPossiblyAnonActorName(model);
348+
return this.getTranslatedMessage('notifications-own-wall-reply-multiple-users', args);
349+
}
350+
351+
args.firstUser = this.getPossiblyAnonActorName(model);
352+
353+
if (model.get('contentCreatorName') === currentUsername) {
354+
return this.getTranslatedMessage('notifications-wall-reply-multiple-users-own-message', args);
355+
}
356+
357+
args.secondUser = model.get('contentCreatorName') || this.getTranslatedMessage('username-anonymous');
358+
return this.getTranslatedMessage('notifications-wall-reply-multiple-users', args);
359+
}
360+
361+
if (isOwnWall) {
362+
args.user = this.getPossiblyAnonActorName(model);
363+
return this.getTranslatedMessage('notifications-own-wall-reply', args);
364+
}
365+
366+
if (model.get('contentCreatorName') === currentUsername) {
367+
args.user = this.getPossiblyAnonActorName(model);
368+
return this.getTranslatedMessage('notifications-wall-reply-own-message', args);
369+
}
370+
371+
args.firstUser = this.getPossiblyAnonActorName(model);
372+
args.secondUser = model.get('contentCreatorName') || this.getTranslatedMessage('username-anonymous');
373+
374+
return this.getTranslatedMessage('notifications-wall-reply', args);
375+
},
376+
377+
getMessageWallPostRemovedBody(model) {
378+
return this.getTranslatedMessage('notifications-own-wall-post-removed', {
379+
postTitle: model.get('title'),
380+
});
381+
},
382+
383+
getMessageWallOwner(url) {
384+
const regex = /\/Message_Wall:(.+?)([?#/].*)?$/i;
385+
const result = regex.exec(url);
386+
387+
if (!result || !result[1]) {
388+
return null;
389+
}
390+
391+
return result[1];
392+
},
393+
394+
getPossiblyAnonActorName(model) {
395+
return model.get('latestActors.0.name') ? model.get('latestActors.0.name') : this.getTranslatedMessage('username-anonymous');
396+
},
397+
298398
getTranslatedMessage(key, context) {
299399
const fullContext = extend({}, {
300400
ns: 'design-system',

app/models/wds-on-site-notifications/wds-on-site-notification.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default EmberObject.extend({
3030

3131
setNormalizedData(notificationData) {
3232
this.setProperties({
33+
contentCreatorName: get(notificationData, 'refersTo.createdByName'),
3334
title: get(notificationData, 'refersTo.title'),
3435
snippet: get(notificationData, 'refersTo.snippet'),
3536
uri: get(notificationData, 'refersTo.uri'),
@@ -42,6 +43,7 @@ export default EmberObject.extend({
4243
totalUniqueActors: get(notificationData, 'events.totalUniqueActors'),
4344
latestActors: this.createActors(get(notificationData, 'events.latestActors')),
4445
type: this.getTypeFromApiData(notificationData),
46+
metadata: this.getMetadata(notificationData),
4547
});
4648
},
4749

@@ -77,9 +79,29 @@ export default EmberObject.extend({
7779
return notificationTypes.articleCommentAtMention;
7880
case 'article-comment-reply-at-mention-notification':
7981
return notificationTypes.articleCommentReplyAtMention;
82+
case 'message-wall-post-notification':
83+
return notificationTypes.messageWallPost;
84+
case 'message-wall-reply-notification':
85+
return notificationTypes.messageWallReply;
86+
case 'wall-post-removed-notification':
87+
return notificationTypes.messageWallPostRemoved;
8088
}
8189
},
8290

91+
getMetadata(notification) {
92+
let metadata =
93+
typeof notification.metadata === 'undefined' || notification.metadata === null ? null : notification.metadata;
94+
if (typeof metadata === 'string') {
95+
try {
96+
metadata = JSON.parse(metadata);
97+
} catch (e) {
98+
// continue regardless of error
99+
}
100+
}
101+
// Caveat: if the metadata was not serialized JSON, a string could be returned instead of an object
102+
return metadata;
103+
},
104+
83105
markAsRead(willUnloadPage) {
84106
if (willUnloadPage && window.navigator.sendBeacon) {
85107
return this.markAsReadUsingSendBeacon();

app/models/wds-on-site-notifications/wds-on-site-notifications.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default EmberObject.extend({
2929
'article-comment-reply',
3030
'article-comment-at-mention',
3131
'article-comment-reply-at-mention',
32+
'message-wall-post',
33+
'message-wall-thread',
3234
];
3335

3436
return `contentType=${supportedContentTypes.join('&contentType=')}`;

app/utils/notification-types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ export default {
88
articleCommentReply: 'article-comment-reply',
99
articleCommentAtMention: 'article-comment-at-mention',
1010
articleCommentReplyAtMention: 'article-comment-reply-at-mention',
11+
messageWallPost: 'message-wall-post',
12+
messageWallReply: 'message-wall-reply',
13+
messageWallPostRemoved: 'message-wall-post-removed',
1114
};

dist/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/design-system.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)