Skip to content

Added Expiration for Contact #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ type CreateGroupResponse struct {
Id string `json:"id"`
}

type UpdateContactRequest struct {
Name string `json:"name"`
Number string `json:"number"`
Expiration string `json:"expiration"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to change the type to int here. Maybe also make it more clear that it's a time?

so e.g something like: ExpirationTime int json:"expiration_time"``?

}

type UpdateProfileRequest struct {
Name string `json:"name"`
Base64Avatar string `json:"base64_avatar"`
Expand Down Expand Up @@ -338,14 +344,8 @@ func runSignalCli(wait bool, args []string, stdin string) (string, error) {
}
}

fullCmd := ""
if(stdin != "") {
fullCmd += "echo '" + stdin + "' | "
}
fullCmd += signalCliBinary + " " + strings.Join(args, " ")

log.Debug("*) su signal-api")
log.Debug("*) ", fullCmd)
log.Debug("*) ", signalCliBinary, " ", strings.Join(args, " "))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally removed some code here (probably due to a merging conflict), see: https://github.com/bbernhard/signal-cli-rest-api/blob/master/src/api/api.go#L345

cmd := exec.Command(signalCliBinary, args...)
if stdin != "" {
Expand Down Expand Up @@ -470,6 +470,48 @@ func (a *Api) RegisterNumber(c *gin.Context) {
c.Writer.WriteHeader(201)
}

// @Summary Update contact.
// @Tags Contact
// @Description Update message expiration time for a user.
// @Accept json
// @Produce json
// @Success 201 {string} string "OK"
// @Failure 400 {object} Error
// @Param data body UpdateContactRequest true "Input Data"
// @Router /v1/updatecontact [post]
func (a *Api) UpdateContact(c *gin.Context) {
var req UpdateContactRequest
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, gin.H{"error": "Couldn't process request - invalid request"})
log.Error(err.Error())
return
}

if len(req.Number) == 0 {
c.JSON(400, gin.H{"error": "Couldn't process request - please provide the recipients number"})
return
}

if len(req.Name) == 0 {
c.JSON(400, gin.H{"error": "Couldn't process request - please provide the recipients name number"})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a return here

}

if len(req.Expiration) == 0 {
c.JSON(400, gin.H{"error": "Couldn't process request - please provide an expirty time in seconds"})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a return here

}

command := []string{"--config", a.signalCliConfig, "updateContact", req.Number, "-n", req.Name, "-e", req.Expiration}

_, err = runSignalCli(false, command, "")
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
c.Writer.WriteHeader(201)
}


// @Summary Verify a registered phone number.
// @Tags Devices
// @Description Verify a registered phone number with the signal network.
Expand Down
14 changes: 14 additions & 0 deletions src/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,20 @@ var doc = `{
}
}
},
"api.UpdateContactRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"number": {
"type": "string"
},
"expiration": {
"type": "string"
}
}
},
"api.TrustIdentityRequest": {
"type": "object",
"properties": {
Expand Down
55 changes: 55 additions & 0 deletions src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,46 @@
}
}
}
},
"/v1/updatecontact": {
"post": {
"description": "Update Contact",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Update Contact"
],
"summary": "Update contact expiration",
"parameters": [
{
"description": "Input Data",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.UpdateContactRequest"
}
}
],
"responses": {
"201": {
"description": "OK",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -1041,6 +1081,7 @@
}
}
},

"api.SendMessageV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1087,6 +1128,20 @@
}
}
},
"api.UpdateContactRequest": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"name": {
"type": "string"
},
"expiration": {
"type": "string"
}
}
},
"api.TrustIdentityRequest": {
"type": "object",
"properties": {
Expand Down
9 changes: 9 additions & 0 deletions src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ definitions:
type: string
type: array
type: object
api.UpdateContactRequest:
properties:
number:
type: string
name:
type: string
expiration:
type: string
type: object
api.TrustIdentityRequest:
properties:
verified_safety_number:
Expand Down
5 changes: 5 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func main() {
identities.GET(":number", api.ListIdentities)
identities.PUT(":number/trust/:numbertotrust", api.TrustIdentity)
}

contacts := v1.Group("updatecontact")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would prefer if we could change the endpoint to contacts, as the POST method already implies that it will be a update/change request. I think what we probably also should do here is to restrict the request to a certain signal instance number. i.e: contacts/:number. And pass that number then also with -u to the runSignalCli function.

{
contacts.POST("", api.UpdateContact)
}
}

v2 := router.Group("/v2")
Expand Down