use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LaoDetailViewModel method closeRollCall.
/**
* Closes the roll call event currently open
*
* <p>Publish a GeneralMessage containing CloseRollCall data.
*/
public void closeRollCall(int nextFragment) {
Log.d(TAG, "call closeRollCall");
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
long end = Instant.now().getEpochSecond();
Channel channel = lao.getChannel();
CloseRollCall closeRollCall = new CloseRollCall(lao.getId(), currentRollCallId, end, new ArrayList<>(attendees));
Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, closeRollCall).subscribe(() -> {
Log.d(TAG, "closed the roll call");
currentRollCallId = "";
attendees.clear();
mCloseRollCallEvent.setValue(new SingleEvent<>(nextFragment));
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_close_rollcall));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LaoDetailViewModel method sendVote.
/**
* Sends a ElectionCastVotes message .
*
* <p>Publish a GeneralMessage containing ElectionCastVotes data.
*
* @param votes the corresponding votes for that election
*/
public void sendVote(List<ElectionVote> votes) {
Election election = mCurrentElection.getValue();
if (election == null) {
Log.d(TAG, "failed to retrieve current election");
return;
}
Log.d(TAG, "sending a new vote in election : " + election + " with election start time" + election.getStartTimestamp());
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
try {
PoPToken token = keyManager.getValidPoPToken(lao);
CastVote castVote = new CastVote(votes, election.getId(), lao.getId());
Channel electionChannel = election.getChannel();
Log.d(TAG, PUBLISH_MESSAGE);
Disposable disposable = networkManager.getMessageSender().publish(token, electionChannel, castVote).doFinally(this::openLaoDetail).subscribe(() -> {
Log.d(TAG, "sent a vote successfully");
// Toast ? + send back to election screen or details screen ?
Toast.makeText(getApplication(), "vote successfully sent !", Toast.LENGTH_LONG).show();
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_send_vote));
disposables.add(disposable);
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
}
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LAONetworkManager method subscribe.
@Override
public Completable subscribe(Channel channel) {
Log.d(TAG, "sending a subscribe on the channel " + channel);
Subscribe subscribe = new Subscribe(channel, requestCounter.incrementAndGet());
return request(subscribe).doOnSuccess(answer -> subscribedChannels.add(channel)).doAfterSuccess(answer -> catchup(channel).subscribe()).ignoreElement();
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LAONetworkManager method unsubscribe.
@Override
public Completable unsubscribe(Channel channel) {
Log.d(TAG, "sending an unsubscribe on the channel " + channel);
Unsubscribe unsubscribe = new Unsubscribe(channel, requestCounter.incrementAndGet());
return request(unsubscribe).doOnSuccess(answer -> subscribedChannels.remove(channel)).ignoreElement();
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LaoDetailViewModel method createNewRollCall.
/**
* Creates new roll call event.
*
* <p>Publish a GeneralMessage containing CreateRollCall data.
*
* @param title the title of the roll call
* @param description the description of the roll call, can be empty
* @param creation the creation time of the roll call
* @param proposedStart the proposed start time of the roll call
* @param proposedEnd the proposed end time of the roll call
* @param open true if we want to directly open the roll call
*/
public void createNewRollCall(String title, String description, long creation, long proposedStart, long proposedEnd, boolean open) {
Log.d(TAG, "creating a new roll call with title " + title);
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
// FIXME Location : Lausanne ?
CreateRollCall createRollCall = new CreateRollCall(title, creation, proposedStart, proposedEnd, "Lausanne", description, lao.getId());
Log.d(TAG, PUBLISH_MESSAGE);
Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, createRollCall).subscribe(() -> {
Log.d(TAG, "created a roll call with id: " + createRollCall.getId());
if (open) {
openRollCall(createRollCall.getId());
} else {
mCreatedRollCallEvent.postValue(new SingleEvent<>(true));
}
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_create_rollcall));
disposables.add(disposable);
}
Aggregations