-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat πΈ (be): add user.index route, controller and service action * styles π (wip): progress on add autocomplete interface * styles π : create highlight parsing input * refactor β¨ (ui): replace avatar comps for generic UserAvatar * feat πΈ : more progress * feat πΈ (be): serialise mentions * styles π : improve highlighted_input * styles π : parse mentions on post_card content * feat πΈ (be): notify post content mentioned users via hook * test π§ͺ (unit): add tests for post mention notification event * feat πΈ (be): parse notification serialized template * styles π : improve highlighted content overlay placement * refactor β¨ : small nits and renames * test π§ͺ (unit): add user_service/search action test * fix β : override user on mention notification
- Loading branch information
1 parent
45448b8
commit 305a7ad
Showing
28 changed files
with
842 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Post from '#models/post' | ||
import User from '#models/user' | ||
import PostMentionNotification from '#notifications/post_mention_notification' | ||
import { NotificationType } from '#enums/notification' | ||
|
||
export default class TriggerPostMentionNotification { | ||
async handle([mentions, post]: [string[], Post]) { | ||
const notifiables = await this.notifiables(mentions) | ||
for (const notifiable of notifiables) { | ||
const userNotifications = await notifiable.unreadNotifications() | ||
const prev = userNotifications.filter( | ||
(notification) => | ||
notification.data.type === NotificationType.PostMentionNotification && | ||
notification.data.postId === post.id | ||
) | ||
if (prev.length > 0) return | ||
notifiable.notify(new PostMentionNotification(post)) | ||
} | ||
} | ||
|
||
async notifiables(mentions: string[]): Promise<User[]> { | ||
const notifiables: User[] = [] | ||
if (mentions.length === 0) return notifiables | ||
for (const mention of mentions) { | ||
const user = await User.findBy('username', mention) | ||
if (user) notifiables.push(user) | ||
} | ||
return notifiables | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NotificationChannelName, NotificationContract } from '@osenco/adonisjs-notifications/types' | ||
import { PostMentionNotificationData } from '@osenco/adonisjs-notifications/types' | ||
import { NotificationType } from '#enums/notification' | ||
import Post from '#models/post' | ||
import type User from '#models/user' | ||
|
||
export default class PostMentionNotification implements NotificationContract<User> { | ||
private post: Post | ||
|
||
protected subject = '' | ||
protected message = '' | ||
|
||
constructor(post: Post) { | ||
this.post = post | ||
this.#templateData() | ||
} | ||
|
||
via(): NotificationChannelName | Array<NotificationChannelName> { | ||
return 'database' | ||
} | ||
|
||
toDatabase(): PostMentionNotificationData { | ||
return { | ||
type: NotificationType.PostMentionNotification, | ||
userId: this.post.userId, | ||
postId: this.post.id, | ||
title: this.subject, | ||
message: this.message, | ||
} | ||
} | ||
|
||
#templateData() { | ||
this.subject = `:authorFullName has mentioned you on their your post` | ||
this.message = `":content"` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Post from '#models/post' | ||
|
||
declare module '@adonisjs/core/types' { | ||
interface EventsList { | ||
'post:mention': [string[], Post] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.