(fix): small notification logic error
(fix): call ui
This commit is contained in:
parent
f1874042ba
commit
6f03604c90
5 changed files with 5961 additions and 3108 deletions
|
|
@ -185,7 +185,7 @@ export default function View() {
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Base
|
<Base
|
||||||
fill
|
fill={isImmersiveFocusedView}
|
||||||
flush={isImmersiveFocusedView || isFocusedTileFlush}
|
flush={isImmersiveFocusedView || isFocusedTileFlush}
|
||||||
type={focusedTileType}
|
type={focusedTileType}
|
||||||
participant={focusedParticipant}
|
participant={focusedParticipant}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,8 @@ function MessageComponent({
|
||||||
})}
|
})}
|
||||||
</p>
|
</p>
|
||||||
<div className="flex items-center justify-start gap-1">
|
<div className="flex items-center justify-start gap-1">
|
||||||
{message.MessageState === "read" ? (
|
{message.SenderId !==
|
||||||
|
ownId ? null : message.MessageState === "read" ? (
|
||||||
<Check
|
<Check
|
||||||
size={12}
|
size={12}
|
||||||
color="var(--primary-foreground-alt)"
|
color="var(--primary-foreground-alt)"
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-router": "^1.169.1",
|
"@tanstack/react-router": "^1.169.1",
|
||||||
"@tauri-apps/api": "^2.11.0",
|
"@tauri-apps/api": "^2.11.0",
|
||||||
|
"@tauri-apps/plugin-notification": "~2",
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/chat": "workspace:*",
|
"@tensamin/chat": "workspace:*",
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,13 @@ import { createContext, useEffect, useContext } from "react";
|
||||||
import { toast as sonnerToast } from "sonner";
|
import { toast as sonnerToast } from "sonner";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@methanium/ui";
|
import { Avatar, AvatarFallback, AvatarImage } from "@methanium/ui";
|
||||||
import { isTauri } from "@tauri-apps/api/core";
|
import { isTauri } from "@tauri-apps/api/core";
|
||||||
|
import {
|
||||||
|
isPermissionGranted as isTauriNotificationPermissionGranted,
|
||||||
|
requestPermission as requestTauriNotificationPermission,
|
||||||
|
sendNotification as sendTauriNotification,
|
||||||
|
} from "@tauri-apps/plugin-notification";
|
||||||
import { useSession } from "@tensamin/storage/session";
|
import { useSession } from "@tensamin/storage/session";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useLocation, useNavigate } from "@tanstack/react-router";
|
||||||
import { decryptChatText } from "@tensamin/crypto/chatSecret";
|
import { decryptChatText } from "@tensamin/crypto/chatSecret";
|
||||||
import { log } from "@tensamin/shared/log";
|
import { log } from "@tensamin/shared/log";
|
||||||
import { playSound } from "@tensamin/shared/sounds";
|
import { playSound } from "@tensamin/shared/sounds";
|
||||||
|
|
@ -31,6 +36,7 @@ export default function Provider(props: { children: React.ReactNode }) {
|
||||||
const { addLiveMessage, chatSecret, getChatSecret, userId } = useChat();
|
const { addLiveMessage, chatSecret, getChatSecret, userId } = useChat();
|
||||||
const { moveUserIdToTop } = useSession();
|
const { moveUserIdToTop } = useSession();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return subscribePush(async (message) => {
|
return subscribePush(async (message) => {
|
||||||
|
|
@ -42,13 +48,19 @@ export default function Provider(props: { children: React.ReactNode }) {
|
||||||
|
|
||||||
if (!data.SenderId) return;
|
if (!data.SenderId) return;
|
||||||
|
|
||||||
|
const isCurrentChat =
|
||||||
|
location.pathname === "/chat" && userId === data.SenderId;
|
||||||
|
const appFocused =
|
||||||
|
document.hasFocus() && document.visibilityState === "visible";
|
||||||
|
const shouldAlert = !isCurrentChat || !appFocused;
|
||||||
|
|
||||||
const messageSecret =
|
const messageSecret =
|
||||||
userId === data.SenderId && chatSecret
|
isCurrentChat && chatSecret
|
||||||
? chatSecret
|
? chatSecret
|
||||||
: await getChatSecret(data.SenderId);
|
: await getChatSecret(data.SenderId);
|
||||||
|
|
||||||
if (!data.Message || !messageSecret) return;
|
if (!data.Message || !messageSecret) return;
|
||||||
playSound("message");
|
if (shouldAlert) playSound("message");
|
||||||
|
|
||||||
void decryptChatText(messageSecret, data.Message.Content)
|
void decryptChatText(messageSecret, data.Message.Content)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
@ -60,18 +72,19 @@ export default function Provider(props: { children: React.ReactNode }) {
|
||||||
.then(async (content) => {
|
.then(async (content) => {
|
||||||
if (!data.Message || !content || !data.SenderId) return;
|
if (!data.Message || !content || !data.SenderId) return;
|
||||||
|
|
||||||
if (userId === data.SenderId) {
|
if (isCurrentChat) {
|
||||||
addLiveMessage({
|
addLiveMessage({
|
||||||
...data.Message,
|
...data.Message,
|
||||||
Content: content ?? "Failed to decrypt message",
|
Content: content ?? "Failed to decrypt message",
|
||||||
decryptionFailed: content === null,
|
decryptionFailed: content === null,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!shouldAlert) return;
|
||||||
|
|
||||||
|
if (!isCurrentChat) {
|
||||||
// todo: add notification symbol to conversation cards (incl. message start)
|
// todo: add notification symbol to conversation cards (incl. message start)
|
||||||
moveUserIdToTop(data.SenderId);
|
moveUserIdToTop(data.SenderId);
|
||||||
const user = await get(data.SenderId);
|
|
||||||
|
|
||||||
if (await load("settings.receive_confirmations")) {
|
if (await load("settings.receive_confirmations")) {
|
||||||
void send(
|
void send(
|
||||||
|
|
@ -84,9 +97,18 @@ export default function Provider(props: { children: React.ReactNode }) {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await get(data.SenderId);
|
||||||
|
|
||||||
if (isTauri()) {
|
if (isTauri()) {
|
||||||
console.log("weewoo");
|
const permissionGranted =
|
||||||
|
(await isTauriNotificationPermissionGranted()) ||
|
||||||
|
(await requestTauriNotificationPermission()) === "granted";
|
||||||
|
|
||||||
|
if (permissionGranted) {
|
||||||
|
sendTauriNotification({ title: user.Display, body: content });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const hasPermissions = await requestNotificationPermission();
|
const hasPermissions = await requestNotificationPermission();
|
||||||
|
|
||||||
|
|
@ -133,6 +155,7 @@ export default function Provider(props: { children: React.ReactNode }) {
|
||||||
chatSecret,
|
chatSecret,
|
||||||
get,
|
get,
|
||||||
load,
|
load,
|
||||||
|
location.pathname,
|
||||||
navigate,
|
navigate,
|
||||||
send,
|
send,
|
||||||
moveUserIdToTop,
|
moveUserIdToTop,
|
||||||
|
|
|
||||||
8624
pnpm-lock.yaml
generated
8624
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue