[Feedback] Hide notification when feedback is open. Fix mixing messages when a thread is open.

This commit is contained in:
Kuba Szczodrzyński 2020-02-09 15:10:03 +01:00
parent bcf3fef303
commit 37ddd643ac
2 changed files with 21 additions and 14 deletions

View File

@ -74,18 +74,20 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
} }
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
app.db.feedbackMessageDao().add(message) app.db.feedbackMessageDao().add(message)
val notification = Notification( if (!EventBus.getDefault().hasSubscriberForEvent(FeedbackMessageEvent::class.java)) {
id = System.currentTimeMillis(), val notification = Notification(
title = "Wiadomość od ${message.senderName}", id = System.currentTimeMillis(),
text = message.text, title = "Wiadomość od ${message.senderName}",
type = Notification.TYPE_FEEDBACK_MESSAGE, text = message.text,
profileId = null, type = Notification.TYPE_FEEDBACK_MESSAGE,
profileName = "Wiadomość od ${message.senderName}" profileId = null,
).addExtra("action", "feedbackMessage").addExtra("feedbackMessageDeviceId", message.deviceId) profileName = "Wiadomość od ${message.senderName}"
app.db.notificationDao().add(notification) ).addExtra("action", "feedbackMessage").addExtra("feedbackMessageDeviceId", message.deviceId)
PostNotifications(app, listOf(notification)) app.db.notificationDao().add(notification)
PostNotifications(app, listOf(notification))
}
EventBus.getDefault().postSticky(FeedbackMessageEvent(message))
} }
EventBus.getDefault().postSticky(FeedbackMessageEvent(message))
} }
private fun sharedEvent(teamCode: String, jsonStr: String, message: String) { private fun sharedEvent(teamCode: String, jsonStr: String, message: String) {

View File

@ -70,9 +70,14 @@ class FeedbackFragment : Fragment(), CoroutineScope {
fun onFeedbackMessageEvent(event: FeedbackMessageEvent) { fun onFeedbackMessageEvent(event: FeedbackMessageEvent) {
EventBus.getDefault().removeStickyEvent(event) EventBus.getDefault().removeStickyEvent(event)
val message = event.message val message = event.message
val chatMessage = getChatMessage(message) if (currentDeviceId != null && message.deviceId == currentDeviceId) {
if (message.received) chatView.receive(chatMessage) val chatMessage = getChatMessage(message)
else chatView.send(chatMessage) if (message.received) chatView.receive(chatMessage)
else chatView.send(chatMessage)
}
else {
Toast.makeText(context, "${message.senderName}: Nowa wiadomość w innym wątku.", Toast.LENGTH_LONG).show()
}
} }
private val users = mutableMapOf( private val users = mutableMapOf(