@ -247,11 +247,17 @@
< fa icon = "spinner" class = "fa-spin-pulse" > < / fa > Loading & hellip ;
< / p >
< / 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 >
< / section >
< / template >
< script lang = "ts" >
import * as R from "ramda" ;
import { UAParser } from "ua-parser-js" ;
import { IIdentifier } from "@veramo/core" ;
import { Component , Vue } from "vue-facing-decorator" ;
@ -267,17 +273,24 @@ import { NotificationIface } from "@/constants/app";
import { db , accountsDB } from "@/db/index" ;
import { Account } from "@/db/tables/accounts" ;
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 {
contactForDid ,
containsNonHiddenDid ,
didInfoForContact ,
getPlanFromCache ,
GiverInputInfo ,
GiveServer Record ,
GiveSummary Record ,
} from "@/libs/endorserServer" ;
import { generateSaveAndActivateIdentity } from "@/libs/util" ;
interface GiveRecordWithContactInfo extends GiveServer Record {
interface GiveRecordWithContactInfo extends GiveSummary Record {
giver : {
displayName : string ;
known : boolean ;
@ -310,11 +323,16 @@ export default class HomeView extends Vue {
feedData : GiveRecordWithContactInfo [ ] = [ ] ;
feedPreviousOldestId ? : string ;
feedLastViewedClaimId ? : string ;
isAnyFeedFilterOn : boolean ;
isCreatingIdentifier = false ;
isFeedFilteredByContacts = false ;
isFeedFilteredByVisible = false ;
isFeedFilteredByNearby = false ;
isFeedLoading = true ;
isRegistered = false ;
searchBoxes : Array < {
name : string ;
bbox : BoundingBox ;
} > = [ ] ;
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
@ -349,11 +367,14 @@ export default class HomeView extends Vue {
this . activeDid = settings ? . activeDid || "" ;
this . allContacts = await db . contacts . toArray ( ) ;
this . feedLastViewedClaimId = settings ? . lastViewedClaimId ;
this . isFeedFilteredByContacts = ! ! settings ? . filterFeedContacts ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedNearby ;
this . isFeedFilteredByVisible = ! ! settings ? . filterFeedByVisible ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedBy Nearby ;
this . isRegistered = ! ! settings ? . isRegistered ;
this . searchBoxes = settings ? . searchBoxes || [ ] ;
this . showShortcutBvc = ! ! settings ? . showShortcutBvc ;
this . isAnyFeedFilterOn = isAnyFeedFilterOn ( settings ) ;
if ( this . allMyDids . length === 0 ) {
this . isCreatingIdentifier = true ;
this . activeDid = await generateSaveAndActivateIdentity ( ) ;
@ -383,7 +404,7 @@ export default class HomeView extends Vue {
}
resultsAreFiltered ( ) {
return this . isFeedFilteredByContacts || this . isFeedFilteredByNearby ;
return this . isFeedFilteredByVisible || this . isFeedFilteredByNearby ;
}
notificationsSupported ( ) {
@ -395,21 +416,15 @@ export default class HomeView extends Vue {
"Content-Type" : "application/json" ,
} ;
const identity = await this . getIdentity ( this . activeDid ) ;
if ( this . activeDid ) {
await accountsDB . open ( ) ;
const allAccounts = await accountsDB . accounts . toArray ( ) ;
const account = allAccounts . find (
( acc ) => acc . did === this . activeDid ,
) as Account ;
const identity = JSON . parse ( account ? . identity || "null" ) ;
if ( ! identity ) {
if ( identity ) {
headers [ "Authorization" ] = "Bearer " + ( await accessToken ( identity ) ) ;
} else {
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." ,
) ;
}
headers [ "Authorization" ] = "Bearer " + ( await accessToken ( identity ) ) ;
} 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
}
@ -420,8 +435,9 @@ export default class HomeView extends Vue {
async reloadFeedOnChange ( ) {
await db . open ( ) ;
const settings = ( await db . settings . get ( MASTER_SETTINGS_KEY ) ) as Settings ;
this . isFeedFilteredByContacts = ! ! settings ? . filterFeedContacts ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedNearby ;
this . isFeedFilteredByVisible = ! ! settings ? . filterFeedByVisible ;
this . isFeedFilteredByNearby = ! ! settings ? . filterFeedByNearby ;
this . isAnyFeedFilterOn = isAnyFeedFilterOn ( settings ) ;
this . feedData = [ ] ;
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 ( ) {
this . isFeedLoading = true ;
let endOfResults = true ;
await this . retrieveGives ( this . apiServer , this . feedPreviousOldestId )
. then ( async ( results ) => {
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
const newFeedData : GiveRecordWithContactInfo = results . data . map (
( record : GiveServerRecord ) => {
const identity = await this . getIdentity ( this . activeDid ) ;
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
/ / 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
@ -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
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
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 {
... record ,
giver : didInfoForContact (
@ -472,9 +531,11 @@ export default class HomeView extends Vue {
this . allMyDids ,
) ,
} ;
} ,
) ;
this . feedData = this . feedData . concat ( newFeedData ) ;
} ) ;
const allNewFeedData : GiveRecordWithContactInfo [ ] =
await Promise . all ( newFeedData ) ;
const filteredFeedData = allNewFeedData . filter ( R . isNotNil ) ;
this . feedData = this . feedData . concat ( filteredFeedData ) ;
this . feedPreviousOldestId =
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 .
@ -501,6 +562,10 @@ export default class HomeView extends Vue {
- 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 ;
}