93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import { redis } from '@/lib/redis'
|
|
|
|
interface NotificationBase {
|
|
id: string
|
|
timestamp: number
|
|
read: boolean
|
|
}
|
|
|
|
export async function notifyOnVote(pollCreatorFid: string, voterFid: string, voterUsername: string, pollId: string, pollQuestion: string) {
|
|
const notification = {
|
|
id: `vote-${voterFid}-${pollId}-${Date.now()}`,
|
|
type: 'vote',
|
|
fromFid: voterFid,
|
|
fromUsername: voterUsername,
|
|
pollId,
|
|
pollQuestion,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:${pollCreatorFid}`, JSON.stringify(notification))
|
|
}
|
|
|
|
export async function notifyOnComment(pollCreatorFid: string, commenterFid: string, commenterUsername: string, pollId: string, pollQuestion: string, commentId: string) {
|
|
const notification = {
|
|
id: `comment-${commenterFid}-${commentId}-${Date.now()}`,
|
|
type: 'comment',
|
|
fromFid: commenterFid,
|
|
fromUsername: commenterUsername,
|
|
pollId,
|
|
pollQuestion,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:${pollCreatorFid}`, JSON.stringify(notification))
|
|
}
|
|
|
|
export async function notifyOnLike(commentAuthorFid: string, likerFid: string, likerUsername: string, commentId: string, pollId?: string) {
|
|
const notification = {
|
|
id: `like-${likerFid}-${commentId}-${Date.now()}`,
|
|
type: 'like',
|
|
fromFid: likerFid,
|
|
fromUsername: likerUsername,
|
|
pollId,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:${commentAuthorFid}`, JSON.stringify(notification))
|
|
}
|
|
|
|
export async function notifyOnFollow(targetFid: string, followerFid: string, followerUsername: string) {
|
|
const notification = {
|
|
id: `follow-${followerFid}-${targetFid}-${Date.now()}`,
|
|
type: 'follow',
|
|
fromFid: followerFid,
|
|
fromUsername: followerUsername,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:${targetFid}`, JSON.stringify(notification))
|
|
}
|
|
|
|
export async function notifyOnWin(winnerFid: string, pollId: string, pollQuestion: string, amount: number) {
|
|
const notification = {
|
|
id: `win-${winnerFid}-${pollId}-${Date.now()}`,
|
|
type: 'win',
|
|
pollId,
|
|
pollQuestion,
|
|
amount,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:${winnerFid}`, JSON.stringify(notification))
|
|
}
|
|
|
|
export async function notifyOnMention(mentionedUsername: string, mentionerFid: string, mentionerUsername: string, pollId: string, commentId: string) {
|
|
const notification = {
|
|
id: `mention-${mentionerFid}-${commentId}-${Date.now()}`,
|
|
type: 'mention',
|
|
fromFid: mentionerFid,
|
|
fromUsername: mentionerUsername,
|
|
pollId,
|
|
timestamp: Date.now(),
|
|
read: false
|
|
}
|
|
|
|
await redis.lpush(`notifications:mention:${mentionedUsername}`, JSON.stringify(notification))
|
|
}
|