-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
116 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...main/kotlin/io/github/smaugfm/monobudget/common/notify/StatementItemNotificationSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.smaugfm.monobudget.common.notify | ||
|
||
import io.github.smaugfm.monobudget.common.model.financial.BankAccountId | ||
import io.github.smaugfm.monobudget.common.model.telegram.MessageWithReplyKeyboard | ||
|
||
interface StatementItemNotificationSender { | ||
suspend fun notify(accountId: BankAccountId, newMessage: MessageWithReplyKeyboard) | ||
} |
2 changes: 1 addition & 1 deletion
2
...monobudget/common/telegram/TelegramApi.kt → ...m/monobudget/common/notify/TelegramApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ommon/telegram/TelegramCallbackHandler.kt → .../common/notify/TelegramCallbackHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gram/TelegramErrorHandlerEventListener.kt → ...tify/TelegramErrorHandlerEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/io/github/smaugfm/monobudget/importer/ImportNotificationSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.smaugfm.monobudget.importer | ||
|
||
import io.github.smaugfm.monobudget.common.model.financial.BankAccountId | ||
import io.github.smaugfm.monobudget.common.model.telegram.MessageWithReplyKeyboard | ||
import io.github.smaugfm.monobudget.common.notify.StatementItemNotificationSender | ||
|
||
object ImportNotificationSender : StatementItemNotificationSender { | ||
override suspend fun notify(accountId: BankAccountId, newMessage: MessageWithReplyKeyboard) { | ||
// no-op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/io/github/smaugfm/monobudget/importer/ImportTransferCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.github.smaugfm.monobudget.importer | ||
|
||
import io.github.smaugfm.lunchmoney.model.LunchmoneyTransaction | ||
import io.github.smaugfm.monobudget.common.account.TransferCache | ||
import io.github.smaugfm.monobudget.common.model.financial.StatementItem | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.newSingleThreadContext | ||
import kotlinx.coroutines.withContext | ||
import kotlin.time.Duration | ||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
class ImportTransferCache(private val cacheTimeSimulatedDuration: Duration) : | ||
TransferCache<LunchmoneyTransaction> { | ||
private val singleThreadedContext = newSingleThreadContext("import-transfer-cache") | ||
private val cache = mutableMapOf<StatementItem, Deferred<LunchmoneyTransaction>>() | ||
.toSortedMap { o1, o2 -> o1.time.compareTo(o2.time) } | ||
|
||
@Suppress("DeferredResultUnused") | ||
override suspend fun getEntries(item: StatementItem): Set<Map.Entry<StatementItem, Deferred<LunchmoneyTransaction>>> = | ||
withContext(singleThreadedContext) { | ||
val threshold = item.time - cacheTimeSimulatedDuration | ||
while (cache.isNotEmpty()) { | ||
val cur = cache.firstKey() | ||
if (cur.time < threshold) { | ||
cache.remove(cur) | ||
} | ||
} | ||
cache.entries | ||
} | ||
|
||
override suspend fun put(item: StatementItem, transaction: Deferred<LunchmoneyTransaction>) { | ||
check(cache.keys.all { item.time >= it.time }) | ||
cache[item] = transaction | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters