use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class LaoDetailViewModel method openRollCall.
/**
* Opens a roll call event.
*
* <p>Publish a GeneralMessage containing OpenRollCall data.
*
* @param id the roll call id to open
*/
public void openRollCall(String id) {
Log.d(TAG, "call openRollCall");
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
long openedAt = Instant.now().getEpochSecond();
Channel channel = lao.getChannel();
String laoId = lao.getId();
Optional<RollCall> optRollCall = lao.getRollCall(id);
if (!optRollCall.isPresent()) {
Log.d(TAG, "failed to retrieve roll call with id " + id + "laoID: " + laoId);
return;
}
RollCall rollCall = optRollCall.get();
OpenRollCall openRollCall = new OpenRollCall(laoId, id, openedAt, rollCall.getState());
attendees = new HashSet<>(rollCall.getAttendees());
try {
attendees.add(keyManager.getPoPToken(lao, rollCall).getPublicKey());
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
}
Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, openRollCall).subscribe(() -> {
Log.d(TAG, "opened the roll call");
currentRollCallId = openRollCall.getUpdateId();
scanningAction = ScanningAction.ADD_ROLL_CALL_ATTENDEE;
openScanning();
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_open_rollcall));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.objects.Lao 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.Lao in project popstellar by dedis.
the class SocialMediaViewModel method isOwner.
/**
* Check whether the sender of a chirp is the current user
*
* @param sender String of the PoPToken PublicKey
* @return true if the sender is the current user
*/
public boolean isOwner(String sender) {
Log.d(TAG, "Testing if the sender is also the owner");
Lao lao = getCurrentLao();
if (lao == null) {
Log.e(TAG, LAO_FAILURE_MESSAGE);
return false;
}
try {
PoPToken token = keyManager.getValidPoPToken(lao);
return sender.equals(token.getPublicKey().getEncoded());
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
return false;
}
}
use of com.github.dedis.popstellar.model.objects.Lao 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.Lao 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);
}
Aggregations