qortalrequest for fetching profile data

This commit is contained in:
PhilReact 2023-10-31 02:02:08 +02:00
parent 4229e361d3
commit 9ac74bcf8d
9 changed files with 325 additions and 139 deletions

View File

@ -727,7 +727,8 @@
"bchange45": "Encrypt", "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": "Instant publish - requires", "bchange47": "Instant publish - requires",
"bchange48": "Do you give this application permission to send you notifications" "bchange48": "Do you give this application permission to send you notifications",
"bchange49": "Do you grant this application permission to access the following private information from your profile?"
}, },
"datapage": { "datapage": {
"dchange1": "Data Management", "dchange1": "Data Management",

View File

@ -467,9 +467,7 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
> >
<input <input
id=${key} id=${key}
placeholder=${`${key} ${translate( placeholder=${key + ' ' + get('settings.address')}
'settings.address'
)}`}
class="input" class="input"
.value=${this.wallets[key]} .value=${this.wallets[key]}
@change=${(e) => { @change=${(e) => {
@ -591,9 +589,9 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
> >
<input <input
id="key-name" id="key-name"
placeholder=${`${translate( placeholder=${translate(
'profile.profile9' 'profile.profile9'
)}`} )}
class="input" class="input"
.value=${this.newCustomDataKey} .value=${this.newCustomDataKey}
@change=${(e) => { @change=${(e) => {
@ -623,7 +621,7 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
<input <input
id=${key} id=${key}
placeholder=${`${translate('profile.profile13')}`} placeholder=${translate('profile.profile13')}
class="input" class="input"
.value=${this.newCustomDataField[key]} .value=${this.newCustomDataField[key]}
@change=${(e) => { @change=${(e) => {
@ -649,7 +647,7 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
<div style="width:100%;display:flex;justify-content:center;gap:10px"> <div style="width:100%;display:flex;justify-content:center;gap:10px">
<input <input
placeholder=${`${translate('profile.profile12')}`} placeholder=${translate('profile.profile12')}
class="input" class="input"
.value=${this.newFieldName} .value=${this.newFieldName}
@change=${(e) => { @change=${(e) => {

View File

@ -20,7 +20,7 @@ import { publishData } from '../../../../plugins/plugins/utils/publish-image.js'
import { parentEpml } from '../show-plugin.js'; import { parentEpml } from '../show-plugin.js';
import '../notification-view/popover.js'; import '../notification-view/popover.js';
import './avatar.js'; import './avatar.js';
import { setNewTab } from '../../redux/app/app-actions.js'; import { setNewTab, setProfileData } from '../../redux/app/app-actions.js';
import './profile-modal-update.js'; import './profile-modal-update.js';
class ProfileQdn extends connect(store)(LitElement) { class ProfileQdn extends connect(store)(LitElement) {
@ -220,12 +220,16 @@ class ProfileQdn extends connect(store)(LitElement) {
console.log({error}) console.log({error})
} }
} else {
customData[key] = data.customData[key];
} }
} }
this.profileData = { this.profileData = {
...response, ...response,
customData customData
} }
store.dispatch(setProfileData(this.profileData))
} }
} }
@ -352,10 +356,10 @@ class ProfileQdn extends connect(store)(LitElement) {
}); });
newObject['customData'][key] = encryptedData; newObject['customData'][key] = encryptedData;
} else { } else {
newObject['customData'][key] = data[key]; newObject['customData'][key] = newObject.customData[key];
} }
} }
console.log({newObject})
const newObjectToBase64 = await objectToBase64(newObject); const newObjectToBase64 = await objectToBase64(newObject);
// const encryptedData = encryptDataGroup({ // const encryptedData = encryptDataGroup({
// data64: newObjectToBase64, // data64: newObjectToBase64,
@ -382,6 +386,8 @@ class ProfileQdn extends connect(store)(LitElement) {
this.resourceExists = true; this.resourceExists = true;
this.profileData = data this.profileData = data
store.dispatch(setProfileData(data))
// this.setValues(newObject, { // this.setValues(newObject, {
// updated: Date.now(), // updated: Date.now(),
// }); // });

View File

@ -9,6 +9,7 @@ const CHAT_HEADS_STREAM_NAME = 'chat_heads'
const NODE_CONFIG_STREAM_NAME = 'node_config' const NODE_CONFIG_STREAM_NAME = 'node_config'
const CHAT_LAST_SEEN = 'chat_last_seen' const CHAT_LAST_SEEN = 'chat_last_seen'
const SIDE_EFFECT_ACTION = 'side_effect_action' const SIDE_EFFECT_ACTION = 'side_effect_action'
const PROFILE_DATA_ACTION = 'profile_data_action'
export const loggedInStream = new EpmlStream(LOGIN_STREAM_NAME, () => store.getState().app.loggedIn) export const loggedInStream = new EpmlStream(LOGIN_STREAM_NAME, () => store.getState().app.loggedIn)
export const configStream = new EpmlStream(CONFIG_STREAM_NAME, () => store.getState().config) export const configStream = new EpmlStream(CONFIG_STREAM_NAME, () => store.getState().config)
@ -18,6 +19,7 @@ export const chatHeadsStateStream = new EpmlStream(CHAT_HEADS_STREAM_NAME, () =>
export const nodeConfigStream = new EpmlStream(NODE_CONFIG_STREAM_NAME, () => store.getState().app.nodeConfig) export const nodeConfigStream = new EpmlStream(NODE_CONFIG_STREAM_NAME, () => store.getState().app.nodeConfig)
export const chatLastSeenStream = new EpmlStream(CHAT_LAST_SEEN, () => store.getState().app.chatLastSeen) export const chatLastSeenStream = new EpmlStream(CHAT_LAST_SEEN, () => store.getState().app.chatLastSeen)
export const sideEffectActionStream = new EpmlStream(SIDE_EFFECT_ACTION, () => store.getState().app.sideEffectAction) export const sideEffectActionStream = new EpmlStream(SIDE_EFFECT_ACTION, () => store.getState().app.sideEffectAction)
export const profileDataActionStream = new EpmlStream(SIDE_EFFECT_ACTION, () => store.getState().app.profileData)
@ -62,7 +64,9 @@ store.subscribe(() => {
if (oldState.app.sideEffectAction !== state.app.sideEffectAction) { if (oldState.app.sideEffectAction !== state.app.sideEffectAction) {
sideEffectActionStream.emit(state.app.sideEffectAction) sideEffectActionStream.emit(state.app.sideEffectAction)
} }
if(oldState.app.profileDataActionStream !== state.app.profileDataActionStream){
profileDataActionStream.emit(state.app.profileData)
}
oldState = state oldState = state
}) })

View File

@ -1,5 +1,5 @@
// Core App Actions here... // Core App Actions here...
import { UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, CHAT_HEADS, ACCOUNT_INFO, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN, ALLOW_QAPP_AUTO_LISTS, REMOVE_QAPP_AUTO_LISTS, SET_NEW_TAB, ADD_TAB_INFO, SET_TAB_NOTIFICATIONS, IS_OPEN_DEV_DIALOG, SET_NEW_NOTIFICATION, SET_SIDE_EFFECT } from '../app-action-types.js' import { UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, CHAT_HEADS, ACCOUNT_INFO, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN, ALLOW_QAPP_AUTO_LISTS, REMOVE_QAPP_AUTO_LISTS, SET_NEW_TAB, ADD_TAB_INFO, SET_TAB_NOTIFICATIONS, IS_OPEN_DEV_DIALOG, SET_NEW_NOTIFICATION, SET_SIDE_EFFECT, SET_PROFILE_DATA } from '../app-action-types.js'
export const doUpdateBlockInfo = (blockObj) => { export const doUpdateBlockInfo = (blockObj) => {
return (dispatch, getState) => { return (dispatch, getState) => {
@ -158,3 +158,9 @@ export const setSideEffectAction = (payload)=> {
payload payload
} }
} }
export const setProfileData = (payload)=> {
return {
type: SET_PROFILE_DATA,
payload
}
}

View File

@ -33,3 +33,4 @@ export const SET_TAB_NOTIFICATIONS = 'SET_TAB_NOTIFICATIONS'
export const IS_OPEN_DEV_DIALOG = 'IS_OPEN_DEV_DIALOG' export const IS_OPEN_DEV_DIALOG = 'IS_OPEN_DEV_DIALOG'
export const SET_NEW_NOTIFICATION = 'SET_NEW_NOTIFICATION' export const SET_NEW_NOTIFICATION = 'SET_NEW_NOTIFICATION'
export const SET_SIDE_EFFECT= 'SET_SIDE_EFFECT' export const SET_SIDE_EFFECT= 'SET_SIDE_EFFECT'
export const SET_PROFILE_DATA = 'SET_PROFILE_DATA'

View File

@ -1,6 +1,6 @@
// Loading state, login state, isNavDrawOpen state etc. None of this needs to be saved to localstorage. // Loading state, login state, isNavDrawOpen state etc. None of this needs to be saved to localstorage.
import { loadStateFromLocalStorage, saveStateToLocalStorage } from '../../localStorageHelpers.js' import { loadStateFromLocalStorage, saveStateToLocalStorage } from '../../localStorageHelpers.js'
import { LOG_IN, LOG_OUT, NETWORK_CONNECTION_STATUS, INIT_WORKERS, ADD_PLUGIN_URL, ADD_PLUGIN, ADD_NEW_PLUGIN_URL, NAVIGATE, SELECT_ADDRESS, ACCOUNT_INFO, CHAT_HEADS, UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, LOAD_NODE_CONFIG, SET_NODE, ADD_NODE, PAGE_URL, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN, ALLOW_QAPP_AUTO_LISTS, REMOVE_QAPP_AUTO_LISTS, SET_NEW_TAB, ADD_TAB_INFO, SET_TAB_NOTIFICATIONS, IS_OPEN_DEV_DIALOG, REMOVE_NODE, EDIT_NODE, SET_NEW_NOTIFICATION, SET_SIDE_EFFECT } from './app-action-types.js' import { LOG_IN, LOG_OUT, NETWORK_CONNECTION_STATUS, INIT_WORKERS, ADD_PLUGIN_URL, ADD_PLUGIN, ADD_NEW_PLUGIN_URL, NAVIGATE, SELECT_ADDRESS, ACCOUNT_INFO, CHAT_HEADS, UPDATE_BLOCK_INFO, UPDATE_NODE_STATUS, UPDATE_NODE_INFO, LOAD_NODE_CONFIG, SET_NODE, ADD_NODE, PAGE_URL, ADD_AUTO_LOAD_IMAGES_CHAT, REMOVE_AUTO_LOAD_IMAGES_CHAT, ALLOW_QAPP_AUTO_AUTH, REMOVE_QAPP_AUTO_AUTH, SET_CHAT_LAST_SEEN, ADD_CHAT_LAST_SEEN, ALLOW_QAPP_AUTO_LISTS, REMOVE_QAPP_AUTO_LISTS, SET_NEW_TAB, ADD_TAB_INFO, SET_TAB_NOTIFICATIONS, IS_OPEN_DEV_DIALOG, REMOVE_NODE, EDIT_NODE, SET_NEW_NOTIFICATION, SET_SIDE_EFFECT, SET_PROFILE_DATA } from './app-action-types.js'
import { initWorkersReducer } from './reducers/init-workers.js' import { initWorkersReducer } from './reducers/init-workers.js'
import { loginReducer } from './reducers/login-reducer.js' import { loginReducer } from './reducers/login-reducer.js'
import { setNode, addNode, removeNode, editNode } from './reducers/manage-node.js' import { setNode, addNode, removeNode, editNode } from './reducers/manage-node.js'
@ -52,7 +52,8 @@ const INITIAL_STATE = {
tabInfo: {}, tabInfo: {},
isOpenDevDialog: false, isOpenDevDialog: false,
newNotification: null, newNotification: null,
sideEffectAction: null sideEffectAction: null,
profileData: null
} }
export default (state = INITIAL_STATE, action) => { export default (state = INITIAL_STATE, action) => {
@ -293,6 +294,12 @@ export default (state = INITIAL_STATE, action) => {
sideEffectAction: action.payload sideEffectAction: action.payload
} }
} }
case SET_PROFILE_DATA: {
return {
...state,
profileData: action.payload
}
}
default: default:
return state return state

View File

@ -66,3 +66,6 @@ export const VOTE_ON_POLL= 'VOTE_ON_POLL'
//CREATE_POLL //CREATE_POLL
export const CREATE_POLL= 'CREATE_POLL' export const CREATE_POLL= 'CREATE_POLL'
//GET_PROFILE_DATA
export const GET_PROFILE_DATA = 'GET_PROFILE_DATA'

View File

@ -281,7 +281,7 @@ class WebBrowser extends LitElement {
else { else {
identifier = null; identifier = null;
} }
}extractComponents } extractComponents
const components = {}; const components = {};
components["service"] = service; components["service"] = service;
components["name"] = name; components["name"] = name;
@ -462,7 +462,7 @@ class WebBrowser extends LitElement {
const joinFee = (Number(data) / 1e8).toFixed(8) const joinFee = (Number(data) / 1e8).toFixed(8)
return joinFee return joinFee
} }
async getArbitraryFee (){ async getArbitraryFee() {
const timestamp = Date.now() const timestamp = Date.now()
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
@ -475,7 +475,7 @@ class WebBrowser extends LitElement {
const arbitraryFee = (Number(data) / 1e8).toFixed(8) const arbitraryFee = (Number(data) / 1e8).toFixed(8)
return { return {
timestamp, timestamp,
fee : Number(data), fee: Number(data),
feeToShow: arbitraryFee feeToShow: arbitraryFee
} }
} }
@ -1562,7 +1562,7 @@ class WebBrowser extends LitElement {
break; break;
} }
case actions.OPEN_NEW_TAB: { case actions.OPEN_NEW_TAB: {
if(!data.qortalLink){ if (!data.qortalLink) {
const obj = {}; const obj = {};
const errorMsg = 'Please enter a qortal link - qortal://...'; const errorMsg = 'Please enter a qortal link - qortal://...';
obj['error'] = errorMsg; obj['error'] = errorMsg;
@ -1593,7 +1593,7 @@ class WebBrowser extends LitElement {
name: this.name name: this.name
} }
); );
if (res.action === 'accept'){ if (res.action === 'accept') {
this.addAppToNotificationList(this.name) this.addAppToNotificationList(this.name)
response = true response = true
break; break;
@ -1608,11 +1608,11 @@ class WebBrowser extends LitElement {
} }
case actions.SEND_LOCAL_NOTIFICATION: { case actions.SEND_LOCAL_NOTIFICATION: {
const {title, url, icon, message} = data const { title, url, icon, message } = data
try { try {
const id = `appNotificationList-${this.selectedAddress.address}` const id = `appNotificationList-${this.selectedAddress.address}`
const checkData = localStorage.getItem(id) ? JSON.parse(localStorage.getItem(id)) : null; const checkData = localStorage.getItem(id) ? JSON.parse(localStorage.getItem(id)) : null;
if(!checkData || !checkData[this.name]) throw new Error('App not on permission list') if (!checkData || !checkData[this.name]) throw new Error('App not on permission list')
const appInfo = checkData[this.name] const appInfo = checkData[this.name]
const lastNotification = appInfo.lastNotification const lastNotification = appInfo.lastNotification
const interval = appInfo.interval const interval = appInfo.interval
@ -1629,7 +1629,7 @@ class WebBrowser extends LitElement {
} else { } else {
throw new Error(`duration until another notification can be sent: ${interval - timeDifference}`) throw new Error(`duration until another notification can be sent: ${interval - timeDifference}`)
} }
} else if(!lastNotification){ } else if (!lastNotification) {
parentEpml.request('showNotification', { parentEpml.request('showNotification', {
title, type: "qapp-local-notification", sound: '', url, options: { body: message, icon, badge: icon } title, type: "qapp-local-notification", sound: '', url, options: { body: message, icon, badge: icon }
}) })
@ -2049,6 +2049,161 @@ class WebBrowser extends LitElement {
break; break;
} }
case 'GET_PROFILE_DATA': {
const defaultProperties = ['tagline', 'bio', 'wallets']
const requiredFields = ['property'];
const missingFields = [];
requiredFields.forEach((field) => {
if (!data[field] && data[field] !== 0) {
missingFields.push(field);
}
});
if (missingFields.length > 0) {
const missingFieldsString = missingFields.join(', ');
const errorMsg = `Missing fields: ${missingFieldsString}`
let data = {};
data['error'] = errorMsg;
response = JSON.stringify(data);
break
}
try {
const profileData = window.parent.reduxStore.getState().app.profileData
if (!profileData) {
throw new Error('User does not have a profile')
}
const property = data.property
const propertyIndex = defaultProperties.indexOf(property)
if (propertyIndex !== -1) {
const requestedData = profileData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
}
if (property.includes('-private')) {
const resPrivateProperty = await showModalAndWait(
actions.GET_PROFILE_DATA, {
property
}
);
if (resPrivateProperty.action === 'accept') {
const requestedData = profileData.customData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
} else {
throw new Error('User denied permission for private property')
}
} else {
const requestedData = profileData.customData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
}
} catch (error) {
const obj = {};
const errorMsg = error.message || 'Failed to join the group.';
obj['error'] = errorMsg;
response = JSON.stringify(obj);
} finally {
this.loader.hide();
}
break;
}
case 'SET_PROFILE_DATA': {
const defaultProperties = ['tagline', 'bio', 'wallets']
const requiredFields = ['property', 'data'];
const missingFields = [];
requiredFields.forEach((field) => {
if (!data[field] && data[field] !== 0) {
missingFields.push(field);
}
});
if (missingFields.length > 0) {
const missingFieldsString = missingFields.join(', ');
const errorMsg = `Missing fields: ${missingFieldsString}`
let data = {};
data['error'] = errorMsg;
response = JSON.stringify(data);
break
}
try {
const profileData = window.parent.reduxStore.getState().app.profileData
if (!profileData) {
throw new Error('User does not have a profile')
}
const property = data.property
const propertyIndex = defaultProperties.indexOf(property)
if (propertyIndex !== -1) {
const requestedData = profileData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
}
if (property.includes('-private')) {
const resPrivateProperty = await showModalAndWait(
actions.GET_PROFILE_DATA, {
property
}
);
if (resPrivateProperty.action === 'accept') {
const requestedData = profileData.customData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
} else {
throw new Error('User denied permission for private property')
}
} else {
const requestedData = profileData.customData[property]
if (requestedData) {
response = JSON.stringify(requestedData);
break
} else {
throw new Error('Cannot find requested data')
}
}
} catch (error) {
const obj = {};
const errorMsg = error.message || 'Failed to join the group.';
obj['error'] = errorMsg;
response = JSON.stringify(obj);
} finally {
this.loader.hide();
}
break;
}
case actions.GET_WALLET_BALANCE: { case actions.GET_WALLET_BALANCE: {
const requiredFields = ['coin']; const requiredFields = ['coin'];
@ -3103,7 +3258,7 @@ class WebBrowser extends LitElement {
} }
} }
addAppToNotificationList(appName) { addAppToNotificationList(appName) {
if(!appName) throw new Error('unknown app name') if (!appName) throw new Error('unknown app name')
const id = `appNotificationList-${this.selectedAddress.address}`; const id = `appNotificationList-${this.selectedAddress.address}`;
const checkData = localStorage.getItem(id) ? JSON.parse(localStorage.getItem(id)) : null; const checkData = localStorage.getItem(id) ? JSON.parse(localStorage.getItem(id)) : null;
@ -3493,6 +3648,11 @@ async function showModalAndWait(type, data) {
<p class="modal-paragraph">${get("browserpage.bchange46")}: <span> ${data.filename}</span></p> <p class="modal-paragraph">${get("browserpage.bchange46")}: <span> ${data.filename}</span></p>
</div> </div>
` : ''} ` : ''}
${type === actions.GET_PROFILE_DATA ? `
<div class="modal-subcontainer">
<p class="modal-paragraph">${get("browserpage.bchange49")}: <span style="font-weight: bold"> ${data.property}</span></p>
</div>
` : ''}
${type === actions.NOTIFICATIONS_PERMISSION ? ` ${type === actions.NOTIFICATIONS_PERMISSION ? `
<div class="modal-subcontainer"> <div class="modal-subcontainer">
<p class="modal-paragraph">${get("browserpage.bchange48")}</p> <p class="modal-paragraph">${get("browserpage.bchange48")}</p>