feat: フォロー承認制ユーザーかの情報をActivityPub側でも持たせるように

This commit is contained in:
2023-12-12 01:32:55 +09:00
parent 6b535a042a
commit fe74d1e30b
26 changed files with 98 additions and 63 deletions
@@ -17,10 +17,10 @@ constructor(
var publicKey: Key,
var endpoints: Map<String, String> = emptyMap(),
var followers: String?,
var following: String?
var following: String?,
val manuallyApprovesFollowers: Boolean? = false
) : Object(add(type, "Person")), HasId, HasName {
@Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod")
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
@@ -40,11 +40,11 @@ constructor(
if (endpoints != other.endpoints) return false
if (followers != other.followers) return false
if (following != other.following) return false
if (manuallyApprovesFollowers != other.manuallyApprovesFollowers) return false
return true
}
@Suppress("CyclomaticComplexMethod")
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + name.hashCode()
@@ -59,6 +59,26 @@ constructor(
result = 31 * result + endpoints.hashCode()
result = 31 * result + (followers?.hashCode() ?: 0)
result = 31 * result + (following?.hashCode() ?: 0)
result = 31 * result + manuallyApprovesFollowers.hashCode()
return result
}
override fun toString(): String {
return "Person(" +
"name='$name', " +
"id='$id', " +
"preferredUsername=$preferredUsername, " +
"summary=$summary, " +
"inbox='$inbox', " +
"outbox='$outbox', " +
"url='$url', " +
"icon=$icon, " +
"publicKey=$publicKey, " +
"endpoints=$endpoints, " +
"followers=$followers, " +
"following=$following, " +
"manuallyApprovesFollowers=$manuallyApprovesFollowers" +
")" +
" ${super.toString()}"
}
}
@@ -68,7 +68,8 @@ class APUserServiceImpl(
),
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
followers = userEntity.followers,
following = userEntity.following
following = userEntity.following,
manuallyApprovesFollowers = userEntity.locked
)
}
@@ -104,7 +105,8 @@ class APUserServiceImpl(
keyId = person.publicKey.id,
following = person.following,
followers = person.followers,
sharedInbox = person.endpoints["sharedInbox"]
sharedInbox = person.endpoints["sharedInbox"],
locked = person.manuallyApprovesFollowers
)
)
}
@@ -134,6 +136,7 @@ class APUserServiceImpl(
),
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
followers = actorEntity.followers,
following = actorEntity.following
following = actorEntity.following,
manuallyApprovesFollowers = actorEntity.locked
)
}
@@ -21,7 +21,8 @@ data class Actor private constructor(
val keyId: String,
val followers: String? = null,
val following: String? = null,
val instance: Long? = null
val instance: Long? = null,
val locked: Boolean
) {
@@ -46,7 +47,8 @@ data class Actor private constructor(
keyId: String,
following: String? = null,
followers: String? = null,
instance: Long? = null
instance: Long? = null,
locked: Boolean
): Actor {
// idは0未満ではいけない
require(id >= 0) { "id must be greater than or equal to 0." }
@@ -137,7 +139,8 @@ data class Actor private constructor(
keyId = keyId,
followers = followers,
following = following,
instance = instance
instance = instance,
locked
)
}
}
@@ -158,7 +161,10 @@ data class Actor private constructor(
"keyId='$keyId', " +
"followers=$followers, " +
"following=$following, " +
"instance=$instance" +
"instance=$instance, " +
"locked=$locked" +
")"
}
}
@@ -25,7 +25,8 @@ class UserResultRowMapper(private val actorBuilder: Actor.UserBuilder) : ResultR
keyId = resultRow[Actors.keyId],
followers = resultRow[Actors.followers],
following = resultRow[Actors.following],
instance = resultRow[Actors.instance]
instance = resultRow[Actors.instance],
locked = resultRow[Actors.locked]
)
}
}
@@ -34,6 +34,7 @@ class ActorRepositoryImpl(
it[following] = actor.following
it[followers] = actor.followers
it[instance] = actor.instance
it[locked] = actor.locked
}
} else {
Actors.update({ Actors.id eq actor.id }) {
@@ -51,6 +52,7 @@ class ActorRepositoryImpl(
it[following] = actor.following
it[followers] = actor.followers
it[instance] = actor.instance
it[locked] = actor.locked
}
}
return actor
@@ -88,6 +90,7 @@ object Actors : Table("actors") {
val following = varchar("following", length = 1000).nullable()
val followers = varchar("followers", length = 1000).nullable()
val instance = long("instance").references(Instance.id).nullable()
val locked = bool("locked")
override val primaryKey: PrimaryKey = PrimaryKey(id)
@@ -12,5 +12,6 @@ data class RemoteUserCreateDto(
val keyId: String,
val followers: String?,
val following: String?,
val sharedInbox: String?
val sharedInbox: String?,
val locked: Boolean?
)
@@ -49,7 +49,8 @@ class UserServiceImpl(
createdAt = Instant.now(),
following = "$userUrl/following",
followers = "$userUrl/followers",
keyId = "$userUrl#pubkey"
keyId = "$userUrl#pubkey",
locked = false
)
val save = actorRepository.save(userEntity)
userDetailRepository.save(UserDetail(nextId, hashedPassword, true, true))
@@ -82,7 +83,8 @@ class UserServiceImpl(
followers = user.followers,
following = user.following,
keyId = user.keyId,
instance = instance?.id
instance = instance?.id,
locked = user.locked ?: false
)
return try {
val save = actorRepository.save(userEntity)
@@ -30,6 +30,7 @@ create table if not exists actors
"following" varchar(1000) null,
followers varchar(1000) null,
"instance" bigint null,
locked boolean not null,
unique ("name", "domain"),
constraint fk_actors_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict
);