Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livestream chat: use commentron, respect default channel #383

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,18 @@ public void onClick(View view) {
}

if (!Helper.isNullOrEmpty(chatMessage) && Lbry.ownChannels.size() > 0) {
// send chat messages as the first created channel
Claim channel = Lbry.ownChannels.get(0);
// get channel to send chat messages as from set default channel
String defaultChannelName = Helper.getDefaultChannelName(context);
List<Claim> defaultChannel = Lbry.ownChannels
.stream()
.filter(c -> c != null && c.getName().equalsIgnoreCase(defaultChannelName))
.collect(Collectors.toList());
Claim channel;
if (defaultChannel.size() > 0) {
channel = defaultChannel.get(0);
} else {
channel = Lbry.ownChannels.get(0);
}

// if the tip UI is open, then require a valid tip amount to be entered
final boolean shouldTip = layoutLivestreamChatTip.getVisibility() == View.VISIBLE;
Expand Down Expand Up @@ -1779,18 +1789,31 @@ public void run() {
// TODO: show a successful tip message or no?
}

// Channel Sign chat message
JSONObject channelSignParams = new JSONObject();
channelSignParams.put("auth_token", Lbryio.AUTH_TOKEN);
JSONObject jsonChannelSign = Comments.channelSignPrivate(
channelSignParams, channel.getClaimId(),
channel.getName(), chatMessage
);

// Then on to comment creation
Map<String, Object> params = new HashMap<>();
JSONObject params = new JSONObject();
params.put("claim_id", actualClaim.getClaimId());
params.put("channel_id", channel.getClaimId());
params.put("comment", chatMessage);
if (!Helper.isNullOrEmpty(supportTxId)) {
params.put("support_tx_id", supportTxId);
}

Lbry.authenticatedGenericApiCall(Lbry.METHOD_COMMENT_CREATE, params, Lbryio.AUTH_TOKEN);
if (jsonChannelSign.has("signature") && jsonChannelSign.has("signing_ts")) {
params.put("signature", jsonChannelSign.getString("signature"));
params.put("signing_ts", jsonChannelSign.getString("signing_ts"));
}

JSONObject response = (JSONObject) Lbry.parseResponse(Comments.performRequest(params, "comment.Create"));
finishChatSend(true);
} catch (ApiCallException | ClassCastException ex) {
} catch (ApiCallException | LbryResponseException | JSONException | IOException ex) {
showError(getString(R.string.could_not_send_chat_message));
finishChatSend(false);
}
Expand Down