-
Notifications
You must be signed in to change notification settings - Fork 732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Account Data with user matrix id for invited user by email #3743
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update the AccountData with the users' matrix Id instead of their email for those invited by email in a direct chat |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,54 @@ | |
|
||
package org.matrix.android.sdk.internal.session.sync | ||
|
||
import org.matrix.android.sdk.api.MatrixPatterns | ||
import org.matrix.android.sdk.internal.session.sync.model.accountdata.toMutable | ||
import org.matrix.android.sdk.internal.session.user.accountdata.DirectChatsHelper | ||
import org.matrix.android.sdk.internal.session.user.accountdata.UpdateUserAccountDataTask | ||
import javax.inject.Inject | ||
|
||
internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor( | ||
private val ephemeralTemporaryStore: RoomSyncEphemeralTemporaryStore | ||
private val directChatsHelper: DirectChatsHelper, | ||
private val ephemeralTemporaryStore: RoomSyncEphemeralTemporaryStore, | ||
private val updateUserAccountDataTask: UpdateUserAccountDataTask | ||
) { | ||
fun handle(synResHaResponsePostTreatmentAggregator: SyncResponsePostTreatmentAggregator) { | ||
suspend fun handle(synResHaResponsePostTreatmentAggregator: SyncResponsePostTreatmentAggregator) { | ||
cleanupEphemeralFiles(synResHaResponsePostTreatmentAggregator.ephemeralFilesToDelete) | ||
updateDirectUserIds(synResHaResponsePostTreatmentAggregator.directChatsToCheck) | ||
} | ||
|
||
private fun cleanupEphemeralFiles(ephemeralFilesToDelete: List<String>) { | ||
ephemeralFilesToDelete.forEach { | ||
ephemeralTemporaryStore.delete(it) | ||
} | ||
} | ||
|
||
private suspend fun updateDirectUserIds(directUserIdsToUpdate: Map<String, String>) { | ||
val directChats = directChatsHelper.getLocalDirectMessages().toMutable() | ||
var hasUpdate = false | ||
directUserIdsToUpdate.forEach { (roomId, candidateUserId) -> | ||
// consider room is a DM if referenced in the DM dictionary | ||
val currentDirectUserId = directChats.firstNotNullOfOrNull { (userId, roomIds) -> userId.takeIf { roomId in roomIds } } | ||
// update directUserId with the given candidateUserId if it mismatches the current one | ||
if (currentDirectUserId != null && !MatrixPatterns.isUserId(currentDirectUserId)) { | ||
// link roomId with the matrix id | ||
directChats | ||
.getOrPut(candidateUserId) { arrayListOf() } | ||
.apply { | ||
if (!contains(roomId)) { | ||
hasUpdate = true | ||
add(roomId) | ||
} | ||
} | ||
|
||
// remove roomId from currentDirectUserId entry | ||
hasUpdate = hasUpdate or(directChats[currentDirectUserId]?.remove(roomId) == true) | ||
// remove currentDirectUserId entry if there is no attached room anymore | ||
hasUpdate = hasUpdate or(directChats.takeIf { it[currentDirectUserId].isNullOrEmpty() }?.remove(currentDirectUserId) != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer, If I remove a key from the directChats dictionary, I also want to edit this flag in order to update the accountData with the updated dictionary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop, in that case, remove returns the removed object, if any or null otherwise |
||
} | ||
} | ||
if (hasUpdate) { | ||
updateUserAccountDataTask.execute(UpdateUserAccountDataTask.DirectChatParams(directMessages = directChats)) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to assign
hasUpdate
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the
remove
method will modify the direct chat dictionary if the given item has been found and removed, so I want to edit this flag in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I was wondering if
hasUpdate
was not already equal to true in this case. It can maybe add some cleanup on some existing account data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I understand now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand, I use the
or
function which will always call the second part of the operation (whether hasUpdate is true or not). The flag should be updated for each modification in the direct chats dictionary. In our case, the cleanup will be performed only for members related to the givendirectUserIdsToUpdate
dictionary.