Search in sources :

Example 36 with Channel

use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.

the class LaoDetailViewModel method dispatchLaoUpdate.

/**
 * Helper method for updateLaoWitnesses and updateLaoName to send a stateLao message
 */
private void dispatchLaoUpdate(String desc, UpdateLao updateLao, Lao lao, Channel channel, MessageGeneral msg) {
    StateLao stateLao = new StateLao(updateLao.getId(), updateLao.getName(), lao.getCreation(), updateLao.getLastModified(), lao.getOrganizer(), msg.getMessageId(), updateLao.getWitnesses(), new ArrayList<>());
    disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, stateLao).subscribe(() -> Log.d(TAG, "updated " + desc), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_state_lao)));
}
Also used : PackageManager(android.content.pm.PackageManager) HomeViewModel(com.github.dedis.popstellar.ui.home.HomeViewModel) NonNull(androidx.annotation.NonNull) ElectionEnd(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionEnd) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) LiveDataReactiveStreams(androidx.lifecycle.LiveDataReactiveStreams) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Manifest(android.Manifest) GeneralSecurityException(java.security.GeneralSecurityException) Lao(com.github.dedis.popstellar.model.objects.Lao) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) Transformations(androidx.lifecycle.Transformations) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) ConsensusElect(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect) KeyManager(com.github.dedis.popstellar.utility.security.KeyManager) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Set(java.util.Set) ElectionVote(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionVote) KeyGenerationException(com.github.dedis.popstellar.utility.error.keys.KeyGenerationException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ElectionSetup(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionSetup) HiltViewModel(dagger.hilt.android.lifecycle.HiltViewModel) Objects(java.util.Objects) ScanningAction(com.github.dedis.popstellar.ui.qrcode.ScanningAction) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Stream(java.util.stream.Stream) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) Application(android.app.Application) RollCall(com.github.dedis.popstellar.model.objects.RollCall) Optional(java.util.Optional) SingleEvent(com.github.dedis.popstellar.SingleEvent) Wallet(com.github.dedis.popstellar.model.objects.Wallet) CameraPermissionViewModel(com.github.dedis.popstellar.ui.qrcode.CameraPermissionViewModel) MutableLiveData(androidx.lifecycle.MutableLiveData) R(com.github.dedis.popstellar.R) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) EventType(com.github.dedis.popstellar.model.objects.event.EventType) EventState(com.github.dedis.popstellar.model.objects.event.EventState) ErrorUtils(com.github.dedis.popstellar.utility.error.ErrorUtils) Signature(com.github.dedis.popstellar.model.objects.security.Signature) ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) LAORepository(com.github.dedis.popstellar.repository.LAORepository) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) UninitializedWalletException(com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Toast(android.widget.Toast) AndroidViewModel(androidx.lifecycle.AndroidViewModel) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) WitnessMessageSignature(com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature) LiveData(androidx.lifecycle.LiveData) Channel(com.github.dedis.popstellar.model.objects.Channel) BackpressureStrategy(io.reactivex.BackpressureStrategy) Election(com.github.dedis.popstellar.model.objects.Election) CastVote(com.github.dedis.popstellar.model.network.method.message.data.election.CastVote) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) Barcode(com.google.android.gms.vision.barcode.Barcode) QRCodeScanningViewModel(com.github.dedis.popstellar.ui.qrcode.QRCodeScanningViewModel) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) VisibleForTesting(androidx.annotation.VisibleForTesting) GlobalNetworkManager(com.github.dedis.popstellar.repository.remote.GlobalNetworkManager) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)

Example 37 with Channel

use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.

the class HomeViewModel method launchLao.

/**
 * launchLao is invoked when the user tries to create a new LAO. The method creates a `CreateLAO`
 * message and publishes it to the root channel. It observers the response in the background and
 * switches to the home screen on success.
 */
