[API/Vulcan] Fix getting MessageBoxes and changing message read status.

This commit is contained in:
Kuba Szczodrzyński 2022-09-21 20:43:18 +02:00
parent cdc0c9d458
commit 7711413b30
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
3 changed files with 12 additions and 5 deletions

View File

@ -26,16 +26,24 @@ class VulcanHebeMessageBoxes(
VULCAN_HEBE_ENDPOINT_MESSAGEBOX,
lastSync = lastSync
) { list, _ ->
var found = false
for (messageBox in list) {
val name = messageBox.getString("Name") ?: continue
val studentName = profile?.studentNameLong ?: continue
if (!name.startsWith(studentName))
if (!name.contains(studentName))
continue
data.messageBoxKey = messageBox.getString("GlobalKey")
data.messageBoxName = name
found = true
break
}
if (!found && list.isNotEmpty()) {
list.firstOrNull()?.let { messageBox ->
data.messageBoxKey = messageBox.getString("GlobalKey")
data.messageBoxName = messageBox.getString("Name")
}
}
data.setSyncNext(ENDPOINT_VULCAN_HEBE_MESSAGE_BOXES, 7 * DAY)
onSuccess(ENDPOINT_VULCAN_HEBE_MESSAGE_BOXES)
}

View File

@ -98,9 +98,6 @@ class VulcanHebeMessages(
val receivers = message.getJsonArray("Receiver")
?.asJsonObjectList()
?: return@forEach
val receiverReadDate =
if (receivers.size == 1) readDate
else -1
for (receiver in receivers) {
val recipientId = if (messageType == TYPE_SENT)
@ -108,6 +105,8 @@ class VulcanHebeMessages(
else
-1
val receiverReadDate = receiver.getLong("HasRead", -1)
val messageRecipientObject = MessageRecipient(
profileId,
recipientId,

View File

@ -24,7 +24,7 @@ class VulcanHebeMessagesChangeStatus(
}
init { let {
val messageKey = messageObject.body?.let { data.parseMessageMeta(it) }?.get("globalKey") ?: run {
val messageKey = messageObject.body?.let { data.parseMessageMeta(it) }?.get("uuid") ?: run {
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
onSuccess()
return@let