Add activity_id column to follow_request table

This commit is contained in:
silverpill 2022-12-12 23:50:40 +00:00
parent 8c14b18d5b
commit b0f9b3537e
5 changed files with 21 additions and 22 deletions

View file

@ -0,0 +1 @@
ALTER TABLE follow_request ADD COLUMN activity_id VARCHAR(250) UNIQUE;

View file

@ -69,6 +69,7 @@ CREATE TABLE follow_request (
id UUID PRIMARY KEY,
source_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
target_id UUID NOT NULL REFERENCES actor_profile (id) ON DELETE CASCADE,
activity_id VARCHAR(250) UNIQUE,
request_status SMALLINT NOT NULL,
UNIQUE (source_id, target_id)
);

View file

@ -609,7 +609,11 @@ async fn follow_account(
let target = get_profile_by_id(db_client, &account_id).await?;
if let Some(remote_actor) = target.actor_json {
// Create follow request if target is remote
match create_follow_request(db_client, &current_user.id, &target.id).await {
match create_follow_request(
db_client,
&current_user.id,
&target.id,
).await {
Ok(follow_request) => {
prepare_follow(
&config.instance(),

View file

@ -140,26 +140,23 @@ pub async fn create_follow_request(
source_id: &Uuid,
target_id: &Uuid,
) -> Result<DbFollowRequest, DatabaseError> {
let request = DbFollowRequest {
id: new_uuid(),
source_id: source_id.to_owned(),
target_id: target_id.to_owned(),
request_status: FollowRequestStatus::Pending,
};
db_client.execute(
let request_id = new_uuid();
let row = db_client.query_one(
"
INSERT INTO follow_request (
id, source_id, target_id, request_status
)
VALUES ($1, $2, $3, $4)
RETURNING follow_request
",
&[
&request.id,
&request.source_id,
&request.target_id,
&request.request_status,
&request_id,
&source_id,
&target_id,
&FollowRequestStatus::Pending,
],
).await.map_err(catch_unique_violation("follow request"))?;
let request = row.try_get("follow_request")?;
Ok(request)
}
@ -517,7 +514,7 @@ mod tests {
#[tokio::test]
#[serial]
async fn test_remote_follow() {
async fn test_follow_remote_profile() {
let db_client = &mut create_test_database().await;
let source_data = UserCreateData {
username: "test".to_string(),
@ -536,20 +533,15 @@ mod tests {
.await.unwrap();
assert_eq!(follow_request.source_id, source.id);
assert_eq!(follow_request.target_id, target.id);
assert!(matches!(
follow_request.request_status,
FollowRequestStatus::Pending,
));
assert_eq!(follow_request.activity_id, None);
assert_eq!(follow_request.request_status, FollowRequestStatus::Pending);
let following = get_following(db_client, &source.id).await.unwrap();
assert!(following.is_empty());
// Accept follow request
follow_request_accepted(db_client, &follow_request.id).await.unwrap();
let follow_request = get_follow_request_by_id(db_client, &follow_request.id)
.await.unwrap();
assert!(matches!(
follow_request.request_status,
FollowRequestStatus::Accepted,
));
assert_eq!(follow_request.request_status, FollowRequestStatus::Accepted);
let following = get_following(db_client, &source.id).await.unwrap();
assert_eq!(following[0].id, target.id);
// Unfollow

View file

@ -87,7 +87,7 @@ impl TryFrom<&Row> for DbRelationship {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum FollowRequestStatus {
Pending,
Accepted,
@ -127,6 +127,7 @@ pub struct DbFollowRequest {
pub id: Uuid,
pub source_id: Uuid,
pub target_id: Uuid,
pub activity_id: Option<String>,
pub request_status: FollowRequestStatus,
}