Skip to content

Commit

Permalink
Added repl method for sending notifications
Browse files Browse the repository at this point in the history
Not tested yet

Signed-off-by: Brian Evans <ebrian101@gmail.com>
  • Loading branch information
mrbrianevans committed May 6, 2023
1 parent d812465 commit c8752d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions repl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {getFeedback} from "./getFeedback.js";
import {getUser} from "./getUserAndOrg.js";
import {setOrgActiveMembers} from "./migrations/setOrgActiveMembers.js";
import {clearSessions} from "./utils/clearSessions.js";
import {sendNotification} from "./utils/sendNotification.js";

if(process.argv.slice(1).includes('--help')) console.log("This is a custom repl for managing the database and queues. Try\n\n\t" +
"docker compose exec repl node index.js")
Expand All @@ -42,6 +43,7 @@ server.context.backupClientLists = ()=>backupClientLists(redis)
server.context.getFeedback = ()=>getFeedback(redis)
server.context.getUser = (userId: string)=>getUser(redis, userId).then(console.log)
server.context.clearSessions = ()=>clearSessions(redis)
server.context.sendNotification = (userId: string, {title, message})=>sendNotification(redis,userId, {title, message})

server.context.exit = ()=>{shutdown('exit()');return 'exiting...'} // could be a Proxy to allow for simply "exit" rather than "exit()"

Expand Down
8 changes: 8 additions & 0 deletions repl/utils/sendNotification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {RedisClient} from "bullmq";
import {sendWebNotification, WebNotification} from "../../backend-shared/notifications/sendWebNotification.js";

export async function sendNotification(redis: RedisClient,userId: string, {title, message}){
const notification: WebNotification = {title, options:{body: message,tag: 'custom-repl-notification',
icon: 'https://filingdeadlines.co.uk/icon/icon500.svg',}}
await sendWebNotification({userId: userId, notification})
}

0 comments on commit c8752d6

Please sign in to comment.