<commit_before>package org.eurofurence.connavigator.gcm

import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.pawegio.kandroid.d
import com.pawegio.kandroid.i
import com.pawegio.kandroid.w
import org.eurofurence.connavigator.BuildConfig
import org.eurofurence.connavigator.database.UpdateIntentService
import org.jetbrains.anko.intentFor

/**
 * Created by David on 14-4-2016.
 */
class PushListenerService : FirebaseMessagingService() {
    val factory by lazy { NotificationFactory(applicationContext) }

    fun subscribe() {
        val messaging = FirebaseMessaging.getInstance()
        if (BuildConfig.DEBUG) {
            messaging.subscribeToTopic("test")
        }
        messaging.subscribeToTopic("announcements")
    }

    override fun onMessageReceived(message: RemoteMessage) {
        i { "Received push message" }
        d { "Message payload :" + message.data }

        when (message.data["Event"]) {
            "Announcement" -> createAnnouncement(message)
            "ImportantAnnouncement" -> createHighPriorityAnnouncement(message)
            "Sync" -> syncData(message)
            else -> w("Message did not contain a valid event. Abandoning!")
        }


    }

    private fun syncData(message: RemoteMessage) {
        i { "Received request to sync data" }

        applicationContext.sendBroadcast(intentFor<UpdateIntentService>())
    }

    private fun createAnnouncement(message: RemoteMessage) {
        i { "Received request to create announcement notification" }

        val notification = factory.createBasicNotification()
                .setContentTitle(message.data["Title"])
                .setContentText(message.data["Text"])

        factory.broadcastNotification(notification)
    }

    private fun createHighPriorityAnnouncement(message: RemoteMessage) {
        i { "Received request to make high priority announcement" }

        val notification = factory.createBasicNotification()
                .setContentTitle(message.data["Title"])
                .setContentText(message.data["Text"])

        factory.broadcastNotification(factory.makeHighPriority(notification))
    }
}<commit_msg>docs(pushService): add logging for events<commit_after>package org.eurofurence.connavigator.gcm

import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.pawegio.kandroid.d
import com.pawegio.kandroid.i
import com.pawegio.kandroid.w
import org.eurofurence.connavigator.BuildConfig
import org.eurofurence.connavigator.database.UpdateIntentService
import org.jetbrains.anko.*

/**
 * Created by David on 14-4-2016.
 */
class PushListenerService : FirebaseMessagingService(), AnkoLogger {
    val factory by lazy { NotificationFactory(applicationContext) }

    fun subscribe() {
        val messaging = FirebaseMessaging.getInstance()
        if (BuildConfig.DEBUG) {
            messaging.subscribeToTopic("test")
        }
        messaging.subscribeToTopic("announcements")
    }

    override fun onMessageReceived(message: RemoteMessage) {
        info { "Received push message" }
        debug { "Message payload :" + message.data }

        when (message.data["Event"]) {
            "Announcement" -> createAnnouncement(message)
            "ImportantAnnouncement" -> createHighPriorityAnnouncement(message)
            "Sync" -> syncData(message)
            else -> warn("Message did not contain a valid event. Abandoning!")
        }


    }

    private fun syncData(message: RemoteMessage) {
        info { "Received request to sync data" }

        applicationContext.sendBroadcast(intentFor<UpdateIntentService>())
    }

    private fun createAnnouncement(message: RemoteMessage) {
        info { "Received request to create announcement notification" }

        val notification = factory.createBasicNotification()
                .setContentTitle(message.data["Title"])
                .setContentText(message.data["Text"])

        factory.broadcastNotification(notification)
    }

    private fun createHighPriorityAnnouncement(message: RemoteMessage) {
        info { "Received request to make high priority announcement" }

        val notification = factory.createBasicNotification()
                .setContentTitle(message.data["Title"])
                .setContentText(message.data["Text"])

        factory.broadcastNotification(factory.makeHighPriority(notification))
    }
}
{'fraction_non_alphanumeric': 0.09332173156406352, 'fraction_numerical': 0.0030454644333260824, 'mean_word_length': 3.281191806331471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '831944', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1176, 'n_words': 239}