Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 28 additions & 56 deletions core/src/main/kotlin/dev/usbharu/multim/api/AccountApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,94 +14,66 @@ interface AccountApi {
account: Account,
since: StatusId? = null,
until: StatusId? = null
): Result<List<Status>,MultiMError>

val FOLLOW: String
get() = "account/follow"

suspend fun follow(account: Account): Result<Unit,MultiMError>

val UNFOLLOW: String
get() = "account/unfollow"
suspend fun unfollow(account: Account): Result<Unit,MultiMError>

val PROFILE: String
get() = "account/profile"
suspend fun profile(account: Account): Result<Profile,MultiMError>

val STATUSES:String
get() = "account/statuses"
suspend fun statuses(account: Account, includeRepost: Boolean = false): Result<List<Status>,MultiMError>

val RELEATIONSHIPS:String
get() = "account/relationships"
suspend fun relationships(myself: Account, other: Account): Result<Relation,MultiMError>

val REQUEST_CANCEL:String
get() = "account/requestCancel"
suspend fun requestCancel(account: Account): Result<Unit,MultiMError>

val REQUEST_ACCEPT:String
get() = "account/requestAccept"
suspend fun requestAccept(account: Account): Result<Unit,MultiMError>
val REQUEST_REJECT:String
get() = "account/requestReject"
suspend fun requestReject(account: Account): Result<Unit,MultiMError>
}

