From 91a636654842bc14d1a113d944215d75ee5b3868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 4 Apr 2020 23:14:40 +0200 Subject: [PATCH] [Messages] Fix opening messages. --- .../ui/modules/messages/MessageFragment.kt | 18 +++++++++++++++--- .../modules/messages/MessagesListFragment.kt | 4 +++- .../compose/MessagesComposeFragment.kt | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt index 14693cb8..35e19c67 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt @@ -123,14 +123,26 @@ class MessageFragment : Fragment(), CoroutineScope { val msg = if (messageString != null) app.gson.fromJson(messageString, MessageFull::class.java)?.also { - //it.body = null - it.addedDate = arguments?.getLong("sentDate") ?: System.currentTimeMillis() + if (arguments?.getLong("sentDate") ?: 0L > 0L) + it.addedDate = arguments?.getLong("sentDate") ?: 0L } else app.db.messageDao().getByIdNow(App.profileId, messageId) + // load recipients in sent messages + val teachers by lazy { app.db.teacherDao().getAllNow(App.profileId) } + msg?.recipients?.forEach { recipient -> + if (recipient.fullName == null) { + recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: "" + } + } + + if (msg?.type == TYPE_SENT && msg.senderName == null) { + msg.senderName = app.profile.accountName ?: app.profile.studentNameLong + } + msg?.also { - it.recipients = app.db.messageRecipientDao().getAllByMessageId(it.profileId, it.id) + //it.recipients = app.db.messageRecipientDao().getAllByMessageId(it.profileId, it.id) if (it.body != null && !it.seen) { app.db.metadataDao().setSeen(it.profileId, it, true) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesListFragment.kt index 127bf017..de9a0c60 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesListFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessagesListFragment.kt @@ -55,7 +55,9 @@ class MessagesListFragment : LazyFragment(), CoroutineScope { } val adapter = MessagesAdapter(activity, teachers) { - + activity.loadTarget(MainActivity.TARGET_MESSAGES_DETAILS, Bundle( + "messageId" to it.id + )) } app.db.messageDao().getAllByType(App.profileId, messageType).observe(this@MessagesListFragment, Observer { items -> diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt index 819978c1..96898871 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/compose/MessagesComposeFragment.kt @@ -505,7 +505,7 @@ class MessagesComposeFragment : Fragment(), CoroutineScope { activity.snackbar(app.getString(R.string.messages_sent_success), app.getString(R.string.ok)) activity.loadTarget(MainActivity.TARGET_MESSAGES_DETAILS, Bundle( - "messageId" to (event.message.id ?: -1), + "messageId" to event.message.id, "message" to app.gson.toJson(event.message), "sentDate" to event.sentDate ))