From b6a7fa2ffb0ca05113692887e3fda7be61b1c318 Mon Sep 17 00:00:00 2001 From: koalasat Date: Thu, 24 Oct 2024 10:34:48 +0200 Subject: [PATCH] Add new note kinds --- .github/workflows/create-release.yml | 6 ++-- .../koalasat/pokey/database/AppDatabase.kt | 2 +- .../pokey/service/NotificationsService.kt | 28 ++++++++++++++----- .../pokey/ui/relays/RelaysFragment.kt | 10 ++----- .../pokey/ui/relays/RelaysViewModel.kt | 11 +------- app/src/main/res/layout/fragment_relays.xml | 22 +++++++-------- app/src/main/res/menu/bottom_nav_menu.xml | 2 +- .../main/res/navigation/mobile_navigation.xml | 11 ++++++-- zapstore.yaml | 2 +- 9 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index e4a9c67..a2a16eb 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -59,13 +59,13 @@ jobs: draft: false prerelease: ${{ steps.regex-match.outputs.match != '' }} - - name: Upload Free APK Universal Asset - id: upload-free-release-asset-universal-apk + - name: Upload APK Universal Asset + id: upload-release-asset-universal-apk uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: app/build/outputs/apk/release/app-release-unsigned-signed.apk - asset_name: amber-fdroid-universal-${{ github.ref_name }}.apk + asset_name: pokey-universal-${{ github.ref_name }}.apk asset_content_type: application/zip diff --git a/app/src/main/java/com/koalasat/pokey/database/AppDatabase.kt b/app/src/main/java/com/koalasat/pokey/database/AppDatabase.kt index ea4d7fc..7f001df 100644 --- a/app/src/main/java/com/koalasat/pokey/database/AppDatabase.kt +++ b/app/src/main/java/com/koalasat/pokey/database/AppDatabase.kt @@ -30,7 +30,7 @@ abstract class AppDatabase : RoomDatabase() { Room.databaseBuilder( context, AppDatabase::class.java, - "amber_db_$pubKey", + "pokey_db_$pubKey", ) .build() instance diff --git a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt index 254214b..13d798c 100644 --- a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt +++ b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt @@ -47,6 +47,7 @@ class NotificationsService : Service() { private var subscriptionNotificationId = "subscriptionNotificationId" private var subscriptionInboxId = "inboxRelays" + private var receivedEventsCache = mutableSetOf() private var defaultRelayUrls = listOf( "wss://relay.damus.io", "wss://offchain.pub", @@ -84,11 +85,11 @@ class NotificationsService : Service() { relay: Relay, afterEOSE: Boolean, ) { + if (receivedEventsCache.contains(event.id)) return Log.d("Pokey", "Relay Event: ${relay.url} - $subscriptionId - ${event.toJson()}") + receivedEventsCache.add(event.id) if (subscriptionId == subscriptionNotificationId) { createNoteNotification(event) - } else if (subscriptionId == subscriptionInboxId) { - manageInboxRelays(event) } } @@ -213,24 +214,38 @@ class NotificationsService : Service() { TypedFilter( types = COMMON_FEED_TYPES, filter = SincePerRelayFilter( - kinds = listOf(1), + kinds = listOf(1, 4, 13, 9735), tags = mapOf("p" to listOf(hexKey)), since = RelayPool.getAll().associate { it.url to EOSETime(latestNotification) }, ), ), ), ) - Client.sendFilter( + Client.sendFilterAndStopOnFirstResponse( + subscriptionInboxId, + listOf( + TypedFilter( + types = EVENT_FINDER_TYPES, + filter = SincePerRelayFilter( + kinds = listOf(10002), + authors = listOf(hexKey), + ), + ), + ), + onResponse = { manageInboxRelays(it) }, + ) + Client.sendFilterAndStopOnFirstResponse( subscriptionInboxId, listOf( TypedFilter( types = EVENT_FINDER_TYPES, filter = SincePerRelayFilter( - kinds = listOf(10050, 10002), + kinds = listOf(10050), authors = listOf(hexKey), ), ), ), + onResponse = { manageInboxRelays(it) }, ) } } @@ -243,6 +258,7 @@ class NotificationsService : Service() { timer.schedule( object : TimerTask() { override fun run() { + receivedEventsCache.clear() RelayPool.getAll().forEach { if (!it.isConnected()) { Log.d( @@ -331,8 +347,6 @@ class NotificationsService : Service() { title = getString(R.string.new_private) } else if (event.kind == 9735) { title = getString(R.string.new_zap) - } else if (event.kind == 3) { - title = getString(R.string.new_follow) } if (title.isEmpty()) return@launch diff --git a/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysFragment.kt b/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysFragment.kt index 4ca3940..95f003f 100644 --- a/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysFragment.kt +++ b/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysFragment.kt @@ -35,15 +35,11 @@ class RelaysFragment : Fragment() { val root: View = binding.root val textView: TextView = binding.titleRelays - relaysViewModel.text.observe(viewLifecycleOwner) { - textView.text = it - } - Pokey.isEnabled.observe(viewLifecycleOwner) { - textView.text = if (it) { - getString(R.string.relays) + if (it) { + textView.visibility = View.GONE } else { - getString(R.string.not_started) + textView.visibility = View.VISIBLE } } diff --git a/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysViewModel.kt b/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysViewModel.kt index ef3ed85..0f50ee2 100644 --- a/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysViewModel.kt +++ b/app/src/main/java/com/koalasat/pokey/ui/relays/RelaysViewModel.kt @@ -1,14 +1,5 @@ package com.koalasat.pokey.ui.relays -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.koalasat.pokey.Pokey -import com.koalasat.pokey.R -class RelaysViewModel() : ViewModel() { - private val _text = MutableLiveData().apply { - value = Pokey.getInstance().getString(R.string.not_started) - } - val text: LiveData = _text -} +class RelaysViewModel() : ViewModel() diff --git a/app/src/main/res/layout/fragment_relays.xml b/app/src/main/res/layout/fragment_relays.xml index df415b4..7836c6a 100644 --- a/app/src/main/res/layout/fragment_relays.xml +++ b/app/src/main/res/layout/fragment_relays.xml @@ -9,23 +9,23 @@ + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - \ No newline at end of file + app:layout_constraintTop_toBottomOf="@+id/title_relays" /> + diff --git a/app/src/main/res/menu/bottom_nav_menu.xml b/app/src/main/res/menu/bottom_nav_menu.xml index 5f871a7..6f50b90 100644 --- a/app/src/main/res/menu/bottom_nav_menu.xml +++ b/app/src/main/res/menu/bottom_nav_menu.xml @@ -16,4 +16,4 @@ android:icon="@drawable/ic_notifications_black_24dp" android:title="@string/title_notifications" /> - \ No newline at end of file + diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index fd1e05a..3383385 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -9,7 +9,14 @@ android:id="@+id/navigation_home" android:name="com.koalasat.pokey.ui.home.HomeFragment" android:label="@string/title_home" - tools:layout="@layout/fragment_home" /> + tools:layout="@layout/fragment_home" > + + + - \ No newline at end of file + diff --git a/zapstore.yaml b/zapstore.yaml index b057142..b9bd810 100644 --- a/zapstore.yaml +++ b/zapstore.yaml @@ -1,4 +1,4 @@ -amber: +pokey: android: identifier: com.kolasat.pokey name: Pokey