Add creator_id to edit

This commit is contained in:
Felix Ableitner 2023-12-18 16:40:27 +01:00
parent e568f109f9
commit 8ed35141b7
17 changed files with 131 additions and 194 deletions

260
Cargo.lock generated
View File

@ -4,8 +4,9 @@ version = 3
[[package]]
name = "activitypub_federation"
version = "0.5.0-beta.5"
source = "git+https://github.com/LemmyNet/activitypub-federation-rust.git?branch=diesel-feature#9ffdadfc8df6719542861466234a7dac2f9707c9"
version = "0.5.0-beta.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0aafb8ad437a019bac2e11d47fad6131974dace1855640a09d0e71d26571c1"
dependencies = [
"activitystreams-kinds",
"async-trait",
@ -19,7 +20,8 @@ dependencies = [
"enum_delegate",
"futures",
"futures-core",
"http",
"http 0.2.11",
"http-body-util",
"http-signature-normalization",
"http-signature-normalization-reqwest",
"httpdate",
@ -97,26 +99,6 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "async-io"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af"
dependencies = [
"async-lock",
"autocfg",
"cfg-if",
"concurrent-queue",
"futures-lite",
"log",
"parking",
"polling",
"rustix 0.37.27",
"slab",
"socket2 0.4.10",
"waker-fn",
]
[[package]]
name = "async-lock"
version = "2.8.0"
@ -155,8 +137,8 @@ dependencies = [
"bytes",
"futures-util",
"headers",
"http",
"http-body",
"http 0.2.11",
"http-body 0.4.5",
"hyper",
"itoa",
"matchit",
@ -185,8 +167,8 @@ dependencies = [
"async-trait",
"bytes",
"futures-util",
"http",
"http-body",
"http 0.2.11",
"http-body 0.4.5",
"mime",
"rustversion",
"tower-layer",
@ -371,15 +353,6 @@ dependencies = [
"inout",
]
[[package]]
name = "concurrent-queue"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -690,15 +663,6 @@ version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "fastrand"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
dependencies = [
"instant",
]
[[package]]
name = "fastrand"
version = "2.0.1"
@ -761,9 +725,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
@ -816,21 +780,6 @@ version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-lite"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce"
dependencies = [
"fastrand 1.9.0",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite",
"waker-fn",
]
[[package]]
name = "futures-macro"
version = "0.3.29"
@ -918,7 +867,7 @@ dependencies = [
"futures-core",
"futures-sink",
"futures-util",
"http",
"http 0.2.11",
"indexmap 1.9.3",
"slab",
"tokio",
@ -947,7 +896,7 @@ dependencies = [
"base64 0.21.5",
"bytes",
"headers-core",
"http",
"http 0.2.11",
"httpdate",
"mime",
"sha1",
@ -959,7 +908,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429"
dependencies = [
"http",
"http 0.2.11",
]
[[package]]
@ -991,6 +940,17 @@ dependencies = [
"itoa",
]
[[package]]
name = "http"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
dependencies = [
"bytes",
"fnv",
"itoa",
]
[[package]]
name = "http-body"
version = "0.4.5"
@ -998,7 +958,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [
"bytes",
"http",
"http 0.2.11",
"pin-project-lite",
]
[[package]]
name = "http-body"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643"
dependencies = [
"bytes",
"http 1.0.0",
]
[[package]]
name = "http-body-util"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
dependencies = [
"bytes",
"futures-util",
"http 1.0.0",
"http-body 1.0.0",
"pin-project-lite",
]
@ -1013,10 +996,11 @@ dependencies = [
[[package]]
name = "http-signature-normalization-reqwest"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c382c69a07b21accae86298d520579403af6479b1cd1c389e3ee11f01d48627"
checksum = "10cfb84663420ec12c4422820bfdf5e8e5e57467892587f43ac432e73ebce880"
dependencies = [
"async-trait",
"base64 0.13.1",
"http-signature-normalization",
"httpdate",
@ -1050,8 +1034,8 @@ dependencies = [
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"http 0.2.11",
"http-body 0.4.5",
"httparse",
"httpdate",
"itoa",
@ -1107,9 +1091,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
@ -1144,26 +1128,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "io-lifetimes"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi",
"libc",
"windows-sys",
]
[[package]]
name = "ipnet"
version = "2.9.0"
@ -1172,9 +1136,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]]
name = "itertools"
version = "0.10.5"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]
@ -1221,12 +1185,6 @@ version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "linux-raw-sys"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
@ -1338,12 +1296,12 @@ dependencies = [
[[package]]
name = "moka"
version = "0.11.3"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa6e72583bf6830c956235bff0d5afec8cf2952f579ebad18ae7821a917d950f"
checksum = "d8017ec3548ffe7d4cef7ac0e12b044c01164a74c0f3119420faeaf13490ad8b"
dependencies = [
"async-io",
"async-lock",
"async-trait",
"crossbeam-channel",
"crossbeam-epoch",
"crossbeam-utils",
@ -1352,7 +1310,6 @@ dependencies = [
"parking_lot",
"quanta",
"rustc_version",
"scheduled-thread-pool",
"skeptic",
"smallvec",
"tagptr",
@ -1440,15 +1397,15 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.18.0"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "openssl"
version = "0.10.59"
version = "0.10.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33"
checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45"
dependencies = [
"bitflags 2.4.1",
"cfg-if",
@ -1478,9 +1435,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.95"
version = "0.9.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9"
checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b"
dependencies = [
"cc",
"libc",
@ -1494,12 +1451,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -1535,9 +1486,9 @@ dependencies = [
[[package]]
name = "percent-encoding"
version = "2.3.0"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pin-project"
@ -1577,22 +1528,6 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "polling"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce"
dependencies = [
"autocfg",
"bitflags 1.3.2",
"cfg-if",
"concurrent-queue",
"libc",
"log",
"pin-project-lite",
"windows-sys",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
@ -1758,8 +1693,8 @@ dependencies = [
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"http 0.2.11",
"http-body 0.4.5",
"hyper",
"hyper-tls",
"ipnet",
@ -1795,7 +1730,7 @@ checksum = "88a3e86aa6053e59030e7ce2d2a3b258dd08fc2d337d52f73f6cb480f5858690"
dependencies = [
"anyhow",
"async-trait",
"http",
"http 0.2.11",
"reqwest",
"serde",
"task-local-extensions",
@ -1831,20 +1766,6 @@ dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.37.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2"
dependencies = [
"bitflags 1.3.2",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys 0.3.8",
"windows-sys",
]
[[package]]
name = "rustix"
version = "0.38.23"
@ -1854,7 +1775,7 @@ dependencies = [
"bitflags 2.4.1",
"errno",
"libc",
"linux-raw-sys 0.4.11",
"linux-raw-sys",
"windows-sys",
]
@ -1888,15 +1809,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "scheduled-thread-pool"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19"
dependencies = [
"parking_lot",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -1937,18 +1849,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.192"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.192"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
@ -2180,9 +2092,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [
"cfg-if",
"fastrand 2.0.1",
"fastrand",
"redox_syscall",
"rustix 0.38.23",
"rustix",
"windows-sys",
]
@ -2252,9 +2164,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.34.0"
version = "1.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c"
dependencies = [
"backtrace",
"bytes",
@ -2454,9 +2366,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "url"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
dependencies = [
"form_urlencoded",
"idna",
@ -2486,12 +2398,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "waker-fn"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690"
[[package]]
name = "walkdir"
version = "2.4.0"

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
activitypub_federation = { git = "https://github.com/LemmyNet/activitypub-federation-rust.git", branch = "diesel-feature", features = ["axum", "diesel"], default-features = false }
activitypub_federation = { version = "0.5.0-beta.6", features = ["axum", "diesel"], default-features = false }
anyhow = "1.0.75"
async-trait = "0.1.74"
axum = "0.6.20"

View File

@ -45,6 +45,7 @@ create table article (
create table edit (
id serial primary key,
creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
hash uuid not null,
ap_id varchar(255) not null unique,
diff text not null,
@ -55,6 +56,7 @@ create table edit (
create table conflict (
id uuid primary key,
diff text not null,
creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
article_id int REFERENCES article ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
previous_version_id uuid not null
);

View File

@ -77,7 +77,7 @@ pub struct EditArticleData {
/// Conflicts are stored in the database so they can be retrieved later from `/api/v3/edit_conflicts`.
#[debug_handler]
pub(in crate::api) async fn edit_article(
Extension(_user): Extension<LocalUserView>,
Extension(user): Extension<LocalUserView>,
data: Data<MyDataHandle>,
Form(edit_form): Form<EditArticleData>,
) -> MyResult<Json<Option<ApiConflict>>> {
@ -90,10 +90,11 @@ pub(in crate::api) async fn edit_article(
if edit_form.previous_version_id == original_article.latest_version {
// No intermediate changes, simply submit new version
submit_article_update(
&data,
edit_form.new_text.clone(),
edit_form.previous_version_id,
&original_article.article,
user.person.id,
&data,
)
.await?;
Ok(Json(None))
@ -108,6 +109,7 @@ pub(in crate::api) async fn edit_article(
let form = DbConflictForm {
id: EditVersion::new(&patch.to_string())?,
diff: patch.to_string(),
creator_id: user.person.id,
article_id: original_article.article.id,
previous_version_id: previous_version.hash,
};
@ -176,6 +178,7 @@ pub(in crate::api) async fn fork_article(
let form = DbEditForm {
ap_id,
diff: e.diff,
creator_id: e.creator_id,
article_id: article.id,
hash: e.hash,
previous_version_id: e.previous_version_id,

View File

@ -24,6 +24,7 @@ use std::sync::Mutex;
pub struct DbConflict {
pub id: EditVersion,
pub diff: String,
pub creator_id: i32,
pub article_id: i32,
pub previous_version_id: EditVersion,
}
@ -41,6 +42,7 @@ pub struct ApiConflict {
pub struct DbConflictForm {
pub id: EditVersion,
pub diff: String,
pub creator_id: i32,
pub article_id: i32,
pub previous_version_id: EditVersion,
}
@ -84,10 +86,11 @@ impl DbConflict {
// patch applies cleanly so we are done
// federate the change
submit_article_update(
data,
new_text,
self.previous_version_id.clone(),
&original_article,
self.creator_id,
data,
)
.await?;
DbConflict::delete(self.id.clone(), &data.db_connection)?;

View File

@ -20,6 +20,7 @@ pub struct DbEdit {
// TODO: we could use hash as primary key, but that gives errors on forking because
// the same edit is used for multiple articles
pub id: i32,
pub creator_id: i32,
/// UUID built from sha224 hash of diff
pub hash: EditVersion,
pub ap_id: ObjectId<DbEdit>,
@ -32,6 +33,7 @@ pub struct DbEdit {
#[derive(Debug, Clone, Insertable, AsChangeset)]
#[diesel(table_name = edit, check_for_backend(diesel::pg::Pg))]
pub struct DbEditForm {
pub creator_id: i32,
pub hash: EditVersion,
pub ap_id: ObjectId<DbEdit>,
pub diff: String,
@ -42,6 +44,7 @@ pub struct DbEditForm {
impl DbEditForm {
pub fn new(
original_article: &DbArticle,
creator_id: i32,
updated_text: &str,
previous_version_id: EditVersion,
) -> MyResult<Self> {
@ -52,6 +55,7 @@ impl DbEditForm {
hash: version,
ap_id,
diff: diff.to_string(),
creator_id,
article_id: original_article.id,
previous_version_id,
})

View File

@ -16,6 +16,7 @@ diesel::table! {
conflict (id) {
id -> Uuid,
diff -> Text,
creator_id -> Int4,
article_id -> Int4,
previous_version_id -> Uuid,
}
@ -24,6 +25,7 @@ diesel::table! {
diesel::table! {
edit (id) {
id -> Int4,
creator_id -> Int4,
hash -> Uuid,
#[max_length = 255]
ap_id -> Varchar,
@ -81,7 +83,11 @@ diesel::table! {
diesel::joinable!(article -> instance (instance_id));
diesel::joinable!(conflict -> article (article_id));
diesel::joinable!(conflict -> person (creator_id));
diesel::joinable!(edit -> article (article_id));
diesel::joinable!(edit -> person (creator_id));
diesel::joinable!(instance_follow -> instance (instance_id));
diesel::joinable!(instance_follow -> person (follower_id));
diesel::joinable!(local_user -> person (person_id));
diesel::allow_tables_to_appear_in_same_query!(

View File

@ -80,6 +80,11 @@ impl DbPerson {
.get_result::<DbPerson>(conn.deref_mut())?)
}
pub fn read(id: i32, data: &Data<MyDataHandle>) -> MyResult<DbPerson> {
let mut conn = data.db_connection.lock().unwrap();
Ok(person::table.find(id).get_result(conn.deref_mut())?)
}
pub fn create_local(
username: String,
password: String,

View File

@ -34,7 +34,6 @@ impl Accept {
kind: Default::default(),
id,
};
dbg!(&accept);
send_activity(
&local_instance,
accept,
@ -64,7 +63,6 @@ impl ActivityHandler for Accept {
}
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
dbg!(&self);
// add to follows
let person = self.object.actor.dereference_local(data).await?;
let instance = self.actor.dereference(data).await?;

View File

@ -55,10 +55,8 @@ impl ActivityHandler for Follow {
}
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
dbg!(&self);
let actor = self.actor.dereference(data).await?;
let local_instance = DbInstance::read_local_instance(&data.db_connection)?;
dbg!(&actor.ap_id, &local_instance.ap_id);
DbInstance::follow(&actor, &local_instance, false, data)?;
// send back an accept

View File

@ -1,6 +1,7 @@
use crate::database::article::DbArticle;
use crate::database::edit::{DbEdit, DbEditForm};
use crate::database::instance::DbInstance;
use crate::database::version::EditVersion;
use crate::database::MyDataHandle;
use crate::error::Error;
@ -16,12 +17,13 @@ pub mod update_local_article;
pub mod update_remote_article;
pub async fn submit_article_update(
data: &Data<MyDataHandle>,
new_text: String,
previous_version: EditVersion,
original_article: &DbArticle,
creator_id: i32,
data: &Data<MyDataHandle>,
) -> Result<(), Error> {
let form = DbEditForm::new(original_article, &new_text, previous_version)?;
let form = DbEditForm::new(original_article, creator_id, &new_text, previous_version)?;
if original_article.local {
let edit = DbEdit::create(&form, &data.db_connection)?;
let updated_article =
@ -32,6 +34,7 @@ pub async fn submit_article_update(
// dont insert edit into db, might be invalid in case of conflict
let edit = DbEdit {
id: -1,
creator_id,
hash: form.hash,
ap_id: form.ap_id,
diff: form.diff,

View File

@ -73,9 +73,11 @@ impl ActivityHandler for RejectEdit {
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// cant convert this to DbEdit as it tries to apply patch and fails
let article = self.object.object.dereference(data).await?;
let creator = self.object.attributed_to.dereference(data).await?;
let form = DbConflictForm {
id: EditVersion::new(&self.object.content)?,
diff: self.object.content,
creator_id: creator.id,
article_id: article.id,
previous_version_id: self.object.previous_version,
};

View File

@ -1,5 +1,6 @@
use crate::database::article::DbArticle;
use crate::database::edit::{DbEdit, DbEditForm};
use crate::database::user::DbPerson;
use crate::database::version::EditVersion;
use crate::database::MyDataHandle;
use crate::error::Error;
@ -26,6 +27,7 @@ pub struct ApubEdit {
pub version: EditVersion,
pub previous_version: EditVersion,
pub object: ObjectId<DbArticle>,
pub attributed_to: ObjectId<DbPerson>,
}
#[async_trait::async_trait]
@ -43,6 +45,7 @@ impl Object for DbEdit {
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
let article = DbArticle::read(self.article_id, &data.db_connection)?;
let creator = DbPerson::read(self.creator_id, data)?;
Ok(ApubEdit {
kind: PatchType::Patch,
id: self.ap_id,
@ -50,6 +53,7 @@ impl Object for DbEdit {
version: self.hash,
previous_version: self.previous_version_id,
object: article.ap_id,
attributed_to: creator.ap_id,
})
}
@ -63,7 +67,9 @@ impl Object for DbEdit {
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
let article = json.object.dereference(data).await?;
let creator = json.attributed_to.dereference(data).await?;
let form = DbEditForm {
creator_id: creator.id,
ap_id: json.id,
diff: json.content,
article_id: article.id,

View File

@ -3,10 +3,10 @@ use crate::database::MyDataHandle;
use crate::error::{Error, MyResult};
use crate::federation::objects::articles_collection::DbArticleCollection;
use crate::federation::send_activity;
use activitypub_federation::activity_sending::SendActivityTask;
use activitypub_federation::fetch::collection_id::CollectionId;
use activitypub_federation::kinds::actor::ServiceType;
use activitypub_federation::protocol::context::WithContext;
use activitypub_federation::traits::ActivityHandler;
use activitypub_federation::{
config::Data,
@ -17,7 +17,7 @@ use activitypub_federation::{
use chrono::{DateTime, Local, Utc};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use tracing::log::warn;
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)]

View File

@ -150,10 +150,10 @@ impl Object for UserOrInstance {
object_id: Url,
data: &Data<Self::DataType>,
) -> Result<Option<Self>, Error> {
let person = DbPerson::read_from_id(object_id.clone(), data).await?;
let person = DbPerson::read_from_id(object_id.clone(), data).await;
Ok(match person {
Some(o) => Some(UserOrInstance::User(o)),
None => DbInstance::read_from_id(object_id, data)
Ok(Some(o)) => Some(UserOrInstance::User(o)),
_ => DbInstance::read_from_id(object_id.clone(), data)
.await?
.map(UserOrInstance::Instance),
})

View File

@ -49,6 +49,7 @@ mod test {
let diff = create_patch(a, b).to_string();
Ok(DbEdit {
id: 0,
creator_id: 0,
hash: EditVersion::new(&diff)?,
ap_id: ObjectId::parse("http://example.com")?,
diff,

View File

@ -163,7 +163,7 @@ pub async fn create_article(instance: &FediwikiInstance, title: String) -> MyRes
previous_version_id: article.latest_version,
resolve_conflict_id: None,
};
edit_article(&instance, &edit_form).await
edit_article(instance, &edit_form).await
}
pub async fn get_article(hostname: &str, article_id: i32) -> MyResult<ArticleView> {