+11
src/lib/AccountComponent.svelte
+11
src/lib/AccountComponent.svelte
···
1
1
<script lang="ts">
2
2
import type { AccountMetadata } from "./pdsfetch";
3
+
import { getTealNowListeningTo } from "./pdsfetch";
3
4
const { account }: { account: AccountMetadata } = $props();
4
5
import { Config } from "../../config";
6
+
7
+
let nowListeningTo: string | null = $state(null);
8
+
9
+
$effect(() => {
10
+
if(account.did){
11
+
getTealNowListeningTo(account.did).then(res => {
12
+
nowListeningTo = res;
13
+
});
14
+
}
15
+
})
5
16
</script>
6
17
7
18
<a id="link" href="{Config.FRONTEND_URL}/profile/{account.did}">
+34
-2
src/lib/pdsfetch.ts
+34
-2
src/lib/pdsfetch.ts
···
14
14
} from "@atcute/identity-resolver";
15
15
import { Config } from "../../config";
16
16
import { Mutex } from "mutex-ts"
17
+
import moment from "moment";
17
18
import type {DidDocument} from "@atcute/client/utils/did";
18
19
// import { ComAtprotoRepoListRecords.Record } from "@atcute/client/lexicons";
19
20
// import { AppBskyFeedPost } from "@atcute/client/lexicons";
···
137
138
limit: 1000,
138
139
},
139
140
});
140
-
return data.repos.filter(x => x.active).map((repo: any) => repo.did) as At.Did[];
141
+
return data.repos.filter(x => x.active).map((repo: any) => repo.did).reverse() as At.Did[];
141
142
};
142
143
const getAccountMetadata = async (
143
144
did: `did:${string}:${string}`,
···
375
376
}
376
377
};
377
378
379
+
type artists = {
380
+
artistName: string;
381
+
}
382
+
383
+
type dietTeal = {
384
+
artists: artists[];
385
+
trackName: string;
386
+
playedTime: number;
387
+
}
388
+
389
+
const getTealNowListeningTo = async (did: At.Did) => {
390
+
const { data } = await rpc.get("com.atproto.repo.listRecords", {
391
+
params: {
392
+
repo: did as At.Identifier,
393
+
collection: "fm.teal.alpha.feed.play",
394
+
limit: 1
395
+
},
396
+
});
397
+
if (data.records.length > 0) {
398
+
const record = data.records[0] as ComAtprotoRepoListRecords.Record;
399
+
const value = record.value as dietTeal;
400
+
const artists = value.artists.map((artist) => artist.artistName).join(", ");
401
+
const timeStamp = moment(value.playedTime).isBefore(moment().subtract(1, "month"))
402
+
? moment(value.playedTime).format("MMM D, YYYY")
403
+
: moment(value.playedTime).fromNow()
404
+
return `Listening to ${value.trackName} by ${artists} ${timeStamp}`;
405
+
}
406
+
console.log(data);
407
+
return null;
408
+
}
409
+
378
410
type CacheEntry<T> = {
379
411
data: T;
380
412
expire_timestamp: number;
···
416
448
}
417
449
}
418
450
419
-
export { getAllMetadataFromPds, getNextPosts, Post, blueskyHandleFromDid };
451
+
export { getAllMetadataFromPds, getNextPosts, Post, blueskyHandleFromDid, getTealNowListeningTo };
420
452
export type { AccountMetadata };