Skip to content

Commit

Permalink
Merge pull request #66 from Asone/60-implement-proxy-tags
Browse files Browse the repository at this point in the history
feat(proxy): implement NIP-48 tag
  • Loading branch information
Asone authored Sep 16, 2023
2 parents bc435c0 + 661ead6 commit 68d31d8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion 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, entry.id.clone()));

let message = match TemplateProcessor::parse(feed.clone(), entry.clone()) {
Ok(message) => message,
Err(e) => {
Expand Down Expand Up @@ -226,6 +229,16 @@ impl RssNostrJob {
}
tags
}

fn get_nip48(mut tags: &Vec<Tag>, guid: String) -> Tag {
// Declare NIP-48.
// NIP-48 : declares to be a proxy from an external signal (rss,activityPub)
Tag::Proxy {
id: guid,
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 {
Expand All @@ -249,6 +262,9 @@ 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 +293,15 @@ mod tests {
assert_eq!(tag.as_vec()[1], "wss://nostr.up");
}

#[test]
fn test_nip_48() {
let guid = "https://www.test.com";
let mut tags: Vec<Tag> = [].to_vec();
let nip_48 = RssNostrJob::get_nip48(&tags, guid.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 68d31d8

Please sign in to comment.