Browse Source

refactor: Remove defunct $needsActiveIdentitySelection method and fix activeDid consistency

## Changes Made

### Code Cleanup
- Remove unused $needsActiveIdentitySelection() method (36 lines)
- Remove method signature from IPlatformServiceMixin interface
- Remove method signature from Vue module declaration

### Database Consistency Fix
- Change activeDid clearing from empty string ('') to NULL for consistency
- Ensures proper foreign key constraint compatibility
- Maintains API compatibility by still returning empty string to components

## Impact
- Reduces codebase complexity by removing unused functionality
- Improves database integrity with consistent NULL usage
- No breaking changes to component APIs
- Migration and auto-selection now handle all identity management

## Files Changed
- src/utils/PlatformServiceMixin.ts: -42 lines, +1 line
pull/188/head
Matthew Raymer 5 days ago
parent
commit
8eb4ad5c74
  1. 43
      src/utils/PlatformServiceMixin.ts

43
src/utils/PlatformServiceMixin.ts

@ -236,45 +236,6 @@ export const PlatformServiceMixin = {
}
},
/**
* Check if active identity needs user intervention
* Returns true if active_identity table is empty but accounts exist
* This allows components to show appropriate UI for user selection
*/
async $needsActiveIdentitySelection(): Promise<boolean> {
try {
// Check if active_identity table has a valid activeDid
const activeIdentity = await this.$dbQuery(
"SELECT activeDid FROM active_identity WHERE id = 1",
);
const currentActiveDid = activeIdentity?.values?.[0]?.[0] as string;
// If we have an activeDid, validate it exists in accounts
if (currentActiveDid) {
const accountExists = await this.$dbQuery(
"SELECT did FROM accounts WHERE did = ?",
[currentActiveDid],
);
return !accountExists?.values?.length;
}
// If no activeDid, check if there are any accounts available
const availableAccounts = await this.$dbQuery(
"SELECT COUNT(*) FROM accounts",
);
const accountCount = availableAccounts?.values?.[0]?.[0] as number;
return accountCount > 0;
} catch (error) {
logger.error(
"[PlatformServiceMixin] Error checking if active identity selection needed:",
error,
);
return false;
}
},
/**
* Get available account DIDs for user selection
* Returns array of DIDs that can be set as active identity
@ -722,7 +683,7 @@ export const PlatformServiceMixin = {
"[PlatformServiceMixin] Active identity not found in accounts, clearing",
);
await this.$dbExec(
"UPDATE active_identity SET activeDid = '', lastUpdated = datetime('now') WHERE id = 1",
"UPDATE active_identity SET activeDid = NULL, lastUpdated = datetime('now') WHERE id = 1",
);
return { activeDid: "" };
}
@ -1975,7 +1936,6 @@ export interface IPlatformServiceMixin {
): Promise<Settings>;
$getActiveIdentity(): Promise<{ activeDid: string }>;
$withTransaction<T>(callback: () => Promise<T>): Promise<T>;
$needsActiveIdentitySelection(): Promise<boolean>;
$getAvailableAccountDids(): Promise<string[]>;
isCapacitor: boolean;
isWeb: boolean;
@ -2100,7 +2060,6 @@ declare module "@vue/runtime-core" {
): Promise<Settings>;
$getActiveIdentity(): Promise<{ activeDid: string }>;
$withTransaction<T>(fn: () => Promise<T>): Promise<T>;
$needsActiveIdentitySelection(): Promise<boolean>;
$getAvailableAccountDids(): Promise<string[]>;
// Specialized shortcuts - contacts cached, settings fresh

Loading…
Cancel
Save