mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-23 12:18:05 +00:00
Compare commits
4 commits
4ae93192f4
...
ffa059c49b
Author | SHA1 | Date | |
---|---|---|---|
ffa059c49b | |||
d3737d4453 | |||
d97c956dd5 | |||
b277ea97a9 |
22
crates/apub/assets/discourse/objects/group.json
Normal file
22
crates/apub/assets/discourse/objects/group.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146",
|
||||
"type": "Group",
|
||||
"updated": "2024-04-05T12:49:51Z",
|
||||
"url": "https://socialhub.activitypub.rocks/c/meeting/threadiverse-wg/88",
|
||||
"name": "Threadiverse Working Group (SocialHub)",
|
||||
"inbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/inbox",
|
||||
"outbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/outbox",
|
||||
"followers": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/followers",
|
||||
"preferredUsername": "threadiverse-wg",
|
||||
"publicKey": {
|
||||
"id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146#main-key",
|
||||
"owner": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApJi4iAcW6bPiHVCxT9p0\n8DVnrDDO4QtLNy7bpRFdMFifmmmXprsuAi9D2MSwbhH49V54HtIkxBpKd2IR/UD8\nmhMDY4CNI9FHpjqLw0wtkzxcqF9urSqhn0/vWX+9oxyhIgQS5KMiIkYDMJiAc691\niEcZ8LCran23xIGl6Dk54Nr3TqTMLcjDhzQYUJbxMrLq5/knWqOKG3IF5OxK+9ZZ\n1wxDF872eJTxJLkmpag+WYNtHzvB2SGTp8j5IF1/pZ9J1c3cpYfaeolTch/B/GQn\najCB4l27U52rIIObxJqFXSY8wHyd0aAmNmxzPZ7cduRlBDhmI40cAmnCV1YQPvpk\nDwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://socialhub.activitypub.rocks/uploads/default/original/1X/8faac84234dc73d074dadaa2bcf24dc746b8647f.png"
|
||||
},
|
||||
"@context": "https://www.w3.org/ns/activitystreams"
|
||||
}
|
13
crates/apub/assets/discourse/objects/page.json
Normal file
13
crates/apub/assets/discourse/objects/page.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"id": "https://socialhub.activitypub.rocks/ap/object/1899f65c062200daec50a4c89ed76dc9",
|
||||
"type": "Note",
|
||||
"audience": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146",
|
||||
"published": "2024-04-13T14:36:19Z",
|
||||
"updated": "2024-04-13T14:36:19Z",
|
||||
"url": "https://socialhub.activitypub.rocks/t/our-next-meeting/4079/1",
|
||||
"attributedTo": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1",
|
||||
"name": "Our next meeting",
|
||||
"context": "https://socialhub.activitypub.rocks/ap/collection/8850f6e85b57c490da915a5dfbbd5045",
|
||||
"content": "<h3>Last Meeting</h3>\n<h4>Recording</h4>\n<a href=\"https://us06web.zoom.us/rec/share/4hGBTvgXJPlu8UkjkkxVARypNg5DH0eeaKlIBv71D4G3lokYyrCrg7cqBCJmL109.FsHYTZDlVvZXrgcn?startTime=1712254114000\">https://us06web.zoom.us/rec/share/4hGBTvgXJPlu8UkjkkxVARypNg5DH0eeaKlIBv71D4G3lokYyrCrg7cqBCJmL109.FsHYTZDlVvZXrgcn?startTime=1712254114000</a>\nPasscode: z+1*4pUB\n<h4>Minutes</h4>\nTo refresh your memory, you can read the minutes of last week's meeting <a href=\"https://community.nodebb.org/topic/17949/minutes…",
|
||||
"@context": "https://www.w3.org/ns/activitystreams"
|
||||
}
|
23
crates/apub/assets/discourse/objects/person.json
Normal file
23
crates/apub/assets/discourse/objects/person.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"id": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1",
|
||||
"type": "Person",
|
||||
"updated": "2024-01-15T12:27:03Z",
|
||||
"url": "https://socialhub.activitypub.rocks/u/angus",
|
||||
"name": "Angus McLeod",
|
||||
"inbox": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1/inbox",
|
||||
"outbox": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1/outbox",
|
||||
"sharedInbox": "https://socialhub.activitypub.rocks/ap/users/inbox",
|
||||
"followers": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1/followers",
|
||||
"preferredUsername": "angus",
|
||||
"publicKey": {
|
||||
"id": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1#main-key",
|
||||
"owner": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3RpuFDuwXZzOeHO5fO2O\nHmP7Flc5JDXJ8OOEJYq5T/dzUKqREOF1ZT0WMww8/E3P6w+gfFsjzThraJb8nHuW\nP6798SUD35CWBclfhw9DapjVn99JyFcAWcH3b9fr6LYshc4y1BoeJagk1kcro2Dc\n+pX0vVXgNjwWnGfyucAgGIUWrNUjcvIvXmyVCBSQfXG3nCALV1JbI4KSgf/5KyBn\nza/QefaetxYiFV8wAisPKLsz3XQAaITsQmbSi+8gmwXt/9U808PK1KphCiClDOWg\noi0HPzJn0rn+mwFCfgNWenvribfeG40AHLG33OkWKvslufjifdWDCOcBYYzyCEV6\n+wIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://socialhub.activitypub.rocks/user_avatar/socialhub.activitypub.rocks/angus/96/2295_2.png"
|
||||
},
|
||||
"@context": "https://www.w3.org/ns/activitystreams"
|
||||
}
|
|
@ -190,4 +190,12 @@ mod tests {
|
|||
test_json::<Person>("assets/mobilizon/objects/person.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object_discourse() -> LemmyResult<()> {
|
||||
test_json::<Group>("assets/discourse/objects/group.json")?;
|
||||
test_json::<Page>("assets/discourse/objects/page.json")?;
|
||||
test_json::<Person>("assets/discourse/objects/person.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ pub struct Page {
|
|||
pub(crate) kind: PageType,
|
||||
pub(crate) id: ObjectId<ApubPost>,
|
||||
pub(crate) attributed_to: AttributedTo,
|
||||
#[serde(deserialize_with = "deserialize_one_or_many")]
|
||||
#[serde(deserialize_with = "deserialize_one_or_many", default)]
|
||||
pub(crate) to: Vec<Url>,
|
||||
// If there is inReplyTo field this is actually a comment and must not be parsed
|
||||
#[serde(deserialize_with = "deserialize_not_present", default)]
|
||||
|
|
|
@ -43,20 +43,13 @@ impl LocalUserLanguage {
|
|||
};
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
||||
conn
|
||||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
let langs = local_user_language
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.order(language_id)
|
||||
.select(language_id)
|
||||
.get_results(conn)
|
||||
.await?;
|
||||
convert_read_languages(conn, langs).await
|
||||
}) as _
|
||||
})
|
||||
.await
|
||||
let langs = local_user_language
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.order(language_id)
|
||||
.select(language_id)
|
||||
.get_results(conn)
|
||||
.await?;
|
||||
convert_read_languages(conn, langs).await
|
||||
}
|
||||
|
||||
/// Update the user's languages.
|
||||
|
@ -90,24 +83,33 @@ impl LocalUserLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::local_user_language::dsl::{local_user_id, local_user_language};
|
||||
// Clear the current user languages
|
||||
delete(local_user_language.filter(local_user_id.eq(for_local_user_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
use crate::schema::local_user_language::dsl::{
|
||||
language_id,
|
||||
local_user_id,
|
||||
local_user_language,
|
||||
};
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(local_user_language)
|
||||
.filter(local_user_id.eq(for_local_user_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let forms = lang_ids
|
||||
.into_iter()
|
||||
.map(|l| LocalUserLanguageForm {
|
||||
.iter()
|
||||
.map(|&l| LocalUserLanguageForm {
|
||||
local_user_id: for_local_user_id,
|
||||
language_id: l,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
insert_into(local_user_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(local_user_language)
|
||||
.values(forms)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
.on_conflict((language_id, local_user_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
Ok(())
|
||||
}) as _
|
||||
})
|
||||
|
@ -159,25 +161,30 @@ impl SiteLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::site_language::dsl::{site_id, site_language};
|
||||
use crate::schema::site_language::dsl::{language_id, site_id, site_language};
|
||||
|
||||
// Clear the current languages
|
||||
delete(site_language.filter(site_id.eq(for_site_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(site_language)
|
||||
.filter(site_id.eq(for_site_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let forms = lang_ids
|
||||
.into_iter()
|
||||
.map(|l| SiteLanguageForm {
|
||||
.iter()
|
||||
.map(|&l| SiteLanguageForm {
|
||||
site_id: for_site_id,
|
||||
language_id: l,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
insert_into(site_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(site_language)
|
||||
.values(forms)
|
||||
.get_result::<Self>(conn)
|
||||
.await?;
|
||||
.on_conflict((site_id, language_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
|
||||
CommunityLanguage::limit_languages(conn, instance_id).await?;
|
||||
|
||||
|
@ -278,8 +285,8 @@ impl CommunityLanguage {
|
|||
}
|
||||
|
||||
let form = lang_ids
|
||||
.into_iter()
|
||||
.map(|language_id| CommunityLanguageForm {
|
||||
.iter()
|
||||
.map(|&language_id| CommunityLanguageForm {
|
||||
community_id: for_community_id,
|
||||
language_id,
|
||||
})
|
||||
|
@ -289,25 +296,25 @@ impl CommunityLanguage {
|
|||
.build_transaction()
|
||||
.run(|conn| {
|
||||
Box::pin(async move {
|
||||
use crate::schema::community_language::dsl::{community_id, community_language};
|
||||
use diesel::result::DatabaseErrorKind::UniqueViolation;
|
||||
// Clear the current languages
|
||||
delete(community_language.filter(community_id.eq(for_community_id)))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
use crate::schema::community_language::dsl::{
|
||||
community_id,
|
||||
community_language,
|
||||
language_id,
|
||||
};
|
||||
// Delete old languages, not including new languages
|
||||
let delete_old = delete(community_language)
|
||||
.filter(community_id.eq(for_community_id))
|
||||
.filter(language_id.ne_all(&lang_ids))
|
||||
.execute(conn);
|
||||
|
||||
let insert_res = insert_into(community_language)
|
||||
// Insert new languages
|
||||
let insert_new = insert_into(community_language)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await;
|
||||
.on_conflict((community_id, language_id))
|
||||
.do_nothing()
|
||||
.execute(conn);
|
||||
|
||||
if let Err(Error::DatabaseError(UniqueViolation, _info)) = insert_res {
|
||||
// race condition: this function was probably called simultaneously from another caller. ignore error
|
||||
// tracing::warn!("unique error: {_info:#?}");
|
||||
// _info.constraint_name() should be = "community_language_community_id_language_id_key"
|
||||
return Ok(());
|
||||
}
|
||||
insert_res?;
|
||||
tokio::try_join!(delete_old, insert_new)?;
|
||||
|
||||
Ok(())
|
||||
}) as _
|
||||
|
|
Loading…
Reference in a new issue