mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-21 13:54:18 +00:00
direct uuid contact search
This commit is contained in:
parent
92a65ec781
commit
379ff16ca6
@ -2601,8 +2601,6 @@ func (s *SignalClient) AddStickerPack(number string, packId string, packKey stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, error) {
|
|
||||||
type SignalCliProfileResponse struct {
|
type SignalCliProfileResponse struct {
|
||||||
LastUpdateTimestamp int64 `json:"lastUpdateTimestamp"`
|
LastUpdateTimestamp int64 `json:"lastUpdateTimestamp"`
|
||||||
GivenName string `json:"givenName"`
|
GivenName string `json:"givenName"`
|
||||||
@ -2610,7 +2608,6 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
|
|||||||
About string `json:"about"`
|
About string `json:"about"`
|
||||||
HasAvatar bool `json:"hasAvatar"`
|
HasAvatar bool `json:"hasAvatar"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListContactsSignlCliResponse struct {
|
type ListContactsSignlCliResponse struct {
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
Uuid string `json:"uuid"`
|
Uuid string `json:"uuid"`
|
||||||
@ -2628,7 +2625,14 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
|
|||||||
NickFamilyName string `json:"nickFamilyName"`
|
NickFamilyName string `json:"nickFamilyName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, error) {
|
||||||
resp := []ListContactsResponse{}
|
resp := []ListContactsResponse{}
|
||||||
|
type Request struct {
|
||||||
|
|
||||||
|
AllRecipients bool `json:"allRecipients"`
|
||||||
|
}
|
||||||
|
|
||||||
|
req :=Request{ AllRecipients: true}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var rawData string
|
var rawData string
|
||||||
@ -2638,7 +2642,7 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rawData, err = jsonRpc2Client.getRaw("listContacts", &number, nil)
|
rawData, err = jsonRpc2Client.getRaw("listContacts", &number, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
@ -2684,19 +2688,68 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) ListContact(number string, uuid string) (ListContactsResponse, error) {
|
func (s *SignalClient) ListContact(number string, uuid string) ([]ListContactsResponse, error) {
|
||||||
contacts, err := s.ListContacts(number)
|
|
||||||
|
resp := []ListContactsResponse{}
|
||||||
|
type Request struct {
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
AllRecipients bool `json:"allRecipients"`
|
||||||
|
}
|
||||||
|
|
||||||
|
req :=Request{ Recipient: uuid, AllRecipients: true}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
var rawData string
|
||||||
|
|
||||||
|
if s.signalCliMode == JsonRpc {
|
||||||
|
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ListContactsResponse{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rawData, err = jsonRpc2Client.getRaw("listContacts", &number, req)
|
||||||
for _, contact := range contacts {
|
if err != nil {
|
||||||
if contact.Uuid == uuid {
|
return resp, err
|
||||||
return contact, nil
|
}
|
||||||
|
} else {
|
||||||
|
cmd := []string{"--config", s.signalCliConfig, "-o", "json", "-a", number, "listContacts"}
|
||||||
|
rawData, err = s.cliClient.Execute(true, cmd, "")
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListContactsResponse{}, &NotFoundError{Description: "No contact with that id (" + uuid + ") found"}
|
var signalCliResp []ListContactsSignlCliResponse
|
||||||
|
err = json.Unmarshal([]byte(rawData), &signalCliResp)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Couldn't list contacts", err.Error())
|
||||||
|
return resp, errors.New("Couldn't process request - invalid signal-cli response")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, value := range signalCliResp {
|
||||||
|
entry := ListContactsResponse{
|
||||||
|
Number: value.Number,
|
||||||
|
Uuid: value.Uuid,
|
||||||
|
Name: value.Name,
|
||||||
|
ProfileName: value.ProfileName,
|
||||||
|
Username: value.Username,
|
||||||
|
Color: value.Color,
|
||||||
|
Blocked: value.Blocked,
|
||||||
|
MessageExpiration: value.MessageExpiration,
|
||||||
|
Note: value.Note,
|
||||||
|
GivenName: value.GivenName,
|
||||||
|
}
|
||||||
|
entry.Profile.About = value.Profile.About
|
||||||
|
entry.Profile.HasAvatar = value.Profile.HasAvatar
|
||||||
|
entry.Profile.LastUpdatedTimestamp = value.Profile.LastUpdateTimestamp
|
||||||
|
entry.Profile.GivenName = value.Profile.GivenName
|
||||||
|
entry.Profile.FamilyName = value.Profile.FamilyName
|
||||||
|
entry.Nickname.Name = value.Nickname
|
||||||
|
entry.Nickname.GivenName = value.NickGivenName
|
||||||
|
entry.Nickname.FamilyName = value.NickFamilyName
|
||||||
|
resp = append(resp, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SetPin(number string, registrationLockPin string) error {
|
func (s *SignalClient) SetPin(number string, registrationLockPin string) error {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user