forked from github/szkolny
[Messages] Fix opening messages.
This commit is contained in:
parent
03c9932b8c
commit
91a6366548
@ -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)
|
||||
}
|
||||
|
@ -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 ->
|
||||
|
@ -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
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user