public void launchLao() {
    String laoName = mLaoName.getValue();
    Log.d(TAG, "creating lao with name " + laoName);
    CreateLao createLao = new CreateLao(laoName, keyManager.getMainPublicKey());
    disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), Channel.ROOT, createLao).subscribe(() -> {
        Log.d(TAG, "got success result for create lao");
        // Create new LAO and add it to the LAORepository LAO lists
        Lao lao = new Lao(createLao.getId());
        laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
        laoRepository.setAllLaoSubject();
        // Send subscribe and catchup after creating a LAO
        networkManager.getMessageSender().subscribe(lao.getChannel()).subscribe();
        openHome();
    }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_create_lao)));
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) JsonParseException(com.google.gson.JsonParseException) R(com.github.dedis.popstellar.R) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) ErrorUtils(com.github.dedis.popstellar.utility.error.ErrorUtils) SeedValidationException(com.github.dedis.popstellar.utility.error.keys.SeedValidationException) LiveDataReactiveStreams(androidx.lifecycle.LiveDataReactiveStreams) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Inject(javax.inject.Inject) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) Manifest(android.Manifest) GeneralSecurityException(java.security.GeneralSecurityException) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) Gson(com.google.gson.Gson) Toast(android.widget.Toast) AndroidViewModel(androidx.lifecycle.AndroidViewModel) Log(android.util.Log) LiveData(androidx.lifecycle.LiveData) Channel(com.github.dedis.popstellar.model.objects.Channel) BackpressureStrategy(io.reactivex.BackpressureStrategy) KeyManager(com.github.dedis.popstellar.utility.security.KeyManager) ActivityCompat(androidx.core.app.ActivityCompat) LAOState(com.github.dedis.popstellar.repository.LAOState) Barcode(com.google.android.gms.vision.barcode.Barcode) HiltViewModel(dagger.hilt.android.lifecycle.HiltViewModel) QRCodeScanningViewModel(com.github.dedis.popstellar.ui.qrcode.QRCodeScanningViewModel) ScanningAction(com.github.dedis.popstellar.ui.qrcode.ScanningAction) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Application(android.app.Application) SingleEvent(com.github.dedis.popstellar.SingleEvent) Wallet(com.github.dedis.popstellar.model.objects.Wallet) GlobalNetworkManager(com.github.dedis.popstellar.repository.remote.GlobalNetworkManager) CameraPermissionViewModel(com.github.dedis.popstellar.ui.qrcode.CameraPermissionViewModel) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) LAOState(com.github.dedis.popstellar.repository.LAOState) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao)

Example 38 with Channel

use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.

the class ChirpHandler method handleChirpAdd.

/**
 * Process an AddChirp message.
 *
 * @param context the HandlerContext of the message
 * @param addChirp the data of the message that was received
 */
public static void handleChirpAdd(HandlerContext context, AddChirp addChirp) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    PublicKey senderPk = context.getSenderPk();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Chirp chirp = new Chirp(messageId);
    chirp.setChannel(channel);
    chirp.setSender(senderPk);
    chirp.setText(addChirp.getText());
    chirp.setTimestamp(addChirp.getTimestamp());
    chirp.setParentId(addChirp.getParentId().orElse(new MessageID("")));
    lao.updateAllChirps(messageId, chirp);
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 39 with Channel

use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.

the class ChirpHandler method handleDeleteChirp.

/**
 * process a DeleteChirp message.
 *
 * @param context the HandlerContext of the message
 * @param deleteChirp the data of the message that was received
 */
public static void handleDeleteChirp(HandlerContext context, DeleteChirp deleteChirp) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Optional<Chirp> chirpOptional = lao.getChirp(deleteChirp.getChirpId());
    Chirp chirp;
    if (!chirpOptional.isPresent()) {
        throw new InvalidMessageIdException(deleteChirp, deleteChirp.getChirpId());
    }
    chirp = chirpOptional.get();
    if (chirp.getIsDeleted()) {
        Log.d(TAG, "The chirp is already deleted");
    } else {
        chirp.setIsDeleted(true);
        chirp.setText("");
    }
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidMessageIdException(com.github.dedis.popstellar.utility.error.InvalidMessageIdException) Lao(com.github.dedis.popstellar.model.objects.Lao)

Aggregations

Channel (com.github.dedis.popstellar.model.objects.Channel)39 Lao (com.github.dedis.popstellar.model.objects.Lao)30 LAORepository (com.github.dedis.popstellar.repository.LAORepository)28 Disposable (io.reactivex.disposables.Disposable)19 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)17 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)16 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)14 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)14 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)13 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)10 GenericMessage (com.github.dedis.popstellar.model.network.GenericMessage)8 Error (com.github.dedis.popstellar.model.network.answer.Error)8 ResultMessages (com.github.dedis.popstellar.model.network.answer.ResultMessages)8 Catchup (com.github.dedis.popstellar.model.network.method.Catchup)8 Publish (com.github.dedis.popstellar.model.network.method.Publish)8 Query (com.github.dedis.popstellar.model.network.method.Query)8 Subscribe (com.github.dedis.popstellar.model.network.method.Subscribe)8 Unsubscribe (com.github.dedis.popstellar.model.network.method.Unsubscribe)8 Data (com.github.dedis.popstellar.model.network.method.message.data.Data)8 JsonRPCErrorException (com.github.dedis.popstellar.utility.error.JsonRPCErrorException)8