@ -247,11 +247,17 @@
< fa icon = "spinner" class = "fa-spin-pulse" > < / fa > Loading & hellip ;
< fa icon = "spinner" class = "fa-spin-pulse" > < / fa > Loading & hellip ;
< / p >
< / p >
< / div >
< / div >
< div v-if ="!isFeedLoading && feedData.length === 0" >
< p class = "text-slate-500 text-center italic mt-4 mb-4" >
No claims match your filters .
< / p >
< / div >
< / div >
< / div >
< / section >
< / section >
< / template >
< / template >
< script lang = "ts" >
< script lang = "ts" >
import * as R from "ramda" ;
import { UAParser } from "ua-parser-js" ;
import { UAParser } from "ua-parser-js" ;
import { IIdentifier } from "@veramo/core" ;
import { IIdentifier } from "@veramo/core" ;
import { Component , Vue } from "vue-facing-decorator" ;
import { Component , Vue } from "vue-facing-decorator" ;
@ -267,17 +273,24 @@ import { NotificationIface } from "@/constants/app";
import { db , accountsDB } from "@/db/index" ;
import { db , accountsDB } from "@/db/index" ;
import { Account } from "@/db/tables/accounts" ;
import { Account } from "@/db/tables/accounts" ;
import { Contact } from "@/db/tables/contacts" ;
import { Contact } from "@/db/tables/contacts" ;
import { MASTER_SETTINGS_KEY , Settings } from "@/db/tables/settings" ;
import {
BoundingBox ,
isAnyFeedFilterOn ,
MASTER_SETTINGS_KEY ,
Settings ,
} from "@/db/tables/settings" ;
import { accessToken } from "@/libs/crypto" ;
import { accessToken } from "@/libs/crypto" ;
import {
import {
contactForDid ,
contactForDid ,
containsNonHiddenDid ,
didInfoForContact ,
didInfoForContact ,
getPlanFromCache ,
GiverInputInfo ,
GiverInputInfo ,
GiveServer Record ,
GiveSummary Record ,
} from "@/libs/endorserServer" ;
} from "@/libs/endorserServer" ;
import { generateSaveAndActivateIdentity } from "@/libs/util" ;
import { generateSaveAndActivateIdentity } from "@/libs/util" ;
interface GiveRecordWithContactInfo extends GiveServer Record {
interface GiveRecordWithContactInfo extends GiveSummary Record {
giver : {
giver : {
displayName : string ;
displayName : string ;
known : boolean ;
known : boolean ;
@ -310,11 +323,16 @@ export default class HomeView extends Vue {
feedData : GiveRecordWithContactInfo [ ] = [ ] ;
feedData : GiveRecordWithContactInfo [ ] = [ ] ;
feedPreviousOldestId ? : string ;
feedPreviousOldestId ? : string ;
feedLastViewedClaimId ? : string ;
feedLastViewedClaimId ? : string ;
isAnyFeedFilterOn : boolean ;
isCreatingIdentifier = false ;
isCreatingIdentifier = false ;
isFeedFilteredByContacts = false ;
isFeedFilteredByVisible = false ;
isFeedFilteredByNearby = false ;
isFeedFilteredByNearby = false ;
isFeedLoading = true ;
isFeedLoading = true ;
isRegistered = false ;
isRegistered = false ;
searchBoxes : Array < {
name : string ;
bbox : BoundingBox ;
} > = [ ] ;
showShortcutBvc = false ;
showShortcutBvc = false ;
userAgentInfo = new UAParser ( ) ; / / s e e h t t p s : / / d o c s . u a p a r s e r . j s . o r g / v 2 / a p i / u a - p a r s e r - j s / g e t - o s . h t m l
userAgentInfo = new UAParser ( ) ; / / s e e h t t p s : / / d o c s . u a p a r s e r . j s . o r g / v 2 / a p i / u a - p a r s e r - j s / g e t - o s . h t m l
@ -349,11 +367,14 @@ export default class HomeView extends Vue {
this . activeDid = settings ? . activeDid || "" ;
this . activeDid = settings ? . activeDid || "" ;
this . allContacts = await db . contacts . toArray ( ) ;
this . allContacts = await db . contacts . toArray ( ) ;
this . feedLastViewedClaimId = settings ? . lastViewedClaimId ;
this . feedLastViewedClaimId = settings ? . lastViewedClaimId ;
this . isFeedFilteredByContacts = ! ! settings ? . filterFeedContacts ;
this . isFeedFilteredByVisible = ! ! settings ? . filterFeedByVisible ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedNearby ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedBy Nearby ;
this . isRegistered = ! ! settings ? . isRegistered ;
this . isRegistered = ! ! settings ? . isRegistered ;
this . searchBoxes = settings ? . searchBoxes || [ ] ;
this . showShortcutBvc = ! ! settings ? . showShortcutBvc ;
this . showShortcutBvc = ! ! settings ? . showShortcutBvc ;
this . isAnyFeedFilterOn = isAnyFeedFilterOn ( settings ) ;
if ( this . allMyDids . length === 0 ) {
if ( this . allMyDids . length === 0 ) {
this . isCreatingIdentifier = true ;
this . isCreatingIdentifier = true ;
this . activeDid = await generateSaveAndActivateIdentity ( ) ;
this . activeDid = await generateSaveAndActivateIdentity ( ) ;
@ -383,7 +404,7 @@ export default class HomeView extends Vue {
}
}
resultsAreFiltered ( ) {
resultsAreFiltered ( ) {
return this . isFeedFilteredByContacts || this . isFeedFilteredByNearby ;
return this . isFeedFilteredByVisible || this . isFeedFilteredByNearby ;
}
}
notificationsSupported ( ) {
notificationsSupported ( ) {
@ -395,21 +416,15 @@ export default class HomeView extends Vue {
"Content-Type" : "application/json" ,
"Content-Type" : "application/json" ,
} ;
} ;
const identity = await this . getIdentity ( this . activeDid ) ;
if ( this . activeDid ) {
if ( this . activeDid ) {
await accountsDB . open ( ) ;
if ( identity ) {
const allAccounts = await accountsDB . accounts . toArray ( ) ;
headers [ "Authorization" ] = "Bearer " + ( await accessToken ( identity ) ) ;
const account = allAccounts . find (
} else {
( acc ) => acc . did === this . activeDid ,
) as Account ;
const identity = JSON . parse ( account ? . identity || "null" ) ;
if ( ! identity ) {
throw new Error (
throw new Error (
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service. Switch your ID." ,
"An ID is chosen but there are no keys for it so it cannot be used to talk with the service. Switch your ID." ,
) ;
) ;
}
}
headers [ "Authorization" ] = "Bearer " + ( await accessToken ( identity ) ) ;
} else {
} else {
/ / i t ' s O K w i t h o u t a u t h . . . w e j u s t w o n ' t g e t a n y i d e n t i f i e r s
/ / i t ' s O K w i t h o u t a u t h . . . w e j u s t w o n ' t g e t a n y i d e n t i f i e r s
}
}
@ -420,8 +435,9 @@ export default class HomeView extends Vue {
async reloadFeedOnChange ( ) {
async reloadFeedOnChange ( ) {
await db . open ( ) ;
await db . open ( ) ;
const settings = ( await db . settings . get ( MASTER_SETTINGS_KEY ) ) as Settings ;
const settings = ( await db . settings . get ( MASTER_SETTINGS_KEY ) ) as Settings ;
this . isFeedFilteredByContacts = ! ! settings ? . filterFeedContacts ;
this . isFeedFilteredByVisible = ! ! settings ? . filterFeedByVisible ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedNearby ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedByNearby ;
this . isAnyFeedFilterOn = isAnyFeedFilterOn ( settings ) ;
this . feedData = [ ] ;
this . feedData = [ ] ;
this . feedPreviousOldestId = undefined ;
this . feedPreviousOldestId = undefined ;
@ -438,14 +454,30 @@ export default class HomeView extends Vue {
}
}
}
}
latLongInAnySearchBox ( lat : number , long : number ) {
for ( const boxInfo of this . searchBoxes ) {
if (
boxInfo . bbox . westLong <= long &&
long <= boxInfo . bbox . eastLong &&
boxInfo . bbox . minLat <= lat &&
lat <= boxInfo . bbox . maxLat
) {
return true ;
}
}
}
public async updateAllFeed ( ) {
public async updateAllFeed ( ) {
this . isFeedLoading = true ;
this . isFeedLoading = true ;
let endOfResults = true ;
await this . retrieveGives ( this . apiServer , this . feedPreviousOldestId )
await this . retrieveGives ( this . apiServer , this . feedPreviousOldestId )
. then ( async ( results ) => {
. then ( async ( results ) => {
if ( results . data . length > 0 ) {
if ( results . data . length > 0 ) {
endOfResults = false ;
/ / i n c l u d e t h e d e s c r i p t i o n s o f t h e g i v e r a n d r e c e i v e r
/ / i n c l u d e t h e d e s c r i p t i o n s o f t h e g i v e r a n d r e c e i v e r
const newFeedData : GiveRecordWithContactInfo = results . data . map (
const identity = await this . getIdentity ( this . activeDid ) ;
( record : GiveServerRecord ) => {
const newFeedData : Array < Promise < GiveRecordWithContactInfo > > =
results . data . map ( async ( record : GiveSummaryRecord ) => {
/ / s i m i l a r c o d e i s i n e n d o r s e r - m o b i l e u t i l i t y . t s
/ / s i m i l a r c o d e i s i n e n d o r s e r - m o b i l e u t i l i t y . t s
/ / c l a i m . c l a i m h a p p e n f o r s o m e c l a i m s w r a p p e d i n a V e r i f i a b l e C r e d e n t i a l
/ / c l a i m . c l a i m h a p p e n f o r s o m e c l a i m s w r a p p e d i n a V e r i f i a b l e C r e d e n t i a l
/ / e s l i n t - d i s a b l e - n e x t - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
/ / e s l i n t - d i s a b l e - n e x t - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
@ -456,6 +488,33 @@ export default class HomeView extends Vue {
/ / r e c i p i e n t . d i d i s f o r l e g a c y d a t a , b e f o r e M a r c h 2 0 2 3
/ / r e c i p i e n t . d i d i s f o r l e g a c y d a t a , b e f o r e M a r c h 2 0 2 3
const recipientDid =
const recipientDid =
claim . recipient ? . identifier || ( claim . recipient as any ) ? . did ; / / e s l i n t - d i s a b l e - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
claim . recipient ? . identifier || ( claim . recipient as any ) ? . did ; / / e s l i n t - d i s a b l e - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
let anyMatch = false ;
if (
this . isFeedFilteredByVisible &&
containsNonHiddenDid ( record )
) {
/ / h a s a v i s i b l e D I D s o i t ' s a k e e p e r
anyMatch = true ;
}
if ( ! anyMatch && this . isFeedFilteredByNearby ) {
/ / c h e c k i f t h e a s s o c i a t e d p r o j e c t h a s a l o c a t i o n i n s i d e u s e r ' s s e a r c h b o x
if ( record . fulfillsPlanHandleId ) {
const plan = await getPlanFromCache (
record . fulfillsPlanHandleId ,
identity ,
this . axios ,
this . apiServer ,
) ;
if ( plan ? . locLat && plan ? . locLon ) {
if ( this . latLongInAnySearchBox ( plan . locLat , plan . locLon ) ) {
anyMatch = true ;
}
}
}
}
if ( this . isAnyFeedFilterOn && ! anyMatch ) {
return null ;
}
return {
return {
... record ,
... record ,
giver : didInfoForContact (
giver : didInfoForContact (
@ -472,9 +531,11 @@ export default class HomeView extends Vue {
this . allMyDids ,
this . allMyDids ,
) ,
) ,
} ;
} ;
} ,
} ) ;
) ;
const allNewFeedData : GiveRecordWithContactInfo [ ] =
this . feedData = this . feedData . concat ( newFeedData ) ;
await Promise . all ( newFeedData ) ;
const filteredFeedData = allNewFeedData . filter ( R . isNotNil ) ;
this . feedData = this . feedData . concat ( filteredFeedData ) ;
this . feedPreviousOldestId =
this . feedPreviousOldestId =
results . data [ results . data . length - 1 ] . jwtId ;
results . data [ results . data . length - 1 ] . jwtId ;
/ / T h e f o l l o w i n g u p d a t e i s o n l y d o n e o n t h e f i r s t l o a d .
/ / T h e f o l l o w i n g u p d a t e i s o n l y d o n e o n t h e f i r s t l o a d .
@ -501,6 +562,10 @@ export default class HomeView extends Vue {
- 1 ,
- 1 ,
) ;
) ;
} ) ;
} ) ;
if ( this . feedData . length === 0 && ! endOfResults ) {
/ / r e p e a t u n t i l t h e r e ' s a t l e a s t s o m e d a t a
this . updateAllFeed ( ) ;
}
this . isFeedLoading = false ;
this . isFeedLoading = false ;
}
}