Skip to content

Commit bf84ee4

Browse files
committed
fix: Looks like yerpc doesn't allow me to have optional parameters
1 parent bb83934 commit bf84ee4

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -869,25 +869,31 @@ impl CommandApi {
869869
///
870870
/// See https://securejoin.delta.chat/ for details about both protocols.
871871
///
872-
/// **qr**: The text of the scanned QR code. Typically, the same string as given
873-
/// to `check_qr()`.
874-
///
875-
/// **source** and **uipath** are for statistics-sending,
876-
/// if the user enabled it in the settings;
877-
/// if you don't have statistics-sending implemented, just pass `None` here.
878-
///
879872
/// **returns**: The chat ID of the joined chat, the UI may redirect to the this chat.
880873
/// A returned chat ID does not guarantee that the chat is protected or the belonging contact is verified.
881874
///
882-
async fn secure_join(
875+
async fn secure_join(&self, account_id: u32, qr: String) -> Result<u32> {
876+
let ctx = self.get_context(account_id).await?;
877+
let chat_id = securejoin::join_securejoin(&ctx, &qr).await?;
878+
Ok(chat_id.to_u32())
879+
}
880+
881+
/// Like `secure_join()`, but allows to pass a source and a UI-path.
882+
/// You only need this if your UI has an option to send statistics
883+
/// to Delta Chat's developers.
884+
///
885+
/// **qr**: The text of the scanned QR code. Typically, the same string as given
886+
/// to `check_qr()`.
887+
/// if the user enabled it in the settings;
888+
async fn secure_join_with_ux_info(
883889
&self,
884890
account_id: u32,
885891
qr: String,
886892
source: Option<u32>,
887893
uipath: Option<u32>,
888894
) -> Result<u32> {
889895
let ctx = self.get_context(account_id).await?;
890-
let chat_id = securejoin::join_securejoin_with_source(&ctx, &qr, source, uipath).await?;
896+
let chat_id = securejoin::join_securejoin_with_ux_info(&ctx, &qr, source, uipath).await?;
891897
Ok(chat_id.to_u32())
892898
}
893899

src/securejoin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async fn get_self_fingerprint(context: &Context) -> Result<Fingerprint> {
147147
///
148148
/// The function returns immediately and the handshake will run in background.
149149
pub async fn join_securejoin(context: &Context, qr: &str) -> Result<ChatId> {
150-
join_securejoin_with_source(context, qr, None, None).await
150+
join_securejoin_with_ux_info(context, qr, None, None).await
151151
}
152152

153153
/// Take a scanned QR-code and do the setup-contact/join-group/invite handshake.
@@ -160,7 +160,7 @@ pub async fn join_securejoin(context: &Context, qr: &str) -> Result<ChatId> {
160160
/// **source** and **uipath** are for statistics-sending,
161161
/// if the user enabled it in the settings;
162162
/// if you don't have statistics-sending implemented, just pass `None` here.
163-
pub async fn join_securejoin_with_source(
163+
pub async fn join_securejoin_with_ux_info(
164164
context: &Context,
165165
qr: &str,
166166
source: Option<u32>,
@@ -173,7 +173,7 @@ pub async fn join_securejoin_with_source(
173173
err
174174
})?;
175175

176-
statistics::count_securejoin_source(context, source, uipath)
176+
statistics::count_securejoin_ux_info(context, source, uipath)
177177
.await
178178
.log_err(context)
179179
.ok();

src/statistics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ async fn get_message_stats(
579579
Ok(message_stats)
580580
}
581581

582-
pub(crate) async fn count_securejoin_source(
582+
pub(crate) async fn count_securejoin_ux_info(
583583
context: &Context,
584584
source: Option<u32>,
585585
uipath: Option<u32>,

src/statistics/statistics_tests.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
use crate::chat::{Chat, create_broadcast, create_group_chat, create_group_ex};
55
use crate::mimeparser::SystemMessage;
66
use crate::qr::check_qr;
7-
use crate::securejoin::{get_securejoin_qr, join_securejoin, join_securejoin_with_source};
7+
use crate::securejoin::{get_securejoin_qr, join_securejoin, join_securejoin_with_ux_info};
88
use crate::test_utils::{TestContext, TestContextManager, get_chat_msg};
99
use crate::tools::SystemTime;
1010
use pretty_assertions::assert_eq;
@@ -287,11 +287,12 @@ async fn test_statistics_securejoin_sources() -> Result<()> {
287287
expected.unknown += 1;
288288
check_statistics(alice, &expected).await;
289289

290-
join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None).await?;
290+
join_securejoin_with_ux_info(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None)
291+
.await?;
291292
expected.clipboard += 1;
292293
check_statistics(alice, &expected).await;
293294

294-
join_securejoin_with_source(
295+
join_securejoin_with_ux_info(
295296
alice,
296297
&qr,
297298
Some(SecurejoinSource::ExternalLink as u32),
@@ -301,7 +302,7 @@ async fn test_statistics_securejoin_sources() -> Result<()> {
301302
expected.external_link += 1;
302303
check_statistics(alice, &expected).await;
303304

304-
join_securejoin_with_source(
305+
join_securejoin_with_ux_info(
305306
alice,
306307
&qr,
307308
Some(SecurejoinSource::InternalLink as u32),
@@ -311,20 +312,22 @@ async fn test_statistics_securejoin_sources() -> Result<()> {
311312
expected.internal_link += 1;
312313
check_statistics(alice, &expected).await;
313314

314-
join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::ImageLoaded as u32), None)
315+
join_securejoin_with_ux_info(alice, &qr, Some(SecurejoinSource::ImageLoaded as u32), None)
315316
.await?;
316317
expected.image_loaded += 1;
317318
check_statistics(alice, &expected).await;
318319

319-
join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Scan as u32), None).await?;
320+
join_securejoin_with_ux_info(alice, &qr, Some(SecurejoinSource::Scan as u32), None).await?;
320321
expected.scan += 1;
321322
check_statistics(alice, &expected).await;
322323

323-
join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None).await?;
324+
join_securejoin_with_ux_info(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None)
325+
.await?;
324326
expected.clipboard += 1;
325327
check_statistics(alice, &expected).await;
326328

327-
join_securejoin_with_source(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None).await?;
329+
join_securejoin_with_ux_info(alice, &qr, Some(SecurejoinSource::Clipboard as u32), None)
330+
.await?;
328331
expected.clipboard += 1;
329332
check_statistics(alice, &expected).await;
330333

@@ -367,7 +370,7 @@ async fn test_statistics_securejoin_uipaths() -> Result<()> {
367370
expected.other += 1;
368371
check_statistics(alice, &expected).await;
369372

370-
join_securejoin_with_source(
373+
join_securejoin_with_ux_info(
371374
alice,
372375
&qr,
373376
Some(0),
@@ -377,7 +380,7 @@ async fn test_statistics_securejoin_uipaths() -> Result<()> {
377380
expected.new_contact += 1;
378381
check_statistics(alice, &expected).await;
379382

380-
join_securejoin_with_source(
383+
join_securejoin_with_ux_info(
381384
alice,
382385
&qr,
383386
Some(0),
@@ -387,7 +390,8 @@ async fn test_statistics_securejoin_uipaths() -> Result<()> {
387390
expected.new_contact += 1;
388391
check_statistics(alice, &expected).await;
389392

390-
join_securejoin_with_source(alice, &qr, Some(0), Some(SecurejoinUIPath::QrIcon as u32)).await?;
393+
join_securejoin_with_ux_info(alice, &qr, Some(0), Some(SecurejoinUIPath::QrIcon as u32))
394+
.await?;
391395
expected.qr_icon += 1;
392396
check_statistics(alice, &expected).await;
393397

0 commit comments

Comments
 (0)