Skip to content

Commit

Permalink
feat: closureを渡すようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jul 2, 2023
1 parent caebd6e commit c6acc73
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChannelAPITest {
val wssURL = "wss://misskey.io/streaming"
val logger = TestLogger.Factory()
val socket =
SocketImpl(wssURL, true, logger, DefaultOkHttpClientProvider())
SocketImpl(wssURL, {false}, logger, DefaultOkHttpClientProvider())
socket.blockingConnect()

var count = 0
Expand All @@ -51,7 +51,7 @@ class ChannelAPITest {
val wssURL = "wss://misskey.io/streaming"
val logger = TestLogger.Factory()
val socket =
SocketImpl(wssURL, true, logger, DefaultOkHttpClientProvider())
SocketImpl(wssURL, {false}, logger, DefaultOkHttpClientProvider())
val channelAPI = ChannelAPI(socket, logger)
runBlocking {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SocketImplTest {
fun testBlockingConnect() {
val wssURL = "wss://misskey.io/streaming"
val logger = TestLogger.Factory()
val socket = SocketImpl(wssURL, logger, DefaultOkHttpClientProvider())
val socket = SocketImpl(wssURL, {false} ,logger, DefaultOkHttpClientProvider())
runBlocking {
socket.blockingConnect()
assertEquals(socket.state(), Socket.State.Connected)
Expand All @@ -33,7 +33,7 @@ class SocketImplTest {

val wssURL = "wss://misskey.io/streaming"
val logger = TestLogger.Factory()
val socket = SocketImpl(wssURL, logger, DefaultOkHttpClientProvider())
val socket = SocketImpl(wssURL, {false}, logger, DefaultOkHttpClientProvider())

runBlocking {

Expand All @@ -55,7 +55,7 @@ class SocketImplTest {
val wssURL = "wss://misskey.io/streaming"
val logger = TestLogger.Factory()
val socket =
SocketImpl(wssURL, logger, DefaultOkHttpClientProvider())
SocketImpl(wssURL, {false}, logger, DefaultOkHttpClientProvider())

runBlocking {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.coroutines.suspendCoroutine

class SocketImpl(
val url: String,
var isRequirePingPong: Boolean,
var isRequirePingPong: () -> Boolean,
loggerFactory: Logger.Factory,
okHttpClientProvider: OkHttpClientProvider,
) : Socket {
Expand Down Expand Up @@ -312,7 +312,7 @@ class SocketImpl(
synchronized(this@SocketImpl) {
pollingJob.cancel()
pollingJob = PollingJob(this@SocketImpl).also {
if (isRequirePingPong) {
if (isRequirePingPong()) {
it.startPolling(4000, 900, 12000)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ class SocketWithAccountProviderImpl @Inject constructor(
if (account.instanceType == Account.InstanceType.MASTODON) {
return null
}
val isRequirePingPong = nodeInfoRepository.get(account.getHost())?.let {
!(it.type is NodeInfo.SoftwareType.Misskey.Normal && it.type.getVersion() >= Version("13.13.2"))
}
synchronized(accountIdWithSocket) {
var socket = accountIdWithSocket[account.accountId]
if (socket != null) {
// NOTE: tokenが異なる場合は再認証された可能性があるので、再生成を行う
if (account.token == accountIdWithToken[account.accountId]) {
logger.debug { "すでにインスタンス化済み" }
socket.isRequirePingPong = isRequirePingPong ?: true
return socket
} else {
socket.destroy()
Expand All @@ -70,7 +66,11 @@ class SocketWithAccountProviderImpl @Inject constructor(

socket = SocketImpl(
url = uri,
isRequirePingPong = isRequirePingPong ?: true,
isRequirePingPong = {
nodeInfoRepository.get(account.getHost())?.let {
!(it.type is NodeInfo.SoftwareType.Misskey.Normal && it.type.getVersion() >= Version("13.13.2"))
} ?: true
},
okHttpClientProvider = okHttpClientProvider,
loggerFactory = loggerFactory,
)
Expand Down

0 comments on commit c6acc73

Please sign in to comment.