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)));
}
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)));
}
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);
}
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("");
}
}
Aggregations