mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[Messages] Fix multiplied recipients with more than one profile.
This commit is contained in:
parent
6611fc5843
commit
83daae46b8
@ -146,25 +146,34 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
else
|
else
|
||||||
app.db.messageDao().getByIdNow(App.profileId, messageId)
|
app.db.messageDao().getByIdNow(App.profileId, messageId)
|
||||||
|
|
||||||
|
if (msg == null)
|
||||||
|
return@withContext null
|
||||||
|
|
||||||
|
// make recipients ID-unique
|
||||||
|
// this helps when multiple profiles receive the same message
|
||||||
|
// (there are multiple -1 recipients for the same message ID)
|
||||||
|
val recipientsDistinct =
|
||||||
|
msg.recipients?.distinctBy { it.id } ?: return@withContext null
|
||||||
|
msg.recipients?.clear()
|
||||||
|
msg.recipients?.addAll(recipientsDistinct)
|
||||||
|
|
||||||
// load recipients in sent messages
|
// load recipients in sent messages
|
||||||
val teachers by lazy { app.db.teacherDao().getAllNow(App.profileId) }
|
val teachers by lazy { app.db.teacherDao().getAllNow(App.profileId) }
|
||||||
msg?.recipients?.forEach { recipient ->
|
msg.recipients?.forEach { recipient ->
|
||||||
if (recipient.fullName == null) {
|
if (recipient.fullName == null) {
|
||||||
recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
|
recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg?.type == TYPE_SENT && msg.senderName == null) {
|
if (msg.type == TYPE_SENT && msg.senderName == null) {
|
||||||
msg.senderName = app.profile.accountName ?: app.profile.studentNameLong
|
msg.senderName = app.profile.accountName ?: app.profile.studentNameLong
|
||||||
}
|
}
|
||||||
|
|
||||||
msg?.also {
|
//msg.recipients = app.db.messageRecipientDao().getAllByMessageId(msg.profileId, msg.id)
|
||||||
//it.recipients = app.db.messageRecipientDao().getAllByMessageId(it.profileId, it.id)
|
if (msg.body != null && !msg.seen) {
|
||||||
if (it.body != null && !it.seen) {
|
app.db.metadataDao().setSeen(msg.profileId, msg, true)
|
||||||
app.db.metadataDao().setSeen(it.profileId, it, true)
|
|
||||||
}
|
}
|
||||||
}
|
return@withContext msg
|
||||||
|
|
||||||
} ?: run {
|
} ?: run {
|
||||||
activity.navigateUp()
|
activity.navigateUp()
|
||||||
return@launch
|
return@launch
|
||||||
|
Loading…
Reference in New Issue
Block a user