Skip to content

Commit c72763c

Browse files
feat: initial port to WD4
1 parent 084e85e commit c72763c

File tree

6 files changed

+96
-126
lines changed

6 files changed

+96
-126
lines changed

src/versia/conversion.rs

+43-40
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use chrono::{DateTime, TimeZone, Utc};
66
use reqwest::header::{self, CONTENT_TYPE};
77
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
88
use serde::{Deserialize, Serialize};
9+
use serde_json::to_string;
910
use time::OffsetDateTime;
1011
use url::Url;
1112

@@ -22,7 +23,7 @@ use crate::{
2223
};
2324

2425
use super::{
25-
objects::{CategoryType, ContentEntry, ContentFormat, Note, PublicKey},
26+
objects::{CategoryType, ContentEntry, ContentFormat, Note, PublicKey, UserCollections},
2627
superx::request_client,
2728
};
2829

@@ -43,12 +44,12 @@ pub async fn versia_post_from_db(
4344
.one(DB.get().unwrap())
4445
.await?;
4546
let author = Url::parse(&creator.unwrap().url)?;
46-
let visibility = match post.visibility.as_str() {
47-
"public" => super::objects::VisibilityType::Public,
48-
"followers" => super::objects::VisibilityType::Followers,
49-
"direct" => super::objects::VisibilityType::Direct,
50-
"unlisted" => super::objects::VisibilityType::Unlisted,
51-
_ => super::objects::VisibilityType::Public,
47+
let group = match post.visibility.as_str() {
48+
"public" => Some("public".to_string()),
49+
"followers" => Some("followers".to_string()),
50+
"direct" => None,
51+
//"unlisted" => super::objects::VisibilityType::Unlisted,
52+
_ => Some("public".to_string()),
5253
};
5354
//let mut mentions = Vec::new();
5455
//for obj in post.tag.clone() {
@@ -60,7 +61,7 @@ pub async fn versia_post_from_db(
6061
ContentEntry::from_string(post.content),
6162
);
6263
let note = super::objects::Note {
63-
rtype: super::objects::VersiaType::Note,
64+
rtype: "Note".to_string(),
6465
id: uuid::Uuid::parse_str(&post.id)?,
6566
author: author.clone(),
6667
uri: url.clone(),
@@ -69,11 +70,10 @@ pub async fn versia_post_from_db(
6970
mentions: None,
7071
category: Some(CategoryType::Microblog),
7172
device: None,
72-
visibility: Some(visibility),
7373
previews: None,
7474
replies_to: None,
7575
quotes: None,
76-
group: None,
76+
group,
7777
attachments: None,
7878
subject: post.title,
7979
is_sensitive: Some(post.sensitive),
@@ -190,11 +190,9 @@ pub async fn versia_user_from_db(
190190
content_type_header.unwrap().to_str().unwrap().to_string()
191191
});
192192
content_format.x.insert(media_type, content_entry);
193-
let mut name = tag.name.chars();
194-
name.next();
195-
name.next_back();
193+
let name = tag.name;
196194
emojis.push(super::objects::CustomEmoji {
197-
name: name.as_str().to_string(),
195+
name,
198196
url: content_format,
199197
});
200198
}
@@ -205,31 +203,36 @@ pub async fn versia_user_from_db(
205203
let extensions = super::objects::ExtensionSpecs {
206204
custom_emojis: emojis,
207205
};
206+
let collections = UserCollections {
207+
outbox: outbox_url,
208+
followers: followers_url,
209+
following: following_url,
210+
featured: featured_url,
211+
};
208212
let user = super::objects::User {
209-
rtype: super::objects::VersiaType::User,
213+
rtype: "User".to_string(),
210214
id: uuid::Uuid::parse_str(&user.id)?,
211215
uri: url.clone(),
212216
username: user.username,
213217
display_name,
214218
inbox: inbox_url,
215-
outbox: outbox_url,
216-
followers: followers_url,
217-
following: following_url,
218-
featured: featured_url,
219219
likes: likes_url,
220220
dislikes: dislikes_url,
221221
bio: Some(bio),
222+
collections,
222223
avatar,
223224
header,
224225
fields: Some(fields),
225226
indexable: false,
226227
created_at: OffsetDateTime::from_unix_timestamp(user.created_at.timestamp()).unwrap(),
227228
public_key: PublicKey {
228229
actor: url.clone(),
229-
public_key: "AAAAC3NzaC1lZDI1NTE5AAAAIMxsX+lEWkHZt9NOvn9yYFP0Z++186LY4b97C4mwj/f2"
230+
key: "AAAAC3NzaC1lZDI1NTE5AAAAIMxsX+lEWkHZt9NOvn9yYFP0Z++186LY4b97C4mwj/f2"
230231
.to_string(), // dummy key
232+
algorithm: "ed25519".to_string(),
231233
},
232234
extensions: Some(extensions),
235+
manually_approves_followers: false,
233236
};
234237
Ok(user)
235238
}
@@ -418,8 +421,8 @@ pub async fn db_user_from_url(url: Url) -> anyhow::Result<entities::user::Model>
418421
),
419422
summary: Set(option_content_format_text(ls_user.bio).await),
420423
updated_at: Set(Some(Utc::now())),
421-
followers: Set(Some(ls_user.followers.to_string())),
422-
following: Set(Some(ls_user.following.to_string())),
424+
followers: Set(Some(ls_user.collections.followers.to_string())),
425+
following: Set(Some(ls_user.collections.following.to_string())),
423426
ap_json: Set(Some(serde_json::to_string(&ap_json).unwrap())),
424427
..Default::default()
425428
};
@@ -464,33 +467,33 @@ pub async fn receive_versia_note(
464467
mentions.push(obj.href.clone());
465468
}
466469
let to = match note
467-
.visibility
470+
.group
468471
.clone()
469-
.unwrap_or(super::objects::VisibilityType::Public)
472+
.unwrap_or("nothing".to_string()).as_str()
470473
{
471-
super::objects::VisibilityType::Public => {
472-
let mut vec = vec![public(), Url::parse(&user.followers.to_string().as_str())?];
474+
"public" => {
475+
let mut vec = vec![public(), Url::parse(&user.collections.followers.to_string().as_str())?];
473476
vec.append(&mut mentions.clone());
474477
vec
475478
}
476-
super::objects::VisibilityType::Followers => {
477-
let mut vec = vec![Url::parse(&user.followers.to_string().as_str())?];
479+
"unlisted" => {
480+
let mut vec = vec![Url::parse(&user.collections.followers.to_string().as_str())?];
478481
vec.append(&mut mentions.clone());
479482
vec
480483
}
481-
super::objects::VisibilityType::Direct => mentions.clone(),
482-
super::objects::VisibilityType::Unlisted => {
483-
let mut vec = vec![Url::parse(&user.followers.to_string().as_str())?];
484+
"followers" => {
485+
let mut vec = vec![Url::parse(&user.collections.followers.to_string().as_str())?];
484486
vec.append(&mut mentions.clone());
485487
vec
486488
}
489+
_ => mentions.clone(),
487490
};
488491
let cc = match note
489-
.visibility
492+
.group
490493
.clone()
491-
.unwrap_or(super::objects::VisibilityType::Public)
494+
.unwrap_or("nothing".to_string()).as_str()
492495
{
493-
super::objects::VisibilityType::Unlisted => Some(vec![public()]),
496+
"unlisted" => Some(vec![public()]),
494497
_ => None,
495498
};
496499
let reply: Option<ObjectId<entities::post::Model>> =
@@ -542,14 +545,14 @@ pub async fn receive_versia_note(
542545
};
543546

544547
let visibility = match note
545-
.visibility
548+
.group
546549
.clone()
547-
.unwrap_or(super::objects::VisibilityType::Public)
550+
.unwrap_or("nothing".to_string()).as_str()
548551
{
549-
super::objects::VisibilityType::Public => "public",
550-
super::objects::VisibilityType::Followers => "followers",
551-
super::objects::VisibilityType::Direct => "direct",
552-
super::objects::VisibilityType::Unlisted => "unlisted",
552+
"public" => "public",
553+
"followers" => "followers",
554+
"unlisted" => "unlisted",
555+
_ => "direct",
553556
};
554557
if let Some(obj) = note.replies_to {
555558
println!("Quoting: {}", db_post_from_url(obj).await?.url);

src/versia/funcs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn send_follow_accept_to_versia(model: follow_relation::Model) -> anyh
3737
let versia_followee = versia_user_from_db(followee_model).await?;
3838

3939
let entity = FollowResult {
40-
rtype: super::objects::VersiaType::FollowAccept,
40+
rtype: "FollowAccept".to_string(),
4141
id,
4242
uri,
4343
created_at: OffsetDateTime::now_utc(),

src/versia/inbox.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use url::Url;
2121
use super::{
2222
conversion::versia_user_from_db,
2323
http::{versia_url_to_user, versia_url_to_user_and_model},
24-
objects::VersiaType,
2524
};
2625

2726
pub async fn inbox_entry(json: &str) -> Result<()> {
@@ -35,9 +34,6 @@ pub async fn inbox_entry(json: &str) -> Result<()> {
3534
Some("Note") => {
3635
let note: super::objects::Note = serde_json::from_str(json)?;
3736
}
38-
Some("Patch") => {
39-
let patch: super::objects::Patch = serde_json::from_str(json)?;
40-
}
4137
Some("Follow") => {
4238
let follow_req: super::objects::Follow = serde_json::from_str(json)?;
4339
follow_request(follow_req).await?;
@@ -48,6 +44,9 @@ pub async fn inbox_entry(json: &str) -> Result<()> {
4844
Some("FollowReject") => {
4945
let follow_rej: super::objects::FollowResult = serde_json::from_str(json)?;
5046
}
47+
Some("Unfollow") => {
48+
let unfollow: super::objects::Unfollow = serde_json::from_str(json)?;
49+
}
5150
// Add more cases for other types as needed
5251
_ => {
5352
return Err(anyhow::anyhow!(

0 commit comments

Comments
 (0)