web/preferences: implement read receipt, typing notification and emoji pack options

This commit is contained in:
Tulir Asokan 2024-11-16 22:57:41 +02:00
parent 795eef1449
commit 1cef899e5c
3 changed files with 17 additions and 10 deletions

View file

@ -83,9 +83,9 @@ export function useCustomEmojis(
ss.emojiRoomsSub.subscribe,
() => ss.getRoomEmojiPacks(),
)
const specialRoomPacks = useSyncExternalStore(
const specialRoomPacks = useSyncExternalStore<Record<string, CustomEmojiPack>>(
room.stateSubs.getSubscriber("im.ponies.room_emotes"),
() => room.getAllEmojiPacks(),
() => room.preferences.show_room_emoji_packs ? room.getAllEmojiPacks() : {},
)
return useMemo(() => {
const allPacksObject = { ...watchedRoomPacks, ...specialRoomPacks }

View file

@ -262,13 +262,17 @@ const MessageComposer = () => {
const now = Date.now()
if (evt.target.value !== "" && typingSentAt.current + 5_000 < now) {
typingSentAt.current = now
if (room.preferences.send_typing_notifications) {
client.rpc.setTyping(room.roomID, 10_000)
.catch(err => console.error("Failed to send typing notification:", err))
}
} else if (evt.target.value === "" && typingSentAt.current > 0) {
typingSentAt.current = 0
if (room.preferences.send_typing_notifications) {
client.rpc.setTyping(room.roomID, 0)
.catch(err => console.error("Failed to send stop typing notification:", err))
}
}
onComposerCaretChange(evt, evt.target.value)
})
const doUploadFile = useCallback((file: File | null | undefined) => {
@ -322,11 +326,13 @@ const MessageComposer = () => {
return () => {
if (typingSentAt.current > 0) {
typingSentAt.current = 0
if (room.preferences.send_typing_notifications) {
client.rpc.setTyping(room.roomID, 0)
.catch(err => console.error("Failed to send stop typing notification due to room switch:", err))
}
}
}, [client, room.roomID])
}
}, [client, room])
useLayoutEffect(() => {
if (!textInput.current) {
return

View file

@ -79,7 +79,8 @@ const TimelineView = () => {
&& newestEvent.sender !== client.userID
) {
room.readUpToRow = newestEvent.timeline_rowid
client.rpc.markRead(room.roomID, newestEvent.event_id, "m.read").then(
const receiptType = roomCtx.store.preferences.send_read_receipts ? "m.read" : "m.read.private"
client.rpc.markRead(room.roomID, newestEvent.event_id, receiptType).then(
() => console.log("Marked read up to", newestEvent.event_id, newestEvent.timeline_rowid),
err => console.error(`Failed to send read receipt for ${newestEvent.event_id}:`, err),
)