|
|
|
@ -21,6 +21,7 @@ import org.session.libsession.utilities.getGroup
|
|
|
|
|
import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateInviteMessage
|
|
|
|
|
import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateMessage
|
|
|
|
|
import org.session.libsignal.utilities.AccountId
|
|
|
|
|
import org.session.libsignal.utilities.Log
|
|
|
|
|
|
|
|
|
|
class InviteContactsJob(val groupSessionId: String, val memberSessionIds: Array<String>) : Job {
|
|
|
|
|
|
|
|
|
@ -100,18 +101,31 @@ class InviteContactsJob(val groupSessionId: String, val memberSessionIds: Array<
|
|
|
|
|
val groupName = configs.withGroupConfigs(sessionId) { it.groupInfo.getName() }
|
|
|
|
|
?: configs.getGroup(sessionId)?.name
|
|
|
|
|
|
|
|
|
|
val failures = results.filter { it.second.isFailure }
|
|
|
|
|
// Gather all the exceptions, while keeping track of the invitee account IDs
|
|
|
|
|
val failures = results.mapNotNull { (id, result) ->
|
|
|
|
|
result.exceptionOrNull()?.let { err -> id to err }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if there are failed invites, display a message
|
|
|
|
|
// assume job "success" even if we fail, the state of invites is tracked outside of this job
|
|
|
|
|
if (failures.isNotEmpty()) {
|
|
|
|
|
// show the failure toast
|
|
|
|
|
val toaster = MessagingModuleConfiguration.shared.toaster
|
|
|
|
|
|
|
|
|
|
val (_, firstError) = failures.first()
|
|
|
|
|
|
|
|
|
|
// Add the rest of the exceptions as suppressed
|
|
|
|
|
for ((_, suppressed) in failures.asSequence().drop(1)) {
|
|
|
|
|
firstError.addSuppressed(suppressed)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.w("InviteContactsJob", "Failed to invite contacts", firstError)
|
|
|
|
|
|
|
|
|
|
GroupInviteException(
|
|
|
|
|
isPromotion = false,
|
|
|
|
|
inviteeAccountIds = failures.map { it.first },
|
|
|
|
|
groupName = groupName.orEmpty(),
|
|
|
|
|
underlying = failures.first().second.exceptionOrNull()!!,
|
|
|
|
|
underlying = firstError,
|
|
|
|
|
).format(MessagingModuleConfiguration.shared.context,
|
|
|
|
|
MessagingModuleConfiguration.shared.usernameUtils).let {
|
|
|
|
|
withContext(Dispatchers.Main) {
|
|
|
|
|