Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 276d7731 authored by Philipp Heckel's avatar Philipp Heckel
Browse files

Enable/disable fast delivery; restart service on boot

parent 719a04ae
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -49,6 +49,13 @@
        <!-- Subscriber foreground service for hosts other than ntfy.sh -->
        <service android:name=".msg.SubscriberService" />

        <!-- Subscriber service restart on reboot -->
        <receiver android:enabled="true" android:name=".msg.SubscriberService$StartReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <!-- Firebase messaging -->
        <service
                android:name=".msg.FirebaseService"
+3 −0
Original line number Diff line number Diff line
@@ -116,6 +116,9 @@ interface SubscriptionDao {
    @Insert
    fun add(subscription: Subscription)

    @Update
    fun update(subscription: Subscription)

    @Query("DELETE FROM subscription WHERE id = :subscriptionId")
    fun remove(subscriptionId: Long)
}
+14 −2
Original line number Diff line number Diff line
@@ -19,17 +19,23 @@ class Repository(private val subscriptionDao: SubscriptionDao, private val notif
            .map { list -> toSubscriptionList(list) }
    }

    fun getSubscriptionIdsLiveData(): LiveData<Set<Long>> {
    fun getSubscriptionIdsWithInstantStatusLiveData(): LiveData<Set<Pair<Long, Boolean>>> {
        return subscriptionDao
            .listFlow()
            .asLiveData()
            .map { list -> list.map { it.id }.toSet() }
            .map { list -> list.map { Pair(it.id, it.instant) }.toSet() }
    }

    fun getSubscriptions(): List<Subscription> {
        return toSubscriptionList(subscriptionDao.list())
    }

    @Suppress("RedundantSuspendModifier")
    @WorkerThread
    suspend fun getSubscription(subscriptionId: Long): Subscription? {
        return toSubscription(subscriptionDao.get(subscriptionId))
    }

    @Suppress("RedundantSuspendModifier")
    @WorkerThread
    suspend fun getSubscription(baseUrl: String, topic: String): Subscription? {
@@ -42,6 +48,12 @@ class Repository(private val subscriptionDao: SubscriptionDao, private val notif
        subscriptionDao.add(subscription)
    }

    @Suppress("RedundantSuspendModifier")
    @WorkerThread
    suspend fun updateSubscription(subscription: Subscription) {
        subscriptionDao.update(subscription)
    }

    @Suppress("RedundantSuspendModifier")
    @WorkerThread
    suspend fun removeSubscription(subscriptionId: Long) {
+2 −0
Original line number Diff line number Diff line
@@ -79,10 +79,12 @@ class ApiService {
                        }
                    }
                } catch (e: Exception) {
                    Log.e(TAG, "Connection to $url failed (1): ${e.message}", e)
                    fail(e)
                }
            }
            override fun onFailure(call: Call, e: IOException) {
                Log.e(TAG, "Connection to $url failed (2): ${e.message}", e)
                fail(e)
            }
        })
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class FirebaseService : FirebaseMessagingService() {
            Log.d(TAG, "Discarding unexpected message: from=${remoteMessage.from}, data=${data}")
            return
        }
        Log.d(TAG, "Received notification: from=${remoteMessage.from}, data=${data}")

        CoroutineScope(job).launch {
            val baseUrl = getString(R.string.app_base_url) // Everything from Firebase comes from main service URL!
Loading