[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, VULCAN_HEBE_ENDPOINT_MESSAGEBOX,
lastSync = lastSync lastSync = lastSync
) { list, _ -> ) { list, _ ->
var found = false
for (messageBox in list) { for (messageBox in list) {
val name = messageBox.getString("Name") ?: continue val name = messageBox.getString("Name") ?: continue
val studentName = profile?.studentNameLong ?: continue val studentName = profile?.studentNameLong ?: continue
if (!name.startsWith(studentName)) if (!name.contains(studentName))
continue continue
data.messageBoxKey = messageBox.getString("GlobalKey") data.messageBoxKey = messageBox.getString("GlobalKey")
data.messageBoxName = name data.messageBoxName = name
found = true
break 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) data.setSyncNext(ENDPOINT_VULCAN_HEBE_MESSAGE_BOXES, 7 * DAY)
onSuccess(ENDPOINT_VULCAN_HEBE_MESSAGE_BOXES) onSuccess(ENDPOINT_VULCAN_HEBE_MESSAGE_BOXES)
} }

View File

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

View File

@ -24,7 +24,7 @@ class VulcanHebeMessagesChangeStatus(
} }
init { let { 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)) EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
onSuccess() onSuccess()
return@let return@let