mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-11-03 06:07:51 +00:00
qortalrequest for local q-app notifications
This commit is contained in:
@@ -719,7 +719,8 @@
|
||||
"bchange43": "Do you give this application permission to add to this list?",
|
||||
"bchange44": "Do you give this application permission to delete from this list?",
|
||||
"bchange45": "Encrypt",
|
||||
"bchange46": "Do you give this application permission to save the following file"
|
||||
"bchange46": "Do you give this application permission to save the following file",
|
||||
"bchange47": "Do you give this application permission to send you notifications"
|
||||
},
|
||||
"datapage": {
|
||||
"dchange1": "Data Management",
|
||||
|
||||
@@ -396,14 +396,15 @@ class ShowPlugin extends connect(store)(LitElement) {
|
||||
icon = 'tab'
|
||||
}
|
||||
|
||||
if (tab.myPlugObj && (tab.myPlugObj.url === 'websites' || tab.myPlugObj.url === 'qapps') && this.tabInfo[tab.id]) {
|
||||
title = this.tabInfo[tab.id].name
|
||||
if (tab.myPlugObj && (tab.myPlugObj.url === 'myapp') && this.tabInfo[tab.id]) {
|
||||
title = this.tabInfo[tab.id].name
|
||||
}
|
||||
|
||||
if (tab.myPlugObj && (tab.myPlugObj.url === 'websites' || tab.myPlugObj.url === 'qapps') && this.tabInfo[tab.id]) {
|
||||
count = this.tabInfo[tab.id].count
|
||||
if (tab.myPlugObj && (tab.myPlugObj.url === 'myapp') && this.tabInfo[tab.id]) {
|
||||
count = this.tabInfo[tab.id].count
|
||||
}
|
||||
|
||||
|
||||
if (tab.myPlugObj && tab.myPlugObj.url === 'q-chat') {
|
||||
for (const chat of this.chatHeads) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NEW_MESSAGE, NEW_MESSAGE_NOTIFICATION_QAPP } from './types'
|
||||
import { newMessage, newMessageNotificationQapp } from './notification-actions'
|
||||
import { NEW_MESSAGE, NEW_MESSAGE_NOTIFICATION_QAPP, NEW_MESSAGE_NOTIFICATION_QAPP_LOCAL } from './types'
|
||||
import { newMessage, newMessageNotificationQapp, newMessageNotificationQappLocal } from './notification-actions'
|
||||
|
||||
export const dispatcher = function (notificationState) {
|
||||
|
||||
@@ -8,6 +8,8 @@ export const dispatcher = function (notificationState) {
|
||||
return newMessage(notificationState.data)
|
||||
case NEW_MESSAGE_NOTIFICATION_QAPP:
|
||||
return newMessageNotificationQapp(notificationState.data)
|
||||
case NEW_MESSAGE_NOTIFICATION_QAPP_LOCAL:
|
||||
return newMessageNotificationQappLocal(notificationState.data)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { newMessage, newMessageNotificationQapp } from './new-message'
|
||||
export { newMessage, newMessageNotificationQapp, newMessageNotificationQappLocal } from './new-message'
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { store } from '../../store.js'
|
||||
import { doPageUrl, setNewTab } from '../../redux/app/app-actions.js'
|
||||
import isElectron from 'is-electron'
|
||||
import ShortUniqueId from 'short-unique-id';
|
||||
|
||||
const uid = new ShortUniqueId()
|
||||
|
||||
export const newMessage = (data) => {
|
||||
const alert = playSound(data.sound)
|
||||
@@ -101,6 +104,157 @@ export const newMessageNotificationQapp = (data) => {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const extractComponents= async (url)=> {
|
||||
if (!url.startsWith("qortal://")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
url = url.replace(/^(qortal\:\/\/)/, "");
|
||||
if (url.includes("/")) {
|
||||
let parts = url.split("/");
|
||||
const service = parts[0].toUpperCase();
|
||||
parts.shift();
|
||||
const name = parts[0];
|
||||
parts.shift();
|
||||
let identifier;
|
||||
|
||||
if (parts.length > 0) {
|
||||
identifier = parts[0]; // Do not shift yet
|
||||
// Check if a resource exists with this service, name and identifier combination
|
||||
let responseObj = await parentEpml.request('apiCall', {
|
||||
url: `/arbitrary/resource/status/${service}/${name}/${identifier}?apiKey=${this.getApiKey()}`
|
||||
})
|
||||
|
||||
if (responseObj.totalChunkCount > 0) {
|
||||
// Identifier exists, so don't include it in the path
|
||||
parts.shift();
|
||||
}
|
||||
else {
|
||||
identifier = null;
|
||||
}
|
||||
}
|
||||
|
||||
const path = parts.join("/");
|
||||
|
||||
const components = {};
|
||||
components["service"] = service;
|
||||
components["name"] = name;
|
||||
components["identifier"] = identifier;
|
||||
components["path"] = path;
|
||||
return components;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export const newMessageNotificationQappLocal = (data) => {
|
||||
const alert = playSound(data.sound)
|
||||
|
||||
// Should I show notification ?
|
||||
if (store.getState().user.notifications.q_chat.showNotification) {
|
||||
|
||||
// Yes, I can but should I play sound ?
|
||||
if (store.getState().user.notifications.q_chat.playSound) {
|
||||
|
||||
const notify = new Notification(data.title, data.options)
|
||||
|
||||
notify.onshow = (e) => {
|
||||
alert.play()
|
||||
}
|
||||
|
||||
notify.onclick = async(e) => {
|
||||
const url = data?.url
|
||||
const value = url
|
||||
let newQuery = value;
|
||||
if (newQuery.endsWith('/')) {
|
||||
newQuery = newQuery.slice(0, -1);
|
||||
}
|
||||
const res = await extractComponents(newQuery)
|
||||
if (!res) return
|
||||
const { service, name, identifier, path } = res
|
||||
let query = `?service=${service}`
|
||||
if (name) {
|
||||
query = query + `&name=${name}`
|
||||
}
|
||||
if (identifier) {
|
||||
query = query + `&identifier=${identifier}`
|
||||
}
|
||||
if (path) {
|
||||
query = query + `&path=${path}`
|
||||
}
|
||||
const tab = {
|
||||
url: `qdn/browser/index.html${query}`,
|
||||
id: uid(),
|
||||
myPlugObj: {
|
||||
"url": service === 'WEBSITE' ? "websites" : "qapps",
|
||||
"domain": "core",
|
||||
"page": `qdn/browser/index.html${query}`,
|
||||
"title": name,
|
||||
"icon": service === 'WEBSITE' ? 'vaadin:desktop' : 'vaadin:external-browser',
|
||||
"mwcicon": service === 'WEBSITE' ? 'desktop_mac' : 'open_in_browser',
|
||||
"menus": [],
|
||||
"parent": false
|
||||
}
|
||||
}
|
||||
store.dispatch(setNewTab(tab))
|
||||
if (!isElectron()) {
|
||||
window.focus();
|
||||
} else {
|
||||
window.electronAPI.focusApp()
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
const notify = new Notification(data.title, data.options)
|
||||
|
||||
notify.onclick = async(e) => {
|
||||
const url = data?.url
|
||||
const value = url
|
||||
let newQuery = value;
|
||||
if (newQuery.endsWith('/')) {
|
||||
newQuery = newQuery.slice(0, -1);
|
||||
}
|
||||
const res = await extractComponents(newQuery)
|
||||
if (!res) return
|
||||
const { service, name, identifier, path } = res
|
||||
let query = `?service=${service}`
|
||||
if (name) {
|
||||
query = query + `&name=${name}`
|
||||
}
|
||||
if (identifier) {
|
||||
query = query + `&identifier=${identifier}`
|
||||
}
|
||||
if (path) {
|
||||
query = query + `&path=${path}`
|
||||
}
|
||||
const tab = {
|
||||
url: `qdn/browser/index.html${query}`,
|
||||
id: uid(),
|
||||
myPlugObj: {
|
||||
"url": service === 'WEBSITE' ? "websites" : "qapps",
|
||||
"domain": "core",
|
||||
"page": `qdn/browser/index.html${query}`,
|
||||
"title": name,
|
||||
"icon": service === 'WEBSITE' ? 'vaadin:desktop' : 'vaadin:external-browser',
|
||||
"mwcicon": service === 'WEBSITE' ? 'desktop_mac' : 'open_in_browser',
|
||||
"menus": [],
|
||||
"parent": false
|
||||
}
|
||||
}
|
||||
store.dispatch(setNewTab(tab))
|
||||
if (!isElectron()) {
|
||||
window.focus();
|
||||
} else {
|
||||
window.electronAPI.focusApp()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const playSound = (soundUrl) => {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export const NEW_MESSAGE = 'NEW_MESSAGE'
|
||||
export const NEW_MESSAGE_NOTIFICATION_QAPP = 'NEW_MESSAGE_NOTIFICATION_QAPP'
|
||||
export const NEW_MESSAGE_NOTIFICATION_QAPP_LOCAL = 'NEW_MESSAGE_NOTIFICATION_QAPP_LOCAL'
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const UI_VERSION = "4.0.4";
|
||||
export const UI_VERSION = "4.3.0";
|
||||
|
||||
Reference in New Issue
Block a user