Compare commits

...

3 Commits

Author SHA1 Message Date
vr-varad
bc0ceacb28
Merge branch 'block-core:main' into feat/imageUpload 2024-04-12 12:44:55 +05:30
SondreB
5d91211754
Add persistence of metrics and sort by popular on home (#134)
- Closes #101
2024-04-09 10:08:36 +02:00
Harshil Jani
17be82375e
Allow tagging(mention) in Notes with username or display name (#137)
Signed-off-by: Harshil-Jani <harshiljani2002@gmail.com>
2024-04-09 10:04:58 +02:00
5 changed files with 31 additions and 6 deletions

View File

@ -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;
})
);

View File

@ -90,6 +90,7 @@ export interface StateDocument {
since: number;
modified?: number;
mediaQueue: MediaItem [];
metrics: { users: any }
}
export interface NostrRelayDocument {

View File

@ -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];

View File

@ -27,7 +27,8 @@ export class StorageService {
state = {
id: 1,
since: timeAgo,
mediaQueue: []
mediaQueue: [],
metrics: { users: {} },
};
}

View File

@ -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' });