Skip to content

Commit

Permalink
feat(proxy): implement NIP-48 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Asone committed Sep 16, 2023
1 parent 971e28d commit edc77ef
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions nostrss-core/src/scheduler/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use feed_rs::model::Entry;
use log::{debug, error};
use nostr_sdk::{prelude::FromSkStr, Client, EventBuilder, Keys, Tag};
use nostr_sdk::{prelude::FromSkStr, Client, EventBuilder, Keys, Kind, Tag};
use std::{collections::HashMap, sync::Arc};
use tokio::sync::{Mutex, MutexGuard};
use tokio_cron_scheduler::Job;
Expand Down Expand Up @@ -155,6 +155,9 @@ impl RssNostrJob {

let mut tags = Self::get_tags(&feed.tags);

// Declare NIP-48.
tags.push(Self::get_nip48(&tags, feed.id.clone()));

let message = match TemplateProcessor::parse(feed.clone(), entry.clone()) {
Ok(message) => message,
Err(e) => {
Expand Down Expand Up @@ -226,7 +229,17 @@ impl RssNostrJob {
}
tags
}
fn get_recommended_relays(recommended_relays_ids: Vec<String>, relays: &[Relay]) -> Vec<Tag> {

fn get_nip48(mut tags: &Vec<Tag>,feed_id: String) -> Tag {
// Declare NIP-48.
// NIP-48 : declares to be a proxy from an external signal (rss,activityPub)
Tag::Proxy {
id: feed_id,
protocol: nostr_sdk::prelude::Protocol::Rss,
}
}

fn get_recommended_relays(recommended_relays_ids: Vec<String>, relays: &[Relay]) -> Vec<Tag> {
let mut relay_tags = Vec::new();
for relay_name in recommended_relays_ids {
let r = relays.iter().find(|relay| relay.name == relay_name);
Expand All @@ -249,6 +262,11 @@ mod tests {

use super::*;

#[test]
fn test_nip_48_signal() {

}

#[test]
fn test_get_tags() {
let relay_ids = ["test".to_string()].to_vec();
Expand Down Expand Up @@ -277,6 +295,17 @@ mod tests {
assert_eq!(tag.as_vec()[1], "wss://nostr.up");
}

#[test]
fn test_nip_48() {

let feed_id = "https://www.test.com";
let mut tags: Vec<Tag> = [].to_vec();
let nip_48 = RssNostrJob::get_nip48(&tags, feed_id.clone().to_string());


assert_eq!(nip_48.kind(),TagKind::Proxy);
}

#[test]
fn test_recommended_relays() {
let feed_tags = ["ad".to_string(), "lorem".to_string(), "ipsum".to_string()].to_vec();
Expand Down

0 comments on commit edc77ef

Please sign in to comment.