Skip to content

Commit

Permalink
feat: 処理の内容を効率化した
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Oct 29, 2023
1 parent ee1459a commit f3c5b93
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,49 @@ class NoteStreamingImpl @Inject constructor(
when (pageable) {
is Pageable.GlobalTimeline -> {
requireNotNull(channelAPIProvider.get(ac)).connect(ChannelAPI.Type.Global)
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.HybridTimeline -> {
requireNotNull(channelAPIProvider.get(ac)).connect(ChannelAPI.Type.Hybrid)
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.LocalTimeline -> {
requireNotNull(channelAPIProvider.get(ac)).connect(ChannelAPI.Type.Local)
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.HomeTimeline -> {
requireNotNull(channelAPIProvider.get(ac)).connect(ChannelAPI.Type.Home)
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.UserListTimeline -> {
requireNotNull(channelAPIProvider.get(ac))
.connect(ChannelAPI.Type.UserList(userListId = pageable.listId))
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.Antenna -> {
requireNotNull(channelAPIProvider.get(ac))
.connect(ChannelAPI.Type.Antenna(antennaId = pageable.antennaId))
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.UserTimeline -> {
requireNotNull(channelAPIProvider.get(ac))
.connectUserTimeline(pageable.userId).convertToNote(getAccount, pageable)
.connectUserTimeline(pageable.userId).convertToNote(ac, pageable)
}
is Pageable.ChannelTimeline -> {
requireNotNull(channelAPIProvider.get(ac))
.connect(ChannelAPI.Type.Channel(channelId = pageable.channelId))
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.CalckeyRecommendedTimeline -> {
requireNotNull(channelAPIProvider.get(ac))
.connect(ChannelAPI.Type.RecommendedTimeline)
.convertToNote(getAccount, pageable)
.convertToNote(ac, pageable)
}
is Pageable.Mastodon -> {
when (pageable) {
is Pageable.Mastodon.HashTagTimeline -> {
requireNotNull(streamingAPIProvider.get(ac)).connectHashTag(pageable.hashtag)
.convertToNoteFromStatus(getAccount, pageable)
.convertToNoteFromStatus(ac, pageable)
}
is Pageable.Mastodon.HomeTimeline -> {
requireNotNull(streamingAPIProvider.get(ac)).connectUser()
Expand All @@ -97,17 +97,17 @@ class NoteStreamingImpl @Inject constructor(
streamingAPIProvider.get(
ac
)
).connectUserList(pageable.listId).convertToNoteFromStatus(getAccount, pageable)
).connectUserList(pageable.listId).convertToNoteFromStatus(ac, pageable)
is Pageable.Mastodon.LocalTimeline -> requireNotNull(
streamingAPIProvider.get(
ac
)
).connectLocalPublic().convertToNoteFromStatus(getAccount, pageable)
).connectLocalPublic().convertToNoteFromStatus(ac, pageable)
is Pageable.Mastodon.PublicTimeline -> requireNotNull(
streamingAPIProvider.get(
ac
)
).connectPublic().convertToNoteFromStatus(getAccount, pageable)
).connectPublic().convertToNoteFromStatus(ac, pageable)
else -> throw IllegalStateException("Global, Hybrid, Local, Homeは以外のStreamは対応していません。")
}
}
Expand All @@ -116,7 +116,7 @@ class NoteStreamingImpl @Inject constructor(
}
}

private fun Flow<ChannelBody>.convertToNote(getAccount: suspend () -> Account, pageable: Pageable): Flow<Note> {
private fun Flow<ChannelBody>.convertToNote(account: Account, pageable: Pageable): Flow<Note> {
return mapNotNull {
it as? ChannelBody.ReceiveNote
}.filter {
Expand All @@ -130,11 +130,11 @@ class NoteStreamingImpl @Inject constructor(
true
}
}.map {
noteDataSourceAdder.addNoteDtoToDataSource(getAccount(), it.body)
noteDataSourceAdder.addNoteDtoToDataSource(account, it.body)
}
}

private fun Flow<TootStatusDTO>.convertToNoteFromStatus(getAccount: suspend () -> Account, pageable: Pageable): Flow<Note> {
private fun Flow<TootStatusDTO>.convertToNoteFromStatus(account: Account, pageable: Pageable): Flow<Note> {
return filter {
if (pageable is CanOnlyMedia<*>) {
if (pageable.getOnlyMedia()) {
Expand All @@ -146,7 +146,7 @@ class NoteStreamingImpl @Inject constructor(
true
}
}.map {
noteDataSourceAdder.addTootStatusDtoIntoDataSource(getAccount(), it)
noteDataSourceAdder.addTootStatusDtoIntoDataSource(account, it)
}
}

Expand Down

0 comments on commit f3c5b93

Please sign in to comment.