mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-04-24 20:07:52 +00:00
cases
This commit is contained in:
parent
e6cbec4b08
commit
b665d229f3
10
src/App.tsx
10
src/App.tsx
@ -404,13 +404,17 @@ function App() {
|
||||
globalApiKey = key;
|
||||
}
|
||||
useEffect(() => {
|
||||
chrome?.runtime?.sendMessage({ action: "getApiKey" }, (response) => {
|
||||
window.sendMessage("getApiKey")
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
handleSetGlobalApikey(response)
|
||||
handleSetGlobalApikey(response);
|
||||
setApiKey(response);
|
||||
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to get API key:", error?.message || "An error occurred");
|
||||
});
|
||||
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (extState) {
|
||||
|
@ -90,14 +90,16 @@ export const NotAuthenticated = ({
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "getCustomNodesFromStorage" },
|
||||
(response) => {
|
||||
window.sendMessage("getCustomNodesFromStorage")
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
setCustomNodes(response || []);
|
||||
}
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to get custom nodes from storage:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}, []);
|
||||
|
||||
useEffect(()=> {
|
||||
@ -147,19 +149,21 @@ export const NotAuthenticated = ({
|
||||
// Assuming the response is in plain text and will be 'true' or 'false'
|
||||
const data = await response.text();
|
||||
if (data === "true") {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "setApiKey", payload },
|
||||
(response) => {
|
||||
window.sendMessage("setApiKey", payload)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
handleSetGlobalApikey(payload);
|
||||
setIsValidApiKey(true);
|
||||
setUseLocalNode(true);
|
||||
if (!fromStartUp) {
|
||||
setApiKey(payload)
|
||||
setApiKey(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to set API key:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
} else {
|
||||
setIsValidApiKey(false);
|
||||
setUseLocalNode(false);
|
||||
@ -208,17 +212,19 @@ export const NotAuthenticated = ({
|
||||
setCustomNodes(nodes);
|
||||
setCustomNodeToSaveIndex(null);
|
||||
if (!nodes) return;
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "setCustomNodes", nodes },
|
||||
(response) => {
|
||||
window.sendMessage("setCustomNodes", nodes)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
setMode("list");
|
||||
setUrl("http://");
|
||||
setCustomApiKey("");
|
||||
// add alert
|
||||
// add alert if needed
|
||||
}
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to set custom nodes:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -338,17 +344,18 @@ export const NotAuthenticated = ({
|
||||
url: "http://127.0.0.1:12391",
|
||||
})
|
||||
setUseLocalNode(false)
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "setApiKey", payload:null },
|
||||
(response) => {
|
||||
window.sendMessage("setApiKey", null)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
setApiKey(null);
|
||||
handleSetGlobalApikey(null);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to set API key:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}}
|
||||
disabled={false}
|
||||
@ -462,16 +469,17 @@ export const NotAuthenticated = ({
|
||||
setMode("list");
|
||||
setShow(false);
|
||||
setUseLocalNode(false);
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "setApiKey", payload:null },
|
||||
(response) => {
|
||||
window.sendMessage("setApiKey", null)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
setApiKey(null);
|
||||
handleSetGlobalApikey(null);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to set API key:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}}
|
||||
variant="contained"
|
||||
>
|
||||
@ -517,16 +525,17 @@ export const NotAuthenticated = ({
|
||||
setShow(false);
|
||||
setIsValidApiKey(false);
|
||||
setUseLocalNode(false);
|
||||
chrome?.runtime?.sendMessage(
|
||||
{ action: "setApiKey", payload:null },
|
||||
(response) => {
|
||||
window.sendMessage("setApiKey", null)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
setApiKey(null);
|
||||
handleSetGlobalApikey(null);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to set API key:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}}
|
||||
variant="contained"
|
||||
>
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {
|
||||
addDataPublishes,
|
||||
addTimestampEnterChat,
|
||||
addUserSettings,
|
||||
banFromGroup,
|
||||
cancelBan,
|
||||
@ -7,7 +8,9 @@ import {
|
||||
createGroup,
|
||||
decryptWallet,
|
||||
findUsableApi,
|
||||
getApiKeyFromStorage,
|
||||
getBalanceInfo,
|
||||
getCustomNodesFromStorage,
|
||||
getDataPublishes,
|
||||
getKeyPair,
|
||||
getLTCBalance,
|
||||
@ -24,6 +27,7 @@ import {
|
||||
removeAdmin,
|
||||
saveTempPublish,
|
||||
sendCoin,
|
||||
setChatHeads,
|
||||
walletVersion,
|
||||
} from "./background";
|
||||
|
||||
@ -716,3 +720,182 @@ export async function balanceCase(request, event) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function notificationCase(request, event) {
|
||||
try {
|
||||
const notificationId = "chat_notification_" + Date.now(); // Create a unique ID
|
||||
|
||||
chrome.notifications.create(notificationId, {
|
||||
type: "basic",
|
||||
iconUrl: "qort.png", // Add an appropriate icon for chat notifications
|
||||
title: "New Group Message!",
|
||||
message: "You have received a new message from one of your groups",
|
||||
priority: 2, // Use the maximum priority to ensure it's noticeable
|
||||
// buttons: [
|
||||
// { title: 'Go to group' }
|
||||
// ]
|
||||
});
|
||||
// Set a timeout to clear the notification after 'timeout' milliseconds
|
||||
setTimeout(() => {
|
||||
chrome.notifications.clear(notificationId);
|
||||
}, 3000);
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "notification",
|
||||
payload: true,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "notification",
|
||||
error: "Error displaying notifaction",
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function addTimestampEnterChatCase(request, event) {
|
||||
try {
|
||||
const { groupId, timestamp } = request.payload;
|
||||
const response = await addTimestampEnterChat({groupId, timestamp});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "addTimestampEnterChat",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "addTimestampEnterChat",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function setApiKeyCase(request, event) {
|
||||
try {
|
||||
const payload = request.payload;
|
||||
chrome.storage.local.set({ apiKey: payload }, () => {
|
||||
// sendResponse(true);
|
||||
});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "setApiKey",
|
||||
payload: true,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "setApiKey",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
export async function setCustomNodesCase(request, event) {
|
||||
try {
|
||||
const nodes = request.payload;
|
||||
chrome.storage.local.set({ customNodes: nodes }, () => {
|
||||
// sendResponse(true);
|
||||
});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "setCustomNodes",
|
||||
payload: true,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "setCustomNodes",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getApiKeyCase(request, event) {
|
||||
try {
|
||||
const response = await getApiKeyFromStorage();
|
||||
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getApiKey",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getApiKey",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCustomNodesFromStorageCase(request, event) {
|
||||
try {
|
||||
const response = await getCustomNodesFromStorage();
|
||||
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getCustomNodesFromStorage",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getCustomNodesFromStorage",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMu
|
||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
||||
import {
|
||||
addDataPublishesCase,
|
||||
addTimestampEnterChatCase,
|
||||
addUserSettingsCase,
|
||||
balanceCase,
|
||||
banFromGroupCase,
|
||||
@ -37,6 +38,8 @@ import {
|
||||
cancelInvitationToGroupCase,
|
||||
createGroupCase,
|
||||
decryptWalletCase,
|
||||
getApiKeyCase,
|
||||
getCustomNodesFromStorageCase,
|
||||
getDataPublishesCase,
|
||||
getTempPublishCase,
|
||||
getUserSettingsCase,
|
||||
@ -48,10 +51,14 @@ import {
|
||||
ltcBalanceCase,
|
||||
makeAdminCase,
|
||||
nameCase,
|
||||
notificationCase,
|
||||
registerNameCase,
|
||||
removeAdminCase,
|
||||
saveTempPublishCase,
|
||||
sendCoinCase,
|
||||
setApiKeyCase,
|
||||
setChatHeadsCase,
|
||||
setCustomNodesCase,
|
||||
userInfoCase,
|
||||
validApiCase,
|
||||
versionCase,
|
||||
@ -134,7 +141,7 @@ const checkDifference = (createdTimestamp) => {
|
||||
Date.now() - createdTimestamp < timeDifferenceForNotificationChatsBackground
|
||||
);
|
||||
};
|
||||
const getApiKeyFromStorage = async () => {
|
||||
export const getApiKeyFromStorage = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.get("apiKey", (result) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
@ -145,7 +152,7 @@ const getApiKeyFromStorage = async () => {
|
||||
});
|
||||
};
|
||||
|
||||
const getCustomNodesFromStorage = async () => {
|
||||
export const getCustomNodesFromStorage = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.get("customNodes", (result) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
@ -396,16 +403,20 @@ const handleNotificationDirect = async (directs) => {
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isFocused) {
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
action: "notification",
|
||||
payload: {},
|
||||
},
|
||||
(response) => {
|
||||
window
|
||||
.sendMessage("notification", {})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
// Handle success if needed
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"Failed to send notification:",
|
||||
error.message || "An error occurred"
|
||||
);
|
||||
});
|
||||
|
||||
const notificationId = "chat_notification_" + Date.now();
|
||||
chrome.notifications.create(notificationId, {
|
||||
type: "basic",
|
||||
@ -639,16 +650,20 @@ const handleNotification = async (groups) => {
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isFocused) {
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
action: "notification",
|
||||
payload: {},
|
||||
},
|
||||
(response) => {
|
||||
window
|
||||
.sendMessage("notification", {})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
// Handle success if needed
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"Failed to send notification:",
|
||||
error.message || "An error occurred"
|
||||
);
|
||||
});
|
||||
|
||||
const notificationId = "chat_notification_" + Date.now();
|
||||
chrome.notifications.create(notificationId, {
|
||||
type: "basic",
|
||||
@ -2614,7 +2629,7 @@ export function removeDuplicateWindow(popupUrl) {
|
||||
);
|
||||
}
|
||||
|
||||
async function setChatHeads(data) {
|
||||
export async function setChatHeads(data) {
|
||||
const wallet = await getSaveWallet();
|
||||
const address = wallet.address0;
|
||||
const dataString = JSON.stringify(data);
|
||||
@ -2818,7 +2833,7 @@ async function setGroupData({
|
||||
});
|
||||
}
|
||||
|
||||
async function addTimestampEnterChat({ groupId, timestamp }) {
|
||||
export async function addTimestampEnterChat({ groupId, timestamp }) {
|
||||
const wallet = await getSaveWallet();
|
||||
const address = wallet.address0;
|
||||
const data = await getTimestampEnterChat();
|
||||
@ -2974,6 +2989,24 @@ function setupMessageListener() {
|
||||
case "removeAdmin":
|
||||
removeAdminCase(request, event);
|
||||
break;
|
||||
case "notification":
|
||||
notificationCase(request, event);
|
||||
break;
|
||||
|
||||
case "addTimestampEnterChat":
|
||||
addTimestampEnterChatCase(request, event);
|
||||
break;
|
||||
case "setApiKey":
|
||||
setApiKeyCase(request, event);
|
||||
break;
|
||||
case "setCustomNodes":
|
||||
setCustomNodesCase(request, event);
|
||||
case "getApiKey":
|
||||
getApiKeyCase(request, event);
|
||||
break;
|
||||
case "getCustomNodesFromStorage":
|
||||
getCustomNodesFromStorageCase(request, event);
|
||||
break;
|
||||
default:
|
||||
console.error("Unknown action:", request.action);
|
||||
}
|
||||
|
@ -267,13 +267,13 @@ const sendChatDirect = async ({ chatReference = undefined, messageText, otherDat
|
||||
"senderName": myName
|
||||
})
|
||||
setNewChat(null)
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: response.recipient,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat()
|
||||
}, 400);
|
||||
|
@ -901,22 +901,22 @@ export const Group = ({
|
||||
setMemberGroups(message.payload);
|
||||
|
||||
if (selectedGroupRef.current && groupSectionRef.current === "chat") {
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: selectedGroupRef.current.groupId,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}
|
||||
if (selectedDirectRef.current) {
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: selectedDirectRef.current.address,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
}
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat();
|
||||
@ -946,18 +946,7 @@ export const Group = ({
|
||||
// Update the component state with the received 'sendqort' state
|
||||
setDirects(message.payload);
|
||||
|
||||
// if (selectedGroupRef.current) {
|
||||
// chrome?.runtime?.sendMessage({
|
||||
// action: "addTimestampEnterChat",
|
||||
// payload: {
|
||||
// timestamp: Date.now(),
|
||||
// groupId: selectedGroupRef.current.groupId,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// setTimeout(() => {
|
||||
// getTimestampEnterChat();
|
||||
// }, 200);
|
||||
|
||||
} else if (message.action === "PLAY_NOTIFICATION_SOUND") {
|
||||
audio.play();
|
||||
}
|
||||
@ -1115,14 +1104,14 @@ export const Group = ({
|
||||
|
||||
setNewChat(false);
|
||||
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: findDirect.address,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
setSelectedDirect(findDirect);
|
||||
getTimestampEnterChat();
|
||||
@ -1152,14 +1141,14 @@ export const Group = ({
|
||||
|
||||
setNewChat(false);
|
||||
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: findDirect.address,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
setSelectedDirect(findDirect);
|
||||
getTimestampEnterChat();
|
||||
@ -1201,14 +1190,14 @@ export const Group = ({
|
||||
|
||||
const handleMarkAsRead = (e) => {
|
||||
const { groupId } = e.detail;
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addGroupNotificationTimestamp",
|
||||
payload: {
|
||||
@ -1323,14 +1312,14 @@ export const Group = ({
|
||||
setFirstSecretKeyInCreation(false);
|
||||
setGroupSection("chat");
|
||||
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: findGroup.groupId,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
setSelectedGroup(findGroup);
|
||||
setMobileViewMode("group");
|
||||
@ -1537,14 +1526,14 @@ export const Group = ({
|
||||
setNewChat(false);
|
||||
setSelectedDirect(null);
|
||||
if (selectedGroupRef.current) {
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: selectedGroupRef.current.groupId,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat();
|
||||
}, 200);
|
||||
@ -1644,13 +1633,13 @@ export const Group = ({
|
||||
setNewChat(false);
|
||||
// setSelectedGroup(null);
|
||||
setIsOpenDrawer(false);
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: direct.address,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
setSelectedDirect(direct);
|
||||
|
||||
@ -1771,172 +1760,7 @@ export const Group = ({
|
||||
borderRadius: !isMobile && '0px 15px 15px 0px'
|
||||
}}
|
||||
>
|
||||
{/* <div
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
justifyContent: "center",
|
||||
gap: "20px",
|
||||
padding: "10px",
|
||||
flexDirection: "column",
|
||||
}}
|
||||
>
|
||||
{isMobile && (
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
justifyContent: "flex-end",
|
||||
}}
|
||||
>
|
||||
<CloseIcon
|
||||
onClick={() => {
|
||||
setIsOpenDrawer(false);
|
||||
}}
|
||||
sx={{
|
||||
cursor: "pointer",
|
||||
color: "white",
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
<CustomButton
|
||||
onClick={() => {
|
||||
setChatMode((prev) =>
|
||||
prev === "directs" ? "groups" : "directs"
|
||||
);
|
||||
|
||||
}}
|
||||
sx={{
|
||||
backgroundColor: chatMode === 'directs' && ( groupChatHasUnread || groupsAnnHasUnread) ? 'red' : 'revert'
|
||||
}}
|
||||
>
|
||||
{chatMode === "groups" && (
|
||||
<>
|
||||
<MarkUnreadChatAltIcon
|
||||
sx={{
|
||||
color: directChatHasUnread ? "red" : "white",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{chatMode === "directs" ? "Switch to groups" : "Direct msgs"}
|
||||
</CustomButton>
|
||||
</div> */}
|
||||
{/* <div
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
flexDirection: "column",
|
||||
alignItems: "flex-start",
|
||||
flexGrow: 1,
|
||||
overflowY: "auto",
|
||||
visibility: chatMode === "groups" && "hidden",
|
||||
position: chatMode === "groups" && "fixed",
|
||||
left: chatMode === "groups" && "-1000px",
|
||||
}}
|
||||
>
|
||||
{directs.map((direct: any) => (
|
||||
<List sx={{
|
||||
width: '100%'
|
||||
}} className="group-list" dense={true}>
|
||||
<ListItem
|
||||
// secondaryAction={
|
||||
// <IconButton edge="end" aria-label="delete">
|
||||
// <SettingsIcon />
|
||||
// </IconButton>
|
||||
// }
|
||||
onClick={() => {
|
||||
setSelectedDirect(null);
|
||||
setNewChat(false);
|
||||
// setSelectedGroup(null);
|
||||
setIsOpenDrawer(false);
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
timestamp: Date.now(),
|
||||
groupId: direct.address,
|
||||
},
|
||||
});
|
||||
setTimeout(() => {
|
||||
setSelectedDirect(direct);
|
||||
|
||||
getTimestampEnterChat();
|
||||
}, 200);
|
||||
}}
|
||||
sx={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
flexDirection: "column",
|
||||
cursor: "pointer",
|
||||
border: "1px #232428 solid",
|
||||
padding: "2px",
|
||||
borderRadius: "2px",
|
||||
background:
|
||||
direct?.address === selectedDirect?.address && "white",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ListItemAvatar>
|
||||
<Avatar
|
||||
sx={{
|
||||
background: "#232428",
|
||||
color: "white",
|
||||
}}
|
||||
alt={direct?.name || direct?.address}
|
||||
// src={`${getBaseApiReact()}/arbitrary/THUMBNAIL/${groupOwner?.name}/qortal_group_avatar_${group.groupId}?async=true`}
|
||||
>
|
||||
{(direct?.name || direct?.address)?.charAt(0)}
|
||||
</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText
|
||||
primary={direct?.name || direct?.address}
|
||||
primaryTypographyProps={{
|
||||
style: {
|
||||
color:
|
||||
direct?.address === selectedDirect?.address &&
|
||||
"black",
|
||||
textWrap: "wrap",
|
||||
overflow: "hidden",
|
||||
},
|
||||
}} // Change the color of the primary text
|
||||
secondaryTypographyProps={{
|
||||
style: {
|
||||
color:
|
||||
direct?.address === selectedDirect?.address &&
|
||||
"black",
|
||||
},
|
||||
}}
|
||||
sx={{
|
||||
width: "150px",
|
||||
fontFamily: "Inter",
|
||||
fontSize: "16px",
|
||||
}}
|
||||
/>
|
||||
{direct?.sender !== myAddress &&
|
||||
direct?.timestamp &&
|
||||
((!timestampEnterData[direct?.address] &&
|
||||
Date.now() - direct?.timestamp <
|
||||
timeDifferenceForNotificationChats) ||
|
||||
timestampEnterData[direct?.address] <
|
||||
direct?.timestamp) && (
|
||||
<MarkChatUnreadIcon
|
||||
sx={{
|
||||
color: "red",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</ListItem>
|
||||
</List>
|
||||
))}
|
||||
</div> */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
@ -1994,14 +1818,14 @@ export const Group = ({
|
||||
// getTimestampEnterChat();
|
||||
}, 200);
|
||||
|
||||
chrome?.runtime?.sendMessage({
|
||||
action: "addTimestampEnterChat",
|
||||
payload: {
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: group.groupId,
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat();
|
||||
}, 200);
|
||||
|
Loading…
x
Reference in New Issue
Block a user