@ -999,6 +999,7 @@ import {
DEFAULT_PUSH_SERVER ,
DEFAULT_PUSH_SERVER ,
IMAGE_TYPE_PROFILE ,
IMAGE_TYPE_PROFILE ,
NotificationIface ,
NotificationIface ,
USE_DEXIE_DB ,
} from "../constants/app" ;
} from "../constants/app" ;
import {
import {
db ,
db ,
@ -1012,6 +1013,7 @@ import {
DEFAULT_PASSKEY_EXPIRATION_MINUTES ,
DEFAULT_PASSKEY_EXPIRATION_MINUTES ,
MASTER_SETTINGS_KEY ,
MASTER_SETTINGS_KEY ,
} from "../db/tables/settings" ;
} from "../db/tables/settings" ;
import * as databaseUtil from "../db/databaseUtil" ;
import {
import {
clearPasskeyToken ,
clearPasskeyToken ,
EndorserRateLimits ,
EndorserRateLimits ,
@ -1030,6 +1032,7 @@ import {
} from "../libs/util" ;
} from "../libs/util" ;
import { UserProfile } from "@/libs/partnerServer" ;
import { UserProfile } from "@/libs/partnerServer" ;
import { logger } from "../utils/logger" ;
import { logger } from "../utils/logger" ;
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory" ;
const inputImportFileNameRef = ref < Blob > ( ) ;
const inputImportFileNameRef = ref < Blob > ( ) ;
@ -1145,9 +1148,14 @@ export default class AccountViewView extends Vue {
if ( error . status === 404 ) {
if ( error . status === 404 ) {
/ / t h i s i s o k : t h e p r o f i l e i s n o t y e t c r e a t e d
/ / t h i s i s o k : t h e p r o f i l e i s n o t y e t c r e a t e d
} else {
} else {
logConsoleAndDb (
databaseUtil . logConsoleAndDb (
"Error loading profile: " + errorStringForLog ( error ) ,
"Error loading profile: " + errorStringForLog ( error ) ,
) ;
) ;
if ( USE_DEXIE_DB ) {
logConsoleAndDb (
"Error loading profile: " + errorStringForLog ( error ) ,
) ;
}
this . $notify (
this . $notify (
{
{
group : "alert" ,
group : "alert" ,
@ -1224,8 +1232,12 @@ export default class AccountViewView extends Vue {
* Initializes component state with values from the database or defaults .
* Initializes component state with values from the database or defaults .
* /
* /
async initializeState ( ) {
async initializeState ( ) {
await db . open ( ) ;
let settings = await databaseUtil . retrieveSettingsForActiveAccount ( ) ;
const settings = await retrieveSettingsForActiveAccount ( ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
settings = await retrieveSettingsForActiveAccount ( ) ;
}
console . log ( "activeDid" , settings . activeDid , "settings" , settings ) ;
this . activeDid = settings . activeDid || "" ;
this . activeDid = settings . activeDid || "" ;
this . apiServer = settings . apiServer || "" ;
this . apiServer = settings . apiServer || "" ;
@ -1268,42 +1280,67 @@ export default class AccountViewView extends Vue {
async toggleShowContactAmounts ( ) {
async toggleShowContactAmounts ( ) {
this . showContactGives = ! this . showContactGives ;
this . showContactGives = ! this . showContactGives ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
showContactGivesInline : this . showContactGives ,
showContactGivesInline : this . showContactGives ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
showContactGivesInline : this . showContactGives ,
} ) ;
}
}
}
async toggleShowGeneralAdvanced ( ) {
async toggleShowGeneralAdvanced ( ) {
this . showGeneralAdvanced = ! this . showGeneralAdvanced ;
this . showGeneralAdvanced = ! this . showGeneralAdvanced ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
showGeneralAdvanced : this . showGeneralAdvanced ,
showGeneralAdvanced : this . showGeneralAdvanced ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
showGeneralAdvanced : this . showGeneralAdvanced ,
} ) ;
}
}
}
async toggleProdWarning ( ) {
async toggleProdWarning ( ) {
this . warnIfProdServer = ! this . warnIfProdServer ;
this . warnIfProdServer = ! this . warnIfProdServer ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
warnIfProdServer : this . warnIfProdServer ,
warnIfProdServer : this . warnIfProdServer ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
warnIfProdServer : this . warnIfProdServer ,
} ) ;
}
}
}
async toggleTestWarning ( ) {
async toggleTestWarning ( ) {
this . warnIfTestServer = ! this . warnIfTestServer ;
this . warnIfTestServer = ! this . warnIfTestServer ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
warnIfTestServer : this . warnIfTestServer ,
warnIfTestServer : this . warnIfTestServer ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
warnIfTestServer : this . warnIfTestServer ,
} ) ;
}
}
}
async toggleShowShortcutBvc ( ) {
async toggleShowShortcutBvc ( ) {
this . showShortcutBvc = ! this . showShortcutBvc ;
this . showShortcutBvc = ! this . showShortcutBvc ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
showShortcutBvc : this . showShortcutBvc ,
showShortcutBvc : this . showShortcutBvc ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
showShortcutBvc : this . showShortcutBvc ,
} ) ;
}
}
}
readableDate ( timeStr : string ) {
readableDate ( timeStr : string ) {
@ -1314,9 +1351,18 @@ export default class AccountViewView extends Vue {
* Processes the identity and updates the component ' s state .
* Processes the identity and updates the component ' s state .
* /
* /
async processIdentity ( ) {
async processIdentity ( ) {
const account : Account | undefined = await retrieveAccountMetadata (
const platformService = PlatformServiceFactory . getInstance ( ) ;
this . activeDid ,
const dbAccount = await platformService . dbQuery ( "SELECT * FROM accounts WHERE did = ?" , [ this . activeDid ] ) ;
) ;
console . log ( "activeDid" , this . activeDid , "dbAccount" , dbAccount ) ;
let account : Account | undefined = undefined ;
if ( dbAccount ) {
account = databaseUtil . mapColumnsToValues ( dbAccount . columns , dbAccount . values ) [ 0 ] as Account ;
}
if ( USE_DEXIE_DB ) {
account = await retrieveAccountMetadata (
this . activeDid ,
) ;
}
if ( account ? . identity ) {
if ( account ? . identity ) {
const identity = JSON . parse ( account . identity as string ) as IIdentifier ;
const identity = JSON . parse ( account . identity as string ) as IIdentifier ;
this . publicHex = identity . keys [ 0 ] . publicKeyHex ;
this . publicHex = identity . keys [ 0 ] . publicKeyHex ;
@ -1359,9 +1405,14 @@ export default class AccountViewView extends Vue {
this . $refs . pushNotificationPermission as PushNotificationPermission
this . $refs . pushNotificationPermission as PushNotificationPermission
) . open ( DAILY_CHECK_TITLE , async ( success : boolean , timeText : string ) => {
) . open ( DAILY_CHECK_TITLE , async ( success : boolean , timeText : string ) => {
if ( success ) {
if ( success ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
await databaseUtil . updateDefaultSettings ( {
notifyingNewActivityTime : timeText ,
notifyingNewActivityTime : timeText ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingNewActivityTime : timeText ,
} ) ;
}
this . notifyingNewActivity = true ;
this . notifyingNewActivity = true ;
this . notifyingNewActivityTime = timeText ;
this . notifyingNewActivityTime = timeText ;
}
}
@ -1375,9 +1426,14 @@ export default class AccountViewView extends Vue {
text : "" , / / u n u s e d , o n l y h e r e t o s a t i s f y t y p e c h e c k
text : "" , / / u n u s e d , o n l y h e r e t o s a t i s f y t y p e c h e c k
callback : async ( success ) => {
callback : async ( success ) => {
if ( success ) {
if ( success ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
await databaseUtil . updateDefaultSettings ( {
notifyingNewActivityTime : "" ,
notifyingNewActivityTime : "" ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingNewActivityTime : "" ,
} ) ;
}
this . notifyingNewActivity = false ;
this . notifyingNewActivity = false ;
this . notifyingNewActivityTime = "" ;
this . notifyingNewActivityTime = "" ;
}
}
@ -1419,10 +1475,16 @@ export default class AccountViewView extends Vue {
DIRECT_PUSH_TITLE ,
DIRECT_PUSH_TITLE ,
async ( success : boolean , timeText : string , message ? : string ) => {
async ( success : boolean , timeText : string , message ? : string ) => {
if ( success ) {
if ( success ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
await databaseUtil . updateDefaultSettings ( {
notifyingReminderMessage : message ,
notifyingReminderMessage : message ,
notifyingReminderTime : timeText ,
notifyingReminderTime : timeText ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingReminderMessage : message ,
notifyingReminderTime : timeText ,
} ) ;
}
this . notifyingReminder = true ;
this . notifyingReminder = true ;
this . notifyingReminderMessage = message || "" ;
this . notifyingReminderMessage = message || "" ;
this . notifyingReminderTime = timeText ;
this . notifyingReminderTime = timeText ;
@ -1438,10 +1500,16 @@ export default class AccountViewView extends Vue {
text : "" , / / u n u s e d , o n l y h e r e t o s a t i s f y t y p e c h e c k
text : "" , / / u n u s e d , o n l y h e r e t o s a t i s f y t y p e c h e c k
callback : async ( success ) => {
callback : async ( success ) => {
if ( success ) {
if ( success ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
await databaseUtil . updateDefaultSettings ( {
notifyingReminderMessage : "" ,
notifyingReminderMessage : "" ,
notifyingReminderTime : "" ,
notifyingReminderTime : "" ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingReminderMessage : "" ,
notifyingReminderTime : "" ,
} ) ;
}
this . notifyingReminder = false ;
this . notifyingReminder = false ;
this . notifyingReminderMessage = "" ;
this . notifyingReminderMessage = "" ;
this . notifyingReminderTime = "" ;
this . notifyingReminderTime = "" ;
@ -1455,30 +1523,47 @@ export default class AccountViewView extends Vue {
public async toggleHideRegisterPromptOnNewContact ( ) {
public async toggleHideRegisterPromptOnNewContact ( ) {
const newSetting = ! this . hideRegisterPromptOnNewContact ;
const newSetting = ! this . hideRegisterPromptOnNewContact ;
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
hideRegisterPromptOnNewContact : newSetting ,
hideRegisterPromptOnNewContact : newSetting ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
hideRegisterPromptOnNewContact : newSetting ,
} ) ;
}
this . hideRegisterPromptOnNewContact = newSetting ;
this . hideRegisterPromptOnNewContact = newSetting ;
}
}
public async updatePasskeyExpiration ( ) {
public async updatePasskeyExpiration ( ) {
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
passkeyExpirationMinutes : this . passkeyExpirationMinutes ,
passkeyExpirationMinutes : this . passkeyExpirationMinutes ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
passkeyExpirationMinutes : this . passkeyExpirationMinutes ,
} ) ;
}
clearPasskeyToken ( ) ;
clearPasskeyToken ( ) ;
this . passkeyExpirationDescription = tokenExpiryTimeDescription ( ) ;
this . passkeyExpirationDescription = tokenExpiryTimeDescription ( ) ;
}
}
public async turnOffNotifyingFlags ( ) {
public async turnOffNotifyingFlags ( ) {
/ / s h o u l d t e l l t h e p u s h s e r v e r a s w e l l
/ / s h o u l d t e l l t h e p u s h s e r v e r a s w e l l
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingNewActivityTime : "" ,
notifyingNewActivityTime : "" ,
notifyingReminderMessage : "" ,
notifyingReminderMessage : "" ,
notifyingReminderTime : "" ,
notifyingReminderTime : "" ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
notifyingNewActivityTime : "" ,
notifyingReminderMessage : "" ,
notifyingReminderTime : "" ,
} ) ;
}
this . notifyingNewActivity = false ;
this . notifyingNewActivity = false ;
this . notifyingNewActivityTime = "" ;
this . notifyingNewActivityTime = "" ;
this . notifyingReminder = false ;
this . notifyingReminder = false ;
@ -1518,7 +1603,10 @@ export default class AccountViewView extends Vue {
* @ returns { Promise < Blob > } The generated blob object .
* @ returns { Promise < Blob > } The generated blob object .
* /
* /
private async generateDatabaseBlob ( ) : Promise < Blob > {
private async generateDatabaseBlob ( ) : Promise < Blob > {
return await db . export ( { prettyJson : true } ) ;
if ( USE_DEXIE_DB ) {
return await db . export ( { prettyJson : true } ) ;
}
throw new Error ( "Not implemented" ) ;
}
}
/ * *
/ * *
@ -1539,7 +1627,7 @@ export default class AccountViewView extends Vue {
private downloadDatabaseBackup ( url : string ) {
private downloadDatabaseBackup ( url : string ) {
const downloadAnchor = this . $refs . downloadLink as HTMLAnchorElement ;
const downloadAnchor = this . $refs . downloadLink as HTMLAnchorElement ;
downloadAnchor . href = url ;
downloadAnchor . href = url ;
downloadAnchor . download = ` ${ db . name } -backup.json ` ;
downloadAnchor . download = ` ${ AppString . APP_NAME_NO_SPACES } -backup.json ` ;
downloadAnchor . click ( ) ; / / d o e s n ' t w o r k f o r s o m e b r o w s e r s , e g . D u c k D u c k G o
downloadAnchor . click ( ) ; / / d o e s n ' t w o r k f o r s o m e b r o w s e r s , e g . D u c k D u c k G o
}
}
@ -1620,7 +1708,8 @@ export default class AccountViewView extends Vue {
* /
* /
async submitImportFile ( ) {
async submitImportFile ( ) {
if ( inputImportFileNameRef . value != null ) {
if ( inputImportFileNameRef . value != null ) {
await db
if ( USE_DEXIE_DB ) {
await db
. delete ( )
. delete ( )
. then ( async ( ) => {
. then ( async ( ) => {
/ / B u l k E r r o r : s e t t i n g s . b u l k A d d ( ) : 1 o f 2 1 o p e r a t i o n s f a i l e d . E r r o r s : C o n s t r a i n t E r r o r : K e y a l r e a d y e x i s t s i n t h e o b j e c t s t o r e .
/ / B u l k E r r o r : s e t t i n g s . b u l k A d d ( ) : 1 o f 2 1 o p e r a t i o n s f a i l e d . E r r o r s : C o n s t r a i n t E r r o r : K e y a l r e a d y e x i s t s i n t h e o b j e c t s t o r e .
@ -1640,6 +1729,9 @@ export default class AccountViewView extends Vue {
- 1 ,
- 1 ,
) ;
) ;
} ) ;
} ) ;
} else {
throw new Error ( "Not implemented" ) ;
}
}
}
}
}
@ -1727,7 +1819,13 @@ export default class AccountViewView extends Vue {
if ( ! this . isRegistered ) {
if ( ! this . isRegistered ) {
/ / t h e u s e r w a s n o t k n o w n t o b e r e g i s t e r e d , b u t n o w t h e y a r e ( b e c a u s e w e g o t n o e r r o r ) s o l e t ' s r e c o r d i t
/ / t h e u s e r w a s n o t k n o w n t o b e r e g i s t e r e d , b u t n o w t h e y a r e ( b e c a u s e w e g o t n o e r r o r ) s o l e t ' s r e c o r d i t
try {
try {
await updateAccountSettings ( did , { isRegistered : true } ) ;
await databaseUtil . updateAccountSettings ( did , { isRegistered : true } ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
isRegistered : true ,
} ) ;
}
this . isRegistered = true ;
this . isRegistered = true ;
} catch ( err ) {
} catch ( err ) {
logger . error ( "Got an error updating settings:" , err ) ;
logger . error ( "Got an error updating settings:" , err ) ;
@ -1787,26 +1885,41 @@ export default class AccountViewView extends Vue {
}
}
async onClickSaveApiServer ( ) {
async onClickSaveApiServer ( ) {
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
apiServer : this . apiServerInput ,
apiServer : this . apiServerInput ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
apiServer : this . apiServerInput ,
} ) ;
}
this . apiServer = this . apiServerInput ;
this . apiServer = this . apiServerInput ;
}
}
async onClickSavePartnerServer ( ) {
async onClickSavePartnerServer ( ) {
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
partnerApiServer : this . partnerApiServerInput ,
partnerApiServer : this . partnerApiServerInput ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
partnerApiServer : this . partnerApiServerInput ,
} ) ;
}
this . partnerApiServer = this . partnerApiServerInput ;
this . partnerApiServer = this . partnerApiServerInput ;
}
}
async onClickSavePushServer ( ) {
async onClickSavePushServer ( ) {
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
webPushServer : this . webPushServerInput ,
webPushServer : this . webPushServerInput ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
webPushServer : this . webPushServerInput ,
} ) ;
}
this . webPushServer = this . webPushServerInput ;
this . webPushServer = this . webPushServerInput ;
this . $notify (
this . $notify (
{
{
@ -1822,10 +1935,15 @@ export default class AccountViewView extends Vue {
openImageDialog ( ) {
openImageDialog ( ) {
( this . $refs . imageMethodDialog as ImageMethodDialog ) . open (
( this . $refs . imageMethodDialog as ImageMethodDialog ) . open (
async ( imgUrl ) => {
async ( imgUrl ) => {
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
profileImageUrl : imgUrl ,
profileImageUrl : imgUrl ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
profileImageUrl : imgUrl ,
} ) ;
}
this . profileImageUrl = imgUrl ;
this . profileImageUrl = imgUrl ;
/ / c o n s o l e . l o g ( " G o t i m a g e U R L : " , i m g U r l ) ;
/ / c o n s o l e . l o g ( " G o t i m a g e U R L : " , i m g U r l ) ;
} ,
} ,
@ -1886,10 +2004,15 @@ export default class AccountViewView extends Vue {
/ / k e e p t h e i m a g e U r l i n l o c a l S t o r a g e s o t h e u s e r c a n t r y a g a i n i f t h e y w a n t
/ / k e e p t h e i m a g e U r l i n l o c a l S t o r a g e s o t h e u s e r c a n t r y a g a i n i f t h e y w a n t
}
}
await db . open ( ) ;
await databaseUtil . updateDefaultSettings ( {
await db . settings . update ( MASTER_SETTINGS_KEY , {
profileImageUrl : undefined ,
profileImageUrl : undefined ,
} ) ;
} ) ;
if ( USE_DEXIE_DB ) {
await db . open ( ) ;
await db . settings . update ( MASTER_SETTINGS_KEY , {
profileImageUrl : undefined ,
} ) ;
}
this . profileImageUrl = undefined ;
this . profileImageUrl = undefined ;
} catch ( error ) {
} catch ( error ) {
@ -1978,7 +2101,10 @@ export default class AccountViewView extends Vue {
throw Error ( "Profile not saved" ) ;
throw Error ( "Profile not saved" ) ;
}
}
} catch ( error ) {
} catch ( error ) {
logConsoleAndDb ( "Error saving profile: " + errorStringForLog ( error ) ) ;
databaseUtil . logConsoleAndDb ( "Error saving profile: " + errorStringForLog ( error ) ) ;
if ( USE_DEXIE_DB ) {
logConsoleAndDb ( "Error saving profile: " + errorStringForLog ( error ) ) ;
}
const errorMessage : string =
const errorMessage : string =
error . response ? . data ? . error ? . message ||
error . response ? . data ? . error ? . message ||
error . response ? . data ? . error ||
error . response ? . data ? . error ||
@ -2068,7 +2194,10 @@ export default class AccountViewView extends Vue {
throw Error ( "Profile not deleted" ) ;
throw Error ( "Profile not deleted" ) ;
}
}
} catch ( error ) {
} catch ( error ) {
logConsoleAndDb ( "Error deleting profile: " + errorStringForLog ( error ) ) ;
databaseUtil . logConsoleAndDb ( "Error deleting profile: " + errorStringForLog ( error ) ) ;
if ( USE_DEXIE_DB ) {
logConsoleAndDb ( "Error deleting profile: " + errorStringForLog ( error ) ) ;
}
const errorMessage : string =
const errorMessage : string =
error . response ? . data ? . error ? . message ||
error . response ? . data ? . error ? . message ||
error . response ? . data ? . error ||
error . response ? . data ? . error ||