mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 06:20:42 +00:00
Enable publish of following list
This commit is contained in:
parent
e40b2dc1a5
commit
533805d476
@ -58,12 +58,19 @@ export class CirclesComponent {
|
||||
}
|
||||
|
||||
async deleteCircle(id: string) {
|
||||
const pubKeys = this.getFollowingInCircle(id).map((f) => f.pubkey);
|
||||
|
||||
await this.circlesService.deleteCircle(id);
|
||||
|
||||
for (var i = 0; i < pubKeys.length; i++) {
|
||||
await this.profile.setCircle(pubKeys[i], '');
|
||||
}
|
||||
|
||||
await this.load();
|
||||
}
|
||||
|
||||
countMembers(circle: Circle) {
|
||||
return this.getFollowingInCircle(circle).length;
|
||||
return this.getFollowingInCircle(circle.id).length;
|
||||
}
|
||||
|
||||
subscriptions: Subscription[] = [];
|
||||
@ -127,11 +134,11 @@ export class CirclesComponent {
|
||||
});
|
||||
}
|
||||
|
||||
getFollowingInCircle(circle: Circle) {
|
||||
if (circle.id == null || circle.id == '') {
|
||||
getFollowingInCircle(id: string) {
|
||||
if (id == null || id == '') {
|
||||
return this.following.filter((f) => f.circle == null || f.circle == '');
|
||||
} else {
|
||||
return this.following.filter((f) => f.circle == circle.id);
|
||||
return this.following.filter((f) => f.circle == id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +154,7 @@ export class CirclesComponent {
|
||||
}
|
||||
|
||||
private getPublicKeys(circle: Circle) {
|
||||
const profiles = this.getFollowingInCircle(circle);
|
||||
const profiles = this.getFollowingInCircle(circle.id);
|
||||
const pubkeys = profiles.map((p) => p.pubkey);
|
||||
return pubkeys;
|
||||
}
|
||||
@ -162,7 +169,7 @@ export class CirclesComponent {
|
||||
const circle = this.circles[i];
|
||||
|
||||
if (circle.public) {
|
||||
const profiles = this.getFollowingInCircle(circle);
|
||||
const profiles = this.getFollowingInCircle(circle.id);
|
||||
const pubkeys = profiles.map((p) => p.pubkey);
|
||||
items.push(...pubkeys);
|
||||
}
|
||||
@ -175,9 +182,10 @@ export class CirclesComponent {
|
||||
return this.utilities.getNostrIdentifier(hex);
|
||||
}
|
||||
|
||||
publishFollowList() {
|
||||
async publishFollowList() {
|
||||
const publicPublicKeys = this.getPublicPublicKeys();
|
||||
console.log('publicPublicKeys:', publicPublicKeys);
|
||||
|
||||
await this.feedService.publishContacts(publicPublicKeys);
|
||||
|
||||
this.snackBar.open(`A total of ${publicPublicKeys.length} was added to your public following list`, 'Hide', {
|
||||
duration: 2000,
|
||||
|
@ -17,6 +17,7 @@ export class DataService {
|
||||
cleanProfileInterval = 1000 * 60 * 60; // Every hour
|
||||
//downloadProfileInterval = 1000 * 3; // Every 3 seconds
|
||||
downloadProfileInterval = 500;
|
||||
profileBatchSize = 20;
|
||||
|
||||
constructor(private storage: StorageService, private profileService: ProfileService, private feedService: FeedService, private validator: DataValidation, private eventService: EventService, private relayService: RelayService) {
|
||||
// Whenever the profile service needs to get a profile from the network, this event is triggered.
|
||||
@ -60,7 +61,7 @@ export class DataService {
|
||||
|
||||
// Grab all queued up profiles and ask for them, or should we have a maximum item?
|
||||
// For now, let us grab 10 and process those until next interval.
|
||||
const pubkeys = this.profileQueue.splice(0, 20);
|
||||
const pubkeys = this.profileQueue.splice(0, this.profileBatchSize);
|
||||
this.fetchProfiles(this.relayService.relays[0], pubkeys);
|
||||
}
|
||||
|
||||
|
@ -765,9 +765,9 @@ export class FeedService {
|
||||
return observable;
|
||||
}
|
||||
|
||||
async publishContacts(contacts: Contact[]) {
|
||||
const mappedContacts = contacts.map((c) => {
|
||||
return ['p', c.pubkey];
|
||||
async publishContacts(pubkeys: string[]) {
|
||||
const mappedContacts = pubkeys.map((c) => {
|
||||
return ['p', c];
|
||||
});
|
||||
|
||||
let originalEvent: Event = {
|
||||
@ -811,20 +811,20 @@ export class FeedService {
|
||||
// First we persist our own event like would normally happen if we receive this event.
|
||||
// await this.#persist(event);
|
||||
|
||||
// for (let i = 0; i < this.relayService.relays.length; i++) {
|
||||
// const relay = this.relayService.relays[i];
|
||||
for (let i = 0; i < this.relayService.relays.length; i++) {
|
||||
const relay = this.relayService.relays[i];
|
||||
|
||||
// let pub = relay.publish(event);
|
||||
// pub.on('ok', () => {
|
||||
// console.log(`${relay.url} has accepted our event`);
|
||||
// });
|
||||
// pub.on('seen', () => {
|
||||
// console.log(`we saw the event on ${relay.url}`);
|
||||
// });
|
||||
// pub.on('failed', (reason: any) => {
|
||||
// console.log(`failed to publish to ${relay.url}: ${reason}`);
|
||||
// });
|
||||
// }
|
||||
let pub = relay.publish(event);
|
||||
pub.on('ok', () => {
|
||||
console.log(`${relay.url} has accepted our event`);
|
||||
});
|
||||
pub.on('seen', () => {
|
||||
console.log(`we saw the event on ${relay.url}`);
|
||||
});
|
||||
pub.on('failed', (reason: any) => {
|
||||
console.log(`failed to publish to ${relay.url}: ${reason}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
|
@ -196,6 +196,13 @@ export class ProfileService {
|
||||
return this.#setFollow(pubkey, circle, true, existingProfile);
|
||||
}
|
||||
|
||||
async setCircle(pubkey: string, circle?: string) {
|
||||
return this.updateProfileValue(pubkey, (p) => {
|
||||
p.circle = circle;
|
||||
return p;
|
||||
});
|
||||
}
|
||||
|
||||
async unfollow(pubkey: string) {
|
||||
return this.#setFollow(pubkey, undefined, undefined);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class ProfileActionsComponent {
|
||||
await this.feedService.downloadRecent([this.profile.pubkey]);
|
||||
} else {
|
||||
// If we already follow but just change the circle, do a smaller operation.
|
||||
await this.profileService.follow(this.profile.pubkey, circle);
|
||||
await this.profileService.setCircle(this.profile.pubkey, circle);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user