add `isMention` and `isReply`
This commit is contained in:
parent
add9e31d8d
commit
9caf8f742a
|
@ -1,6 +1,6 @@
|
||||||
// todo: rename to notifications (center?), inbox, or keep same as other platforms
|
// todo: rename to notifications (center?), inbox, or keep same as other platforms
|
||||||
import type { ChatMessage } from './chat'
|
import type { ChatMessage } from './chat'
|
||||||
// import type { Client } from './client'
|
import type { Client } from './client'
|
||||||
|
|
||||||
// todo?: union
|
// todo?: union
|
||||||
// todo?: rename to Activity
|
// todo?: rename to Activity
|
||||||
|
@ -8,6 +8,8 @@ type Notification = {
|
||||||
// fixme?: specify message type (message_reply)
|
// fixme?: specify message type (message_reply)
|
||||||
type: 'message'
|
type: 'message'
|
||||||
value: ChatMessage
|
value: ChatMessage
|
||||||
|
isMention?: boolean
|
||||||
|
isReply?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivityCenterLatest = {
|
type ActivityCenterLatest = {
|
||||||
|
@ -19,13 +21,13 @@ type ActivityCenterLatest = {
|
||||||
// todo?: rename to NotificationCenter
|
// todo?: rename to NotificationCenter
|
||||||
export class ActivityCenter {
|
export class ActivityCenter {
|
||||||
// todo?: use client.account for mentions and replies, or in chat.ts
|
// todo?: use client.account for mentions and replies, or in chat.ts
|
||||||
// #client: Client
|
#client: Client
|
||||||
|
|
||||||
#notifications: Set<Notification>
|
#notifications: Set<Notification>
|
||||||
#callbacks: Set<(latest: ActivityCenterLatest) => void>
|
#callbacks: Set<(latest: ActivityCenterLatest) => void>
|
||||||
|
|
||||||
constructor(/* client: Client */) {
|
constructor(client: Client) {
|
||||||
// this.#client = client
|
this.#client = client
|
||||||
|
|
||||||
this.#notifications = new Set()
|
this.#notifications = new Set()
|
||||||
this.#callbacks = new Set()
|
this.#callbacks = new Set()
|
||||||
|
@ -43,8 +45,7 @@ export class ActivityCenter {
|
||||||
|
|
||||||
const chat = unreadChats.get(chatUuid)
|
const chat = unreadChats.get(chatUuid)
|
||||||
if (chat) {
|
if (chat) {
|
||||||
// fixme!: isReply || isMention
|
const shouldIncrement = notification.isMention || notification.isReply
|
||||||
const shouldIncrement = false
|
|
||||||
if (shouldIncrement) {
|
if (shouldIncrement) {
|
||||||
chat.count++
|
chat.count++
|
||||||
}
|
}
|
||||||
|
@ -74,8 +75,28 @@ export class ActivityCenter {
|
||||||
return { notifications, unreadChats }
|
return { notifications, unreadChats }
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMessageNotification = (value: ChatMessage) => {
|
// todo: pass ids instead of values and resolve within
|
||||||
this.#notifications.add({ type: 'message', value })
|
public addMessageNotification = (
|
||||||
|
newMessage: ChatMessage,
|
||||||
|
referencedMessage?: ChatMessage
|
||||||
|
) => {
|
||||||
|
let isMention: boolean | undefined
|
||||||
|
let isReply: boolean | undefined
|
||||||
|
|
||||||
|
if (this.#client.account) {
|
||||||
|
const publicKey = `0x${this.#client.account.publicKey}`
|
||||||
|
|
||||||
|
isMention = newMessage.text.includes(publicKey)
|
||||||
|
isReply = referencedMessage?.signer === publicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo?: getLatest on login
|
||||||
|
this.#notifications.add({
|
||||||
|
type: 'message',
|
||||||
|
value: newMessage,
|
||||||
|
isMention,
|
||||||
|
isReply,
|
||||||
|
})
|
||||||
|
|
||||||
this.emitLatest()
|
this.emitLatest()
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,7 +320,10 @@ export class Chat {
|
||||||
|
|
||||||
// todo?: if not muted
|
// todo?: if not muted
|
||||||
if (!this.#isActive) {
|
if (!this.#isActive) {
|
||||||
this.client.activityCenter.addMessageNotifications(newMessage)
|
this.client.activityCenter.addMessageNotification(
|
||||||
|
newMessage,
|
||||||
|
this.#messages.get(newMessage.responseTo)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Client {
|
||||||
this.#wakuDisconnectionTimer = wakuDisconnectionTimer
|
this.#wakuDisconnectionTimer = wakuDisconnectionTimer
|
||||||
|
|
||||||
// Activity Center
|
// Activity Center
|
||||||
this.activityCenter = new ActivityCenter(/* this */)
|
this.activityCenter = new ActivityCenter(this)
|
||||||
|
|
||||||
// Community
|
// Community
|
||||||
this.community = new Community(this, options.publicKey)
|
this.community = new Community(this, options.publicKey)
|
||||||
|
|
Loading…
Reference in New Issue