object NotImplAccountApi : AccountApi {
override suspend fun userTimeline(
account: Account,
since: StatusId?,
until: StatusId?
): Result<List<Status>, MultiMError> {
): Result<List<Status>,MultiMError>{
Logger.debug("Account Api","Not impl account api. userTimeline.")
return Err(MultiMError("userTimeline not implements", null, ErrorType.NOT_IMPL))
}

override suspend fun follow(account: Account): Result<Unit, MultiMError> {
val FOLLOW: String
get() = "account/follow"

suspend fun follow(account: Account): Result<Unit,MultiMError>{
Logger.debug("Account Api","Not impl account api. follow.")
return Err(MultiMError("follow not implements", null, ErrorType.NOT_IMPL))
}

override suspend fun unfollow(account: Account): Result<Unit, MultiMError> {
val UNFOLLOW: String
get() = "account/unfollow"
suspend fun unfollow(account: Account): Result<Unit,MultiMError>{
Logger.debug("Account Api","Not impl account api. unfollow.")
return Err(MultiMError("unfollow not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun profile(account: Account): Result<Profile, MultiMError> {
val PROFILE: String
get() = "account/profile"
suspend fun profile(account: Account): Result<Profile,MultiMError>{
Logger.debug("Account Api","Not impl account api. profile.")
return Err(MultiMError("profile not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun statuses(
account: Account,
includeRepost: Boolean
): Result<List<Status>, MultiMError> {
val STATUSES:String
get() = "account/statuses"
suspend fun statuses(account: Account, includeRepost: Boolean = false): Result<List<Status>,MultiMError>{
Logger.debug("Account Api","Not impl account api. statuses.")
return Err(MultiMError("statuses not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun relationships(
myself: Account,
other: Account
): Result<Relation, MultiMError> {
val RELEATIONSHIPS:String
get() = "account/relationships"
suspend fun relationships(myself: Account, other: Account): Result<Relation,MultiMError>{
Logger.debug("Account Api","Not impl account api. relationships.")
return Err(MultiMError("relationships not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun requestCancel(account: Account): Result<Unit, MultiMError> {
val REQUEST_CANCEL:String
get() = "account/requestCancel"
suspend fun requestCancel(account: Account): Result<Unit,MultiMError>{
Logger.debug("Account Api","Not impl account api. requestCancel.")
return Err(MultiMError("requestCancel not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun requestAccept(account: Account): Result<Unit, MultiMError> {
val REQUEST_ACCEPT:String
get() = "account/requestAccept"
suspend fun requestAccept(account: Account): Result<Unit,MultiMError>{
Logger.debug("Account Api","Not impl account api. requestAccept.")
return Err(MultiMError("requestAccept not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun requestReject(account: Account): Result<Unit, MultiMError> {
val REQUEST_REJECT:String
get() = "account/requestReject"
suspend fun requestReject(account: Account): Result<Unit,MultiMError>{
Logger.debug("Account Api","Not impl account api. requestReject.")
return Err(MultiMError("requestReject not implements",null,ErrorType.NOT_IMPL))
}
}

object NotImplAccountApi : AccountApi
18 changes: 7 additions & 11 deletions core/src/main/kotlin/dev/usbharu/multim/api/EmojiApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import dev.usbharu.multim.model.Emoji
interface EmojiApi {
val GET:String
get() = "emoji/get"
suspend fun get(name:String):MultiMResult<Emoji>

val FIND_BY_NAME:String
get() = "emoji/findByName"

suspend fun findByName(name:String):MultiMResult<List<Emoji>>
}

object NotImplEmojiApi : EmojiApi {
override suspend fun get(name: String): MultiMResult<Emoji> {
suspend fun get(name:String):MultiMResult<Emoji>{
Logger.debug("Emoji Api","Not impl emoji api get $name")
return Err(MultiMError("emoji get not implements",null, ErrorType.NOT_IMPL))
}

override suspend fun findByName(name: String): MultiMResult<List<Emoji>> {
val FIND_BY_NAME:String
get() = "emoji/findByName"

suspend fun findByName(name:String):MultiMResult<List<Emoji>>{
Logger.debug("Emoji Api","Not impl emoji api findByName $name")
return Err(MultiMError("emoji findByName not implements",null,ErrorType.NOT_IMPL))
}
}

object NotImplEmojiApi : EmojiApi
17 changes: 6 additions & 11 deletions core/src/main/kotlin/dev/usbharu/multim/api/IApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,18 @@ interface IApi {
val PROFILE: String
get() = "i/profile"

suspend fun profile(): MultiMResult<Profile>
val STATUSES: String
get() = "i/statuses"

suspend fun statuses(): MultiMResult<List<Status>>

}

object NotImplIApi : IApi {
override suspend fun profile(): MultiMResult<Profile> {
suspend fun profile(): MultiMResult<Profile> {
Logger.debug("I Api", "Not impl i api. profile")
return Err(MultiMError("profile not implements", null, ErrorType.NOT_IMPL))
}
val STATUSES: String
get() = "i/statuses"

override suspend fun statuses(): MultiMResult<List<Status>> {
suspend fun statuses(): MultiMResult<List<Status>> {
Logger.debug("I Api", "Not impl i api. statuses")
return Err(MultiMError("profile not implements", null, ErrorType.NOT_IMPL))
}

}

object NotImplIApi : IApi
135 changes: 53 additions & 82 deletions core/src/main/kotlin/dev/usbharu/multim/api/StatusApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@ import kotlinx.datetime.toLocalDateTime
interface StatusApi {
val POST:String
get() = "status/post"
suspend fun post(status: StatusForPost): Result<Status,MultiMError>
suspend fun post(status: StatusForPost): Result<Status,MultiMError>{
Logger.debug("Status Api","Not impl status api post")
return Err(MultiMError("post not implements",null, ErrorType.NOT_IMPL))
}

val DELETE:String
get() = "status/delete"
suspend fun delete(id: StatusId): Result<Unit,MultiMError>
suspend fun delete(id: StatusId): Result<Unit,MultiMError>{
Logger.debug("Status Api","Not impl status api delete")
return Err(MultiMError("delete not implements",null,ErrorType.NOT_IMPL))
}
val FIND_BY_ID:String
get() = "status/findById"
suspend fun findById(id: StatusId): Result<Status,MultiMError>
suspend fun findById(id: StatusId): Result<Status,MultiMError> {
Logger.debug("Status Api","Not impl status api findById")
return Err(MultiMError("findById not implements",null,ErrorType.NOT_IMPL))
}
val ADD_REACTION:String
get() = "status/addReaction"
suspend fun addReaction(id: StatusId, reaction: Reaction): Result<Unit,MultiMError>
suspend fun addReaction(id: StatusId, reaction: Reaction): Result<Unit,MultiMError> {
Logger.debug("Status Api","Not impl status api addReaction")
return Err(MultiMError("addReaction not implements",null,ErrorType.NOT_IMPL))
}

val REMOVE_REACTION:String
get() = "status/remvoeReaction"
Expand All @@ -35,109 +47,68 @@ interface StatusApi {
* @param reaction 実装によって挙動が変わります。nullでも
* @return
*/
suspend fun removeReaction(id: StatusId, reaction: Reaction?): Result<Unit,MultiMError>
val REACTIONS:String
get() = "status/reactions"
suspend fun reactions(id: StatusId): Result<Map<Reaction, Int>,MultiMError>
val REPLIES:String
get() = "status/replies"
suspend fun replies(id: StatusId): Result<List<Status>,MultiMError>
val REPOST:String
get() = "status/repost"
suspend fun repost(id: StatusId): Result<Status,MultiMError>
val UN_REPOST:String
get() = "status/unRepost"
suspend fun unRepost(id: StatusId): Result<Unit,MultiMError>
val REPLY_TO:String
get() = "status/replyTo"
suspend fun replyTo(id: StatusId, status: StatusForPost): Result<Status,MultiMError>
val ADD_TO_BOOKMARKS:String
get() = "status/addBookMarks"
suspend fun addToBookmarks(id: StatusId): Result<Unit,MultiMError>
val REMOVE_FROM_BOOKMARKS:String
get() = "status/removeFromBookmarks"
suspend fun removeFromBookmarks(id: StatusId): Result<Unit,MultiMError>
val GET_PREVIOUS_AND_NEXT:String
get() = "status/getPreviousAndNext"
suspend fun getPreviousAndNext(id: StatusId): Result<PreviousAndNextPosts,MultiMError>

fun getUniqueId(status: Status):Int{
val localDateTime = status.createdAt.toLocalDateTime(TimeZone.UTC)
val date:String =
"${localDateTime.year}${localDateTime.monthNumber}${localDateTime.dayOfMonth}${localDateTime.hour}${localDateTime.minute}${localDateTime.second}"
return UniqueId.hashAlgorithm.hash32x86(
(status.content.text + status.account.accountName + date).encodeToByteArray()
).toInt()
}
}


object NotImplStatusApi : StatusApi {
override suspend fun post(status: StatusForPost): Result<Status, MultiMError> {
Logger.debug("Status Api","Not impl status api post")
return Err(MultiMError("post not implements",null, ErrorType.NOT_IMPL))
}

override suspend fun delete(id: StatusId): Result<Unit, MultiMError> {
Logger.debug("Status Api","Not impl status api delete")
return Err(MultiMError("delete not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun findById(id: StatusId): Result<Status, MultiMError> {
Logger.debug("Status Api","Not impl status api findById")
return Err(MultiMError("findById not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun addReaction(id: StatusId, reaction: Reaction): Result<Unit, MultiMError> {
Logger.debug("Status Api","Not impl status api addReaction")
return Err(MultiMError("addReaction not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun removeReaction(
id: StatusId,
reaction: Reaction?
): Result<Unit, MultiMError> {
suspend fun removeReaction(id: StatusId, reaction: Reaction?): Result<Unit,MultiMError> {
Logger.debug("Status Api","Not impl status api removeReaction")
return Err(MultiMError("removeReaction not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun reactions(id: StatusId): Result<Map<Reaction, Int>, MultiMError> {
val REACTIONS:String
get() = "status/reactions"
suspend fun reactions(id: StatusId): Result<Map<Reaction, Int>,MultiMError>{
Logger.debug("Status Api","Not impl status api reactions")
return Err(MultiMError("reactions not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun replies(id: StatusId): Result<List<Status>, MultiMError> {
val REPLIES:String
get() = "status/replies"
suspend fun replies(id: StatusId): Result<List<Status>,MultiMError>{
Logger.debug("Status Api","Not impl status api replies")
return Err(MultiMError("replies not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun repost(id: StatusId): Result<Status, MultiMError> {
val REPOST:String
get() = "status/repost"
suspend fun repost(id: StatusId): Result<Status,MultiMError> {
Logger.debug("Status Api","Not impl status api repost")
return Err(MultiMError("repost not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun unRepost(id: StatusId): Result<Unit, MultiMError> {
val UN_REPOST:String
get() = "status/unRepost"
suspend fun unRepost(id: StatusId): Result<Unit,MultiMError>{
Logger.debug("Status Api","Not impl status api unRepost")
return Err(MultiMError("unRepost not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun replyTo(id: StatusId, status: StatusForPost): Result<Status, MultiMError> {
val REPLY_TO:String
get() = "status/replyTo"
suspend fun replyTo(id: StatusId, status: StatusForPost): Result<Status,MultiMError> {
Logger.debug("Status Api","Not impl status api replyTo")
return Err(MultiMError("replyTo not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun addToBookmarks(id: StatusId): Result<Unit, MultiMError> {
val ADD_TO_BOOKMARKS:String
get() = "status/addBookMarks"
suspend fun addToBookmarks(id: StatusId): Result<Unit,MultiMError>{
Logger.debug("Status Api","Not impl status api addToBookmarks")
return Err(MultiMError("addToBookmarks not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun removeFromBookmarks(id: StatusId): Result<Unit, MultiMError> {
val REMOVE_FROM_BOOKMARKS:String
get() = "status/removeFromBookmarks"
suspend fun removeFromBookmarks(id: StatusId): Result<Unit,MultiMError>{
Logger.debug("Status Api","Not impl status api removeFromBookmarks")
return Err(MultiMError("removeFromBookmarks not implements",null,ErrorType.NOT_IMPL))
}

override suspend fun getPreviousAndNext(id: StatusId): Result<PreviousAndNextPosts, MultiMError> {
val GET_PREVIOUS_AND_NEXT:String
get() = "status/getPreviousAndNext"
suspend fun getPreviousAndNext(id: StatusId): Result<PreviousAndNextPosts,MultiMError>{
Logger.debug("Status Api","Not impl status api getPreviousAndNext")
return Err(MultiMError("getPreviousAndNext not implements",null,ErrorType.NOT_IMPL))
}

fun getUniqueId(status: Status):Int{
val localDateTime = status.createdAt.toLocalDateTime(TimeZone.UTC)
val date:String =
"${localDateTime.year}${localDateTime.monthNumber}${localDateTime.dayOfMonth}${localDateTime.hour}${localDateTime.minute}${localDateTime.second}"
return UniqueId.hashAlgorithm.hash32x86(
(status.content.text + status.account.accountName + date).encodeToByteArray()
).toInt()
}
}


object NotImplStatusApi : StatusApi
Loading