add query param for private msgs
This commit is contained in:
@ -468,6 +468,8 @@ pub struct PrivateContext {
|
||||
pub sbot_status: Option<SbotStatus>,
|
||||
// local peer id (whoami)
|
||||
pub id: Option<String>,
|
||||
// id of the peer being messaged
|
||||
pub recipient_id: Option<String>,
|
||||
}
|
||||
|
||||
impl PrivateContext {
|
||||
@ -481,10 +483,11 @@ impl PrivateContext {
|
||||
sbot_config: None,
|
||||
sbot_status: None,
|
||||
id: None,
|
||||
recipient_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build() -> Result<Self, PeachWebError> {
|
||||
pub async fn build(recipient_id: Option<String>) -> Result<Self, PeachWebError> {
|
||||
let mut context = Self::default();
|
||||
|
||||
// retrieve current ui theme
|
||||
@ -500,6 +503,8 @@ impl PrivateContext {
|
||||
|
||||
let mut sbot_client = init_sbot_with_config(&sbot_config).await?;
|
||||
|
||||
context.recipient_id = recipient_id;
|
||||
|
||||
let local_id = sbot_client.whoami().await?;
|
||||
context.id = Some(local_id);
|
||||
} else {
|
||||
|
@ -102,10 +102,19 @@ pub async fn create_invite(invite: Form<Invite>, _auth: Authenticated) -> Flash<
|
||||
// HELPERS AND ROUTES FOR /private
|
||||
|
||||
/// A private message composition and publication page.
|
||||
#[get("/private")]
|
||||
pub async fn private(flash: Option<FlashMessage<'_>>, _auth: Authenticated) -> Template {
|
||||
#[get("/private?<public_key>")]
|
||||
pub async fn private(
|
||||
mut public_key: Option<String>,
|
||||
flash: Option<FlashMessage<'_>>,
|
||||
_auth: Authenticated,
|
||||
) -> Template {
|
||||
if let Some(ref key) = public_key {
|
||||
// `url_decode` replaces '+' with ' ', so we need to revert that
|
||||
public_key = Some(key.replace(' ', "+"));
|
||||
}
|
||||
|
||||
// build the private context object
|
||||
let context = PrivateContext::build().await;
|
||||
let context = PrivateContext::build(public_key).await;
|
||||
|
||||
match context {
|
||||
// we were able to build the context without errors
|
||||
@ -141,7 +150,7 @@ pub struct Private {
|
||||
/// Publish a private message.
|
||||
#[post("/private", data = "<private>")]
|
||||
pub async fn private_post(private: Form<Private>, _auth: Authenticated) -> Flash<Redirect> {
|
||||
let url = uri!("/scuttlebutt", private);
|
||||
let url = uri!("/scuttlebutt", private(None::<String>));
|
||||
|
||||
// retrieve go-sbot systemd process status
|
||||
let sbot_status = match SbotStatus::read() {
|
||||
|
@ -6,10 +6,10 @@
|
||||
<div class="capsule capsule-profile border-ssb" title="Scuttlebutt account profile information">
|
||||
<div class="center" style="display: flex; flex-direction: column; margin-bottom: 2rem;" title="Public key (ID) of the peer being written to">
|
||||
<label for="publicKey" class="label-small font-gray">PUBLIC KEY</label>
|
||||
<input type="text" id="publicKey" name="recipient" placeholder="@xYz...=.ed25519" autofocus>
|
||||
<input type="text" id="publicKey" name="recipient" placeholder="@xYz...=.ed25519" {% if recipient_id %}value="{{ recipient_id }}"{% else %}autofocus{% endif %}>
|
||||
</div>
|
||||
<!-- input for message contents -->
|
||||
<textarea id="privatePost" class="center input message-input" name="text" title="Compose a private message" placeholder="Write a private message..."></textarea>
|
||||
<textarea id="privatePost" class="center input message-input" name="text" title="Compose a private message" placeholder="Write a private message..."{% if recipient_id %} autofocus{% endif %}></textarea>
|
||||
<!-- hidden input field to pass the public key of the local peer -->
|
||||
<input type="hidden" id="localId" name="id" value="{{ id }}">
|
||||
</div>
|
||||
|
@ -63,7 +63,7 @@
|
||||
{% else %}
|
||||
<p>Unable to determine block state</p>
|
||||
{% endif %}
|
||||
<a id="privateMessage" class="button button-primary center" href="/scuttlebutt/private_message" title="Private Message">Send Private Message</a>
|
||||
<a id="privateMessage" class="button button-primary center" href="/scuttlebutt/private?public_key={{ id }}" title="Private Message">Send Private Message</a>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
|
Reference in New Issue
Block a user