implemented "sendContacts" functionality

see #416
This commit is contained in:
Bernhard B
2023-10-07 11:18:16 +02:00
parent 07aee21672
commit 9e09775d94
3 changed files with 40 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -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 {

View File

@@ -242,6 +242,7 @@ func main() {
contacts := v1.Group("/contacts")
{
contacts.PUT(":number", api.UpdateContact)
contacts.POST(":number/sync", api.SendContacts)
}
}