Skip to content

Commit

Permalink
api: implement Rpc.GetChatIdByContactId()
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Feb 4, 2024
1 parent c7ed4b2 commit 951cc3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion deltachat/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,14 @@ func (self *Rpc) LookupContactIdByAddr(accountId AccountId, addr string) (option
// chat
// ---------------------------------------------

// TODO: get_chat_id_by_contact_id
// Returns the [`ChatId`] for the 1:1 chat with `contactId` if it exists.
//
// If it does not exist, zero is returned.
func (self *Rpc) GetChatIdByContactId(accountId AccountId, contactId ContactId) (ChatId, error) {
var id ChatId
err := self.Transport.CallResult(self.Context, &id, "get_chat_id_by_contact_id", accountId, contactId)
return id, err
}

// Returns all message IDs of the given types in a chat.
// Typically used to show a gallery.
Expand Down
11 changes: 11 additions & 0 deletions deltachat/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ func TestRpc_SetChatVisibility(t *testing.T) {
})
}

func TestRpc_GetChatIdByContactId(t *testing.T) {
t.Parallel()
acfactory.WithOnlineAccount(func(rpc *Rpc, accId AccountId) {
contactId, err := rpc.CreateContact(accId, "[email protected]", "")
require.Nil(t, err)
chatId, err := rpc.GetChatIdByContactId(accId, contactId)
require.Nil(t, err)
require.NotEqual(t, chatId, 0)
})
}

func TestAccount_Select(t *testing.T) {
t.Parallel()
acfactory.WithRpc(func(rpc *Rpc) {
Expand Down

0 comments on commit 951cc3a

Please sign in to comment.