return timestamp of sent message

see #137
This commit is contained in:
Bernhard B
2021-05-26 18:02:55 +02:00
parent e58797d889
commit 68c6595ab9
4 changed files with 36 additions and 9 deletions

View File

@@ -118,6 +118,10 @@ type TrustIdentityRequest struct {
VerifiedSafetyNumber string `json:"verified_safety_number"` VerifiedSafetyNumber string `json:"verified_safety_number"`
} }
type SendMessageResponse struct {
Timestamp string `json:"timestamp"`
}
func convertInternalGroupIdToGroupId(internalId string) string { func convertInternalGroupIdToGroupId(internalId string) string {
return groupPrefix + base64.StdEncoding.EncodeToString([]byte(internalId)) return groupPrefix + base64.StdEncoding.EncodeToString([]byte(internalId))
} }
@@ -235,7 +239,7 @@ func send(c *gin.Context, attachmentTmpDir string, signalCliConfig string, numbe
cmd = append(cmd, attachmentTmpPaths...) cmd = append(cmd, attachmentTmpPaths...)
} }
_, err := runSignalCli(true, cmd, message) resp, err := runSignalCli(true, cmd, message)
if err != nil { if err != nil {
cleanupTmpFiles(attachmentTmpPaths) cleanupTmpFiles(attachmentTmpPaths)
if strings.Contains(err.Error(), signalCliV2GroupError) { if strings.Contains(err.Error(), signalCliV2GroupError) {
@@ -246,8 +250,10 @@ func send(c *gin.Context, attachmentTmpDir string, signalCliConfig string, numbe
return return
} }
sendMessageResponse := SendMessageResponse{Timestamp: strings.TrimSuffix(resp, "\n")}
cleanupTmpFiles(attachmentTmpPaths) cleanupTmpFiles(attachmentTmpPaths)
c.Writer.WriteHeader(201) c.JSON(201, sendMessageResponse)
} }
func parseWhitespaceDelimitedKeyValueStringList(in string, keys []string) []map[string]string { func parseWhitespaceDelimitedKeyValueStringList(in string, keys []string) []map[string]string {
@@ -543,7 +549,7 @@ func (a *Api) Send(c *gin.Context) {
// @Description Send a signal message // @Description Send a signal message
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 201 {string} string "OK" // @Success 201 {object} SendMessageResponse
// @Failure 400 {object} Error // @Failure 400 {object} Error
// @Param data body SendMessageV2 true "Input Data" // @Param data body SendMessageV2 true "Input Data"
// @Router /v2/send [post] // @Router /v2/send [post]

View File

@@ -902,9 +902,9 @@ var doc = `{
], ],
"responses": { "responses": {
"201": { "201": {
"description": "OK", "description": "Created",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/api.SendMessageResponse"
} }
}, },
"400": { "400": {
@@ -1048,6 +1048,14 @@ var doc = `{
} }
} }
}, },
"api.SendMessageResponse": {
"type": "object",
"properties": {
"timestamp": {
"type": "string"
}
}
},
"api.SendMessageV1": { "api.SendMessageV1": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@@ -887,9 +887,9 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "OK", "description": "Created",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/api.SendMessageResponse"
} }
}, },
"400": { "400": {
@@ -1033,6 +1033,14 @@
} }
} }
}, },
"api.SendMessageResponse": {
"type": "object",
"properties": {
"timestamp": {
"type": "string"
}
}
},
"api.SendMessageV1": { "api.SendMessageV1": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@@ -84,6 +84,11 @@ definitions:
use_voice: use_voice:
type: boolean type: boolean
type: object type: object
api.SendMessageResponse:
properties:
timestamp:
type: string
type: object
api.SendMessageV1: api.SendMessageV1:
properties: properties:
base64_attachment: base64_attachment:
@@ -718,9 +723,9 @@ paths:
- application/json - application/json
responses: responses:
"201": "201":
description: OK description: Created
schema: schema:
type: string $ref: '#/definitions/api.SendMessageResponse'
"400": "400":
description: Bad Request description: Bad Request
schema: schema: