@@ -6,6 +6,7 @@ use chrono::{DateTime, TimeZone, Utc};
6
6
use reqwest:: header:: { self , CONTENT_TYPE } ;
7
7
use sea_orm:: { ActiveModelTrait , ColumnTrait , EntityTrait , QueryFilter , Set } ;
8
8
use serde:: { Deserialize , Serialize } ;
9
+ use serde_json:: to_string;
9
10
use time:: OffsetDateTime ;
10
11
use url:: Url ;
11
12
@@ -22,7 +23,7 @@ use crate::{
22
23
} ;
23
24
24
25
use super :: {
25
- objects:: { CategoryType , ContentEntry , ContentFormat , Note , PublicKey } ,
26
+ objects:: { CategoryType , ContentEntry , ContentFormat , Note , PublicKey , UserCollections } ,
26
27
superx:: request_client,
27
28
} ;
28
29
@@ -43,12 +44,12 @@ pub async fn versia_post_from_db(
43
44
. one ( DB . get ( ) . unwrap ( ) )
44
45
. await ?;
45
46
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 ( ) ) ,
52
53
} ;
53
54
//let mut mentions = Vec::new();
54
55
//for obj in post.tag.clone() {
@@ -60,7 +61,7 @@ pub async fn versia_post_from_db(
60
61
ContentEntry :: from_string ( post. content ) ,
61
62
) ;
62
63
let note = super :: objects:: Note {
63
- rtype : super :: objects :: VersiaType :: Note ,
64
+ rtype : " Note" . to_string ( ) ,
64
65
id : uuid:: Uuid :: parse_str ( & post. id ) ?,
65
66
author : author. clone ( ) ,
66
67
uri : url. clone ( ) ,
@@ -69,11 +70,10 @@ pub async fn versia_post_from_db(
69
70
mentions : None ,
70
71
category : Some ( CategoryType :: Microblog ) ,
71
72
device : None ,
72
- visibility : Some ( visibility) ,
73
73
previews : None ,
74
74
replies_to : None ,
75
75
quotes : None ,
76
- group : None ,
76
+ group,
77
77
attachments : None ,
78
78
subject : post. title ,
79
79
is_sensitive : Some ( post. sensitive ) ,
@@ -190,11 +190,9 @@ pub async fn versia_user_from_db(
190
190
content_type_header. unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( )
191
191
} ) ;
192
192
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 ;
196
194
emojis. push ( super :: objects:: CustomEmoji {
197
- name : name . as_str ( ) . to_string ( ) ,
195
+ name,
198
196
url : content_format,
199
197
} ) ;
200
198
}
@@ -205,31 +203,36 @@ pub async fn versia_user_from_db(
205
203
let extensions = super :: objects:: ExtensionSpecs {
206
204
custom_emojis : emojis,
207
205
} ;
206
+ let collections = UserCollections {
207
+ outbox : outbox_url,
208
+ followers : followers_url,
209
+ following : following_url,
210
+ featured : featured_url,
211
+ } ;
208
212
let user = super :: objects:: User {
209
- rtype : super :: objects :: VersiaType :: User ,
213
+ rtype : " User" . to_string ( ) ,
210
214
id : uuid:: Uuid :: parse_str ( & user. id ) ?,
211
215
uri : url. clone ( ) ,
212
216
username : user. username ,
213
217
display_name,
214
218
inbox : inbox_url,
215
- outbox : outbox_url,
216
- followers : followers_url,
217
- following : following_url,
218
- featured : featured_url,
219
219
likes : likes_url,
220
220
dislikes : dislikes_url,
221
221
bio : Some ( bio) ,
222
+ collections,
222
223
avatar,
223
224
header,
224
225
fields : Some ( fields) ,
225
226
indexable : false ,
226
227
created_at : OffsetDateTime :: from_unix_timestamp ( user. created_at . timestamp ( ) ) . unwrap ( ) ,
227
228
public_key : PublicKey {
228
229
actor : url. clone ( ) ,
229
- public_key : "AAAAC3NzaC1lZDI1NTE5AAAAIMxsX+lEWkHZt9NOvn9yYFP0Z++186LY4b97C4mwj/f2"
230
+ key : "AAAAC3NzaC1lZDI1NTE5AAAAIMxsX+lEWkHZt9NOvn9yYFP0Z++186LY4b97C4mwj/f2"
230
231
. to_string ( ) , // dummy key
232
+ algorithm : "ed25519" . to_string ( ) ,
231
233
} ,
232
234
extensions : Some ( extensions) ,
235
+ manually_approves_followers : false ,
233
236
} ;
234
237
Ok ( user)
235
238
}
@@ -418,8 +421,8 @@ pub async fn db_user_from_url(url: Url) -> anyhow::Result<entities::user::Model>
418
421
) ,
419
422
summary : Set ( option_content_format_text ( ls_user. bio ) . await ) ,
420
423
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 ( ) ) ) ,
423
426
ap_json : Set ( Some ( serde_json:: to_string ( & ap_json) . unwrap ( ) ) ) ,
424
427
..Default :: default ( )
425
428
} ;
@@ -464,33 +467,33 @@ pub async fn receive_versia_note(
464
467
mentions. push ( obj. href . clone ( ) ) ;
465
468
}
466
469
let to = match note
467
- . visibility
470
+ . group
468
471
. clone ( )
469
- . unwrap_or ( super :: objects :: VisibilityType :: Public )
472
+ . unwrap_or ( "nothing" . to_string ( ) ) . as_str ( )
470
473
{
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( ) ) ?] ;
473
476
vec. append ( & mut mentions. clone ( ) ) ;
474
477
vec
475
478
}
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( ) ) ?] ;
478
481
vec. append ( & mut mentions. clone ( ) ) ;
479
482
vec
480
483
}
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( ) ) ?] ;
484
486
vec. append ( & mut mentions. clone ( ) ) ;
485
487
vec
486
488
}
489
+ _ => mentions. clone ( ) ,
487
490
} ;
488
491
let cc = match note
489
- . visibility
492
+ . group
490
493
. clone ( )
491
- . unwrap_or ( super :: objects :: VisibilityType :: Public )
494
+ . unwrap_or ( "nothing" . to_string ( ) ) . as_str ( )
492
495
{
493
- super :: objects :: VisibilityType :: Unlisted => Some ( vec ! [ public( ) ] ) ,
496
+ "unlisted" => Some ( vec ! [ public( ) ] ) ,
494
497
_ => None ,
495
498
} ;
496
499
let reply: Option < ObjectId < entities:: post:: Model > > =
@@ -542,14 +545,14 @@ pub async fn receive_versia_note(
542
545
} ;
543
546
544
547
let visibility = match note
545
- . visibility
548
+ . group
546
549
. clone ( )
547
- . unwrap_or ( super :: objects :: VisibilityType :: Public )
550
+ . unwrap_or ( "nothing" . to_string ( ) ) . as_str ( )
548
551
{
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 " ,
553
556
} ;
554
557
if let Some ( obj) = note. replies_to {
555
558
println ! ( "Quoting: {}" , db_post_from_url( obj) . await ?. url) ;
0 commit comments