From 9e09775d94a0905339c53276dac448596ad6b2d5 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Sat, 7 Oct 2023 11:18:16 +0200 Subject: [PATCH] implemented "sendContacts" functionality see #416 --- src/api/api.go | 24 ++++++++++++++++++++++++ src/client/client.go | 15 +++++++++++++++ src/main.go | 1 + 3 files changed, 40 insertions(+) diff --git a/src/api/api.go b/src/api/api.go index df9c7cf..ceb8666 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -1623,3 +1623,27 @@ func (a *Api) GetTrustMode(c *gin.Context) { c.JSON(200, trustMode) } + +// @Summary Send a synchronization message with the local contacts list to all linked devices. +// @Tags Contacts +// @Description Send a synchronization message with the local contacts list to all linked devices. This command should only be used if this is the primary device. +// @Accept json +// @Produce json +// @Param number path string true "Registered Phone Number" +// @Success 204 +// @Failure 400 {object} Error +// @Router /v1/contacts{number}/sync [post] +func (a *Api) SendContacts(c *gin.Context) { + number := c.Param("number") + if number == "" { + c.JSON(400, Error{Msg: "Couldn't process request - number missing"}) + return + } + + err := a.signalClient.SendContacts(number) + if err != nil { + c.JSON(400, Error{Msg: err.Error()}) + return + } + c.Status(http.StatusNoContent) +} diff --git a/src/client/client.go b/src/client/client.go index 6ecb7dc..72e629a 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -1582,6 +1582,21 @@ func (s *SignalClient) SearchForNumbers(number string, numbers []string) ([]Sear return searchResultEntries, err } +func (s* SignalClient) SendContacts(number string) error { + var err error + if s.signalCliMode == JsonRpc { + jsonRpc2Client, err := s.getJsonRpc2Client(number) + if err != nil { + return err + } + _, err = jsonRpc2Client.getRaw("sendContacts", nil) + } else { + cmd := []string{"--config", s.signalCliConfig, "-a", number, "sendContacts"} + _, err = s.cliClient.Execute(true, cmd, "") + } + return err +} + func (s *SignalClient) UpdateContact(number string, recipient string, name *string, expirationInSeconds *int) error { var err error if s.signalCliMode == JsonRpc { diff --git a/src/main.go b/src/main.go index 7cd512b..0d1e6a0 100644 --- a/src/main.go +++ b/src/main.go @@ -242,6 +242,7 @@ func main() { contacts := v1.Group("/contacts") { contacts.PUT(":number", api.UpdateContact) + contacts.POST(":number/sync", api.SendContacts) } }