Skip to content

Commit 8b6470d

Browse files
committed
add new Rpc API: GetChatSecurejoinQrCode, importVcardContents, makeVcard
1 parent 3cf3338 commit 8b6470d

File tree

4 files changed

+185
-144
lines changed

4 files changed

+185
-144
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
## Added
6+
7+
- new Rpc API: `GetChatSecurejoinQrCode`, `importVcardContents`, `makeVcard`
8+
39
## v1.2.14
410

511
## Added

deltachat/acfactory.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,47 +198,43 @@ func (factory *AcFactory) NextMsg(rpc *Rpc, accId AccountId) *MsgSnapshot {
198198
return msg
199199
}
200200

201-
// Introduce two accounts to each other creating a 1:1 chat between them and exchanging messages.
201+
// Introduce two accounts to each other creating a 1:1 chat between them.
202202
func (factory *AcFactory) IntroduceEachOther(rpc1 *Rpc, accId1 AccountId, rpc2 *Rpc, accId2 AccountId) {
203-
chatId := factory.CreateChat(rpc1, accId1, rpc2, accId2)
204-
_, err := rpc1.MiscSendTextMessage(accId1, chatId, "hi")
203+
qrdata, err := rpc1.GetChatSecurejoinQrCode(accId1, option.None[ChatId]())
205204
if err != nil {
206205
panic(err)
207206
}
208-
factory.WaitForEventInChat(rpc1, accId1, chatId, EventMsgsChanged{})
209-
snapshot := factory.NextMsg(rpc2, accId2)
210-
if snapshot.Text != "hi" {
211-
panic("unexpected message: " + snapshot.Text)
212-
}
213-
214-
err = rpc2.AcceptChat(accId2, snapshot.ChatId)
207+
_, err = rpc2.SecureJoin(accId2, qrdata)
215208
if err != nil {
216209
panic(err)
217210
}
218-
_, err = rpc2.MiscSendTextMessage(accId2, snapshot.ChatId, "hello")
219-
if err != nil {
220-
panic(err)
211+
212+
for {
213+
event := factory.WaitForEvent(rpc1, accId1, EventSecurejoinInviterProgress{}).(EventSecurejoinInviterProgress)
214+
if event.Progress == 1000 {
215+
break
216+
}
221217
}
222-
factory.WaitForEventInChat(rpc2, accId2, snapshot.ChatId, EventMsgsChanged{})
223-
snapshot = factory.NextMsg(rpc1, accId1)
224-
if snapshot.Text != "hello" {
225-
panic("unexpected message: " + snapshot.Text)
218+
219+
for {
220+
event := factory.WaitForEvent(rpc2, accId2, EventSecurejoinJoinerProgress{}).(EventSecurejoinJoinerProgress)
221+
if event.Progress == 1000 {
222+
break
223+
}
226224
}
227225
}
228226

229227
// Create a 1:1 chat with accId2 in the chatlist of accId1.
230228
func (factory *AcFactory) CreateChat(rpc1 *Rpc, accId1 AccountId, rpc2 *Rpc, accId2 AccountId) ChatId {
231-
addr2, err := rpc2.GetConfig(accId2, "configured_addr")
229+
vcard, err := rpc2.makeVcard(accId2, []ContactId{ContactSelf})
232230
if err != nil {
233231
panic(err)
234232
}
235-
236-
contactId, err := rpc1.CreateContact(accId1, addr2.Unwrap(), "")
233+
ids, err := rpc1.importVcardContents(accId1, vcard)
237234
if err != nil {
238235
panic(err)
239236
}
240-
241-
chatId, err := rpc1.CreateChatByContactId(accId1, contactId)
237+
chatId, err := rpc1.CreateChatByContactId(accId1, ids[0])
242238
if err != nil {
243239
panic(err)
244240
}

deltachat/rpc.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ func (rpc *Rpc) GetChatEncryptionInfo(accountId AccountId, chatId ChatId) (strin
336336
return data, err
337337
}
338338

339+
// Get QR code text that will offer a [SecureJoin](https://securejoin.delta.chat/) invitation.
340+
// If `chatId` is a group chat ID, SecureJoin QR code for the group is returned.
341+
// If `chatId` is unset, setup contact QR code is returned.
342+
func (rpc *Rpc) GetChatSecurejoinQrCode(accountId AccountId, chatId option.Option[ChatId]) (string, error) {
343+
var data string
344+
err := rpc.Transport.CallResult(rpc.Context, &data, "get_chat_securejoin_qr_code", accountId, chatId)
345+
return data, err
346+
}
347+
339348
// Get Join-Group QR code text and SVG data.
340349
func (rpc *Rpc) GetChatSecurejoinQrCodeSvg(accountId AccountId, chatId option.Option[ChatId]) (string, string, error) {
341350
var data [2]string
@@ -609,6 +618,22 @@ func (rpc *Rpc) CreateContact(accountId AccountId, email string, name string) (C
609618
return id, err
610619
}
611620

621+
// Imports contacts from a vCard.
622+
//
623+
// Returns the ids of created/modified contacts in the order they appear in the vCard.
624+
func (rpc *Rpc) importVcardContents(accountId AccountId, vcard string) ([]ContactId, error) {
625+
var ids []ContactId
626+
err := rpc.Transport.CallResult(rpc.Context, &ids, "import_vcard_contents", accountId, vcard)
627+
return ids, err
628+
}
629+
630+
// Returns a vCard containing contacts with the given ids.
631+
func (rpc *Rpc) makeVcard(accountId AccountId, contacts []ContactId) (string, error) {
632+
var vcard string
633+
err := rpc.Transport.CallResult(rpc.Context, &vcard, "make_vcard", accountId, contacts)
634+
return vcard, err
635+
}
636+
612637
// Returns contact id of the created or existing DM chat with that contact
613638
func (rpc *Rpc) CreateChatByContactId(accountId AccountId, contactId ContactId) (ChatId, error) {
614639
var id ChatId

0 commit comments

Comments
 (0)