mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 22:40:44 +00:00
Merge branch 'block-core:main' into feat/imageUpload
This commit is contained in:
commit
bc0ceacb28
@ -17,6 +17,7 @@ import { DataService } from '../services/data';
|
||||
import { StorageService } from '../services/storage';
|
||||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import { UIService } from '../services/ui';
|
||||
import { MetricService } from '../services/metric-service';
|
||||
|
||||
interface DefaultProfile {
|
||||
pubkey: string;
|
||||
@ -118,7 +119,8 @@ export class HomeComponent {
|
||||
private router: Router,
|
||||
private breakpointObserver: BreakpointObserver,
|
||||
private ngZone: NgZone,
|
||||
private formBuilder: UntypedFormBuilder
|
||||
private formBuilder: UntypedFormBuilder,
|
||||
private metricService: MetricService
|
||||
) {
|
||||
console.log('HOME constructor!!'); // Hm.. called twice, why?
|
||||
}
|
||||
@ -257,7 +259,11 @@ export class HomeComponent {
|
||||
this.profileService.following$.subscribe((profiles) => {
|
||||
// this.profileCount = Math.floor(window.innerWidth / this.profileThumbnailWidth);
|
||||
this.profileCount = 75;
|
||||
this.profiles = profiles.slice(0, this.profileCount);
|
||||
let slized = profiles.slice(0, this.profileCount);
|
||||
let sorted = slized.sort((a, b) => {
|
||||
return this.metricService.get(a.pubkey) < this.metricService.get(b.pubkey) ? 1 : -1;
|
||||
});
|
||||
this.profiles = sorted;
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -90,6 +90,7 @@ export interface StateDocument {
|
||||
since: number;
|
||||
modified?: number;
|
||||
mediaQueue: MediaItem [];
|
||||
metrics: { users: any }
|
||||
}
|
||||
|
||||
export interface NostrRelayDocument {
|
||||
|
@ -1,12 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MetricService {
|
||||
users: {
|
||||
[pubKey: string]: number;
|
||||
} = {};
|
||||
constructor(private storage: StorageService) {}
|
||||
|
||||
get users(): { [pubKey: string]: number } {
|
||||
if (!this.storage.state?.metrics?.users) {
|
||||
this.storage.state.metrics = { users: {} };
|
||||
}
|
||||
|
||||
return this.storage.state.metrics.users;
|
||||
}
|
||||
|
||||
increase(value: number, pubKey: string) {
|
||||
let existingMetric = this.users[pubKey];
|
||||
|
@ -27,7 +27,8 @@ export class StorageService {
|
||||
state = {
|
||||
id: 1,
|
||||
since: timeAgo,
|
||||
mediaQueue: []
|
||||
mediaQueue: [],
|
||||
metrics: { users: {} },
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -298,6 +298,16 @@ export class ContentComponent {
|
||||
} else {
|
||||
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: token.substring(6), token: decoded.type });
|
||||
}
|
||||
} else if (token.startsWith('@')) {
|
||||
const username = token.substring(1);
|
||||
const npub = this.profileService.following.find((follower) => follower.name === username)?.npub;
|
||||
if (npub) {
|
||||
const decoded = nip19.decode(npub);
|
||||
const val = decoded.data as any;
|
||||
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: val, token: decoded.type });
|
||||
} else {
|
||||
res[i] += token;
|
||||
}
|
||||
} else if (token.startsWith('http://') || token.startsWith('https://')) {
|
||||
if (this.isImage(token)) {
|
||||
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: token, token: 'image' });
|
||||
|
Loading…
Reference in New Issue
Block a user