Compare commits

..

1 Commits

5 changed files with 98 additions and 158 deletions

View File

@ -2408,7 +2408,6 @@ func (a *Api) AddStickerPack(c *gin.Context) {
// @Produce json
// @Success 200 {object} []client.ListContactsResponse
// @Param number path string true "Registered Phone Number"
// @Param all_recipients query string false "Include all known recipients, not only contacts." (default: false)"
// @Router /v1/contacts/{number} [get]
func (a *Api) ListContacts(c *gin.Context) {
number, err := url.PathUnescape(c.Param("number"))
@ -2422,12 +2421,8 @@ func (a *Api) ListContacts(c *gin.Context) {
return
}
allRecipients := c.DefaultQuery("all_recipients", "false")
if allRecipients != "true" && allRecipients != "false" {
c.JSON(400, Error{Msg: "Couldn't process request - all_recipients parameter needs to be either 'true' or 'false'"})
return
}
contacts, err := a.signalClient.ListContacts(number, StringToBool(allRecipients), "")
contacts, err := a.signalClient.ListContacts(number)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
@ -2442,7 +2437,6 @@ func (a *Api) ListContacts(c *gin.Context) {
// @Produce json
// @Success 200 {object} client.ListContactsResponse
// @Param number path string true "Registered Phone Number"
// @Param all_recipients query string false "Include all known recipients, not only contacts." (default: false)"
// @Router /v1/contacts/{number}/{uuid} [get]
func (a *Api) ListContact(c *gin.Context) {
number, err := url.PathUnescape(c.Param("number"))
@ -2462,13 +2456,7 @@ func (a *Api) ListContact(c *gin.Context) {
return
}
allRecipients := c.DefaultQuery("all_recipients", "false")
if allRecipients != "true" && allRecipients != "false" {
c.JSON(400, Error{Msg: "Couldn't process request - all_recipients parameter needs to be either 'true' or 'false'"})
return
}
contacts, err := a.signalClient.ListContacts(number, StringToBool(allRecipients), uuid)
contact, err := a.signalClient.ListContact(number, uuid)
if err != nil {
switch err.(type) {
case *client.NotFoundError:
@ -2480,7 +2468,7 @@ func (a *Api) ListContact(c *gin.Context) {
}
}
c.JSON(200, contacts[0])
c.JSON(200, contact)
}
// @Summary Returns the avatar of a contact

View File

@ -2602,7 +2602,7 @@ func (s *SignalClient) AddStickerPack(number string, packId string, packKey stri
}
}
func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient string) ([]ListContactsResponse, error) {
func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, error) {
type SignalCliProfileResponse struct {
LastUpdateTimestamp int64 `json:"lastUpdateTimestamp"`
GivenName string `json:"givenName"`
@ -2611,7 +2611,7 @@ func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient
HasAvatar bool `json:"hasAvatar"`
}
type ListContactsSignalCliResponse struct {
type ListContactsSignlCliResponse struct {
Number string `json:"number"`
Uuid string `json:"uuid"`
Name string `json:"name"`
@ -2634,51 +2634,29 @@ func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient
var rawData string
if s.signalCliMode == JsonRpc {
type Request struct {
AllRecipients bool `json:"allRecipients,omitempty"`
Recipient string `json:"recipient,omitempty"`
}
req := Request{}
if allRecipients {
req.AllRecipients = allRecipients
}
if recipient != "" {
req.Recipient = recipient
}
jsonRpc2Client, err := s.getJsonRpc2Client()
if err != nil {
return nil, err
}
rawData, err = jsonRpc2Client.getRaw("listContacts", &number, req)
rawData, err = jsonRpc2Client.getRaw("listContacts", &number, nil)
if err != nil {
return resp, err
}
} else {
cmd := []string{"--config", s.signalCliConfig, "-o", "json", "-a", number, "listContacts"}
if allRecipients {
cmd = append(cmd, "--all-recipients")
}
if recipient != "" {
cmd = append(cmd, recipient)
}
rawData, err = s.cliClient.Execute(true, cmd, "")
if err != nil {
return resp, err
}
}
var signalCliResp []ListContactsSignalCliResponse
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")
}
if recipient != "" && len(signalCliResp) == 0 {
return resp, &NotFoundError{Description: "No user with that id (" + recipient + ") found"}
}
for _, value := range signalCliResp {
entry := ListContactsResponse{
Number: value.Number,
@ -2706,6 +2684,20 @@ func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient
return resp, nil
}
func (s *SignalClient) ListContact(number string, uuid string) (ListContactsResponse, error) {
contacts, err := s.ListContacts(number)
if err != nil {
return ListContactsResponse{}, err
}
for _, contact := range contacts {
if contact.Uuid == uuid {
return contact, nil
}
}
return ListContactsResponse{}, &NotFoundError{Description: "No contact with that id (" + uuid + ") found"}
}
func (s *SignalClient) SetPin(number string, registrationLockPin string) error {
if s.signalCliMode == JsonRpc {

View File

@ -573,12 +573,6 @@ const docTemplate = `{
"name": "number",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Include all known recipients, not only contacts.",
"name": "all_recipients",
"in": "query"
}
],
"responses": {
@ -688,12 +682,6 @@ const docTemplate = `{
"name": "number",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Include all known recipients, not only contacts.",
"name": "all_recipients",
"in": "query"
}
],
"responses": {
@ -2665,7 +2653,7 @@ const docTemplate = `{
"type": "string"
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
"$ref": "#/definitions/api.GroupPermissions"
}
}
},
@ -2739,6 +2727,32 @@ const docTemplate = `{
}
}
},
"api.GroupPermissions": {
"type": "object",
"properties": {
"add_members": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"edit_group": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"send_messages": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
}
}
},
"api.LoggingConfiguration": {
"type": "object",
"properties": {
@ -3071,7 +3085,7 @@ const docTemplate = `{
"type": "string"
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
"$ref": "#/definitions/api.GroupPermissions"
}
}
},
@ -3216,9 +3230,6 @@ const docTemplate = `{
"items": {
"type": "string"
}
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
}
}
},
@ -3348,32 +3359,6 @@ const docTemplate = `{
}
}
},
"data.GroupPermissions": {
"type": "object",
"properties": {
"add_members": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"edit_group": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"send_messages": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
}
}
},
"data.LinkPreviewType": {
"type": "object",
"properties": {

View File

@ -570,12 +570,6 @@
"name": "number",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Include all known recipients, not only contacts.",
"name": "all_recipients",
"in": "query"
}
],
"responses": {
@ -685,12 +679,6 @@
"name": "number",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Include all known recipients, not only contacts.",
"name": "all_recipients",
"in": "query"
}
],
"responses": {
@ -2662,7 +2650,7 @@
"type": "string"
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
"$ref": "#/definitions/api.GroupPermissions"
}
}
},
@ -2736,6 +2724,32 @@
}
}
},
"api.GroupPermissions": {
"type": "object",
"properties": {
"add_members": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"edit_group": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"send_messages": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
}
}
},
"api.LoggingConfiguration": {
"type": "object",
"properties": {
@ -3068,7 +3082,7 @@
"type": "string"
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
"$ref": "#/definitions/api.GroupPermissions"
}
}
},
@ -3213,9 +3227,6 @@
"items": {
"type": "string"
}
},
"permissions": {
"$ref": "#/definitions/data.GroupPermissions"
}
}
},
@ -3345,32 +3356,6 @@
}
}
},
"data.GroupPermissions": {
"type": "object",
"properties": {
"add_members": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"edit_group": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
},
"send_messages": {
"type": "string",
"enum": [
"only-admins",
"every-member"
]
}
}
},
"data.LinkPreviewType": {
"type": "object",
"properties": {

View File

@ -61,7 +61,7 @@ definitions:
name:
type: string
permissions:
$ref: '#/definitions/data.GroupPermissions'
$ref: '#/definitions/api.GroupPermissions'
type: object
api.CreateGroupResponse:
properties:
@ -110,6 +110,24 @@ definitions:
error:
type: string
type: object
api.GroupPermissions:
properties:
add_members:
enum:
- only-admins
- every-member
type: string
edit_group:
enum:
- only-admins
- every-member
type: string
send_messages:
enum:
- only-admins
- every-member
type: string
type: object
api.LoggingConfiguration:
properties:
Level:
@ -331,7 +349,7 @@ definitions:
name:
type: string
permissions:
$ref: '#/definitions/data.GroupPermissions'
$ref: '#/definitions/api.GroupPermissions'
type: object
api.UpdateProfileRequest:
properties:
@ -427,8 +445,6 @@ definitions:
items:
type: string
type: array
permissions:
$ref: '#/definitions/data.GroupPermissions'
type: object
client.IdentityEntry:
properties:
@ -512,24 +528,6 @@ definitions:
username_link:
type: string
type: object
data.GroupPermissions:
properties:
add_members:
enum:
- only-admins
- every-member
type: string
edit_group:
enum:
- only-admins
- every-member
type: string
send_messages:
enum:
- only-admins
- every-member
type: string
type: object
data.LinkPreviewType:
properties:
base64_thumbnail:
@ -930,10 +928,6 @@ paths:
name: number
required: true
type: string
- description: Include all known recipients, not only contacts.
in: query
name: all_recipients
type: string
produces:
- application/json
responses:
@ -984,10 +978,6 @@ paths:
name: number
required: true
type: string
- description: Include all known recipients, not only contacts.
in: query
name: all_recipients
type: string
produces:
- application/json
responses: