Skip to content

Commit

Permalink
organizer is responsible for sorting attendee list before sending + v…
Browse files Browse the repository at this point in the history
…erifying list is sorted when displaying (organizer or attendee) + keeping order of attendees list as received
  • Loading branch information
Kaz-ookid committed Jun 3, 2024
1 parent 94f1e76 commit c8e7e38
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class RollCallBuilder {
}

fun setAttendees(attendees: Set<PublicKey>): RollCallBuilder {
this.attendees = HashSet(attendees)
this.attendees = LinkedHashSet(attendees)
return this
}

fun setEmptyAttendees(): RollCallBuilder {
attendees = HashSet()
attendees = LinkedHashSet()
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class RollCallArrayAdapter(
private val myToken: PoPToken?,
) : ArrayAdapter<String>(context, layout, attendeesList) {

init {
RollCallFragment.isAttendeeListSorted(attendeesList, context)
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.dedis.popstellar.ui.lao.event.rollcall

import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Bundle
Expand All @@ -9,6 +10,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.lifecycle.MutableLiveData
import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.databinding.RollCallFragmentBinding
import com.github.dedis.popstellar.model.objects.RollCall
Expand Down Expand Up @@ -253,6 +256,7 @@ class RollCallFragment : AbstractEventFragment {
.getAttendees()
.stream()
.map(PublicKey::encoded)
.sorted(compareBy(String::toString))
.collect(Collectors.toList())

binding.rollCallAttendeesText.text =
Expand Down Expand Up @@ -342,17 +346,27 @@ class RollCallFragment : AbstractEventFragment {

companion object {
val TAG: String = RollCallFragment::class.java.simpleName
private val deAnonymizationWarned = MutableLiveData(false)

@JvmStatic
fun newInstance(persistentId: String?): RollCallFragment {
deAnonymizationWarned.value = false
val fragment = RollCallFragment()
val bundle = Bundle(1)
bundle.putString(ROLL_CALL_ID, persistentId)
fragment.arguments = bundle

return fragment
}

fun isAttendeeListSorted(attendeesList: List<String>, context: Context): Boolean {
if (attendeesList != attendeesList.sorted() && deAnonymizationWarned.value == false) {
deAnonymizationWarned.value = true
logAndShow(context, TAG, R.string.roll_call_attendees_list_not_sorted)
return false
}
return true
}

/**
* The following is only for testing purposes. Production should never pass arguments to a
* fragment instantiation but should rather use arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import io.reactivex.Completable
import io.reactivex.Observable
import io.reactivex.Single
import java.time.Instant
import java.util.TreeSet
import java.util.stream.Collectors
import javax.inject.Inject
import timber.log.Timber
import java.util.TreeSet

@HiltViewModel
class RollCallViewModel
Expand All @@ -53,7 +53,7 @@ constructor(
) : AndroidViewModel(application), QRCodeScanningViewModel {
private lateinit var laoId: String

private val attendees: TreeSet<PublicKey> = TreeSet(Comparator.comparing { it.toString() })
private val attendees: TreeSet<PublicKey> = TreeSet(compareBy { it.toString() })
override val nbScanned = MutableLiveData<Int>()
lateinit var attendedRollCalls: Observable<List<RollCall>>
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,23 @@ constructor(
val updateId = closeRollCall.updateId
val closes = closeRollCall.closes
val existingRollCall = rollCallRepo.getRollCallWithId(laoView.id, closes)
val currentAttendees = existingRollCall.attendees
currentAttendees.addAll(closeRollCall.attendees)

val currentAttendees: Set<PublicKey>
if (closeRollCall.attendees.containsAll(existingRollCall.attendees)) {
// closeRollCall.attendees is sorted, so we prefer to use it if we can
currentAttendees = closeRollCall.attendees.toMutableSet()
} else {
// if both lists have different attendees, we merge them even though we lose the order
// We are not ordering it because it is important to keep the order that we received to know if we face de-anonymization
currentAttendees = existingRollCall.attendees
currentAttendees.addAll(closeRollCall.attendees)
}

// log existingRollCall.attendees and closeRollCall.attendees
Timber.tag(TAG).d("existingRollCall.attendees: %s", existingRollCall.attendees)
Timber.tag(TAG).d("closeRollCall.attendees: %s", closeRollCall.attendees)
// log currentAttendees
Timber.tag(TAG).d("currentAttendees: %s", currentAttendees)

val builder = RollCallBuilder()
builder
Expand All @@ -142,7 +157,6 @@ constructor(
.setEnd(closeRollCall.closedAt)
val laoId = laoView.id
val rollCall = builder.build()

witnessingRepo.addWitnessMessage(laoId, closeRollCallWitnessMessage(messageId, rollCall))
if (witnessingRepo.areWitnessesEmpty(laoId)) {
addRollCallRoutine(rollCallRepo, digitalCashRepo, laoId, rollCall)
Expand Down
2 changes: 2 additions & 0 deletions fe2-android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
<string name="roll_call_scanned">Scanned tokens : %1$d</string>
<string name="roll_call_description_title">Description</string>
<string name="roll_call_location_title">Location</string>
<string name="roll_call_attendees_list_not_sorted">Attendees list is not sorted, risk of de-anonymization</string>


<!-- Meeting -->
<string name="meeting_title">Meeting</string>
Expand Down

0 comments on commit c8e7e38

Please sign in to comment.