mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
added possibility to update the group description & the avatar
see #417
This commit is contained in:
@@ -48,6 +48,11 @@ type CreateGroupRequest struct {
|
||||
GroupLinkState string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"`
|
||||
}
|
||||
|
||||
type UpdateGroupRequest struct {
|
||||
Base64Avatar *string `json:"base64_avatar"`
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
type ChangeGroupMembersRequest struct {
|
||||
Members []string `json:"members"`
|
||||
}
|
||||
@@ -1259,6 +1264,7 @@ func (a *Api) QuitGroup(c *gin.Context) {
|
||||
// @Failure 400 {object} Error
|
||||
// @Param number path string true "Registered Phone Number"
|
||||
// @Param groupid path string true "Group ID"
|
||||
// @Param data body UpdateGroupRequest true "Input Data"
|
||||
// @Router /v1/groups/{number}/{groupid} [put]
|
||||
func (a *Api) UpdateGroup(c *gin.Context) {
|
||||
number := c.Param("number")
|
||||
@@ -1274,7 +1280,15 @@ func (a *Api) UpdateGroup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = a.signalClient.UpdateGroup(number, internalGroupId)
|
||||
var req UpdateGroupRequest
|
||||
err = c.BindJSON(&req)
|
||||
if err != nil {
|
||||
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = a.signalClient.UpdateGroup(number, internalGroupId, req.Base64Avatar, req.Description)
|
||||
if err != nil {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
|
||||
@@ -1282,21 +1282,80 @@ func (s *SignalClient) QuitGroup(number string, groupId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SignalClient) UpdateGroup(number string, groupId string) error {
|
||||
func (s *SignalClient) UpdateGroup(number string, groupId string, base64Avatar *string, groupDescription *string) error {
|
||||
var err error
|
||||
var avatarTmpPath string = ""
|
||||
if base64Avatar != nil {
|
||||
u, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avatarBytes, err := base64.StdEncoding.DecodeString(*base64Avatar)
|
||||
if err != nil {
|
||||
return errors.New("Couldn't decode base64 encoded avatar: " + err.Error())
|
||||
}
|
||||
|
||||
fType, err := filetype.Get(avatarBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avatarTmpPath = s.avatarTmpDir + u.String() + "." + fType.Extension
|
||||
|
||||
f, err := os.Create(avatarTmpPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := f.Write(avatarBytes); err != nil {
|
||||
cleanupTmpFiles([]string{avatarTmpPath})
|
||||
return err
|
||||
}
|
||||
if err := f.Sync(); err != nil {
|
||||
cleanupTmpFiles([]string{avatarTmpPath})
|
||||
return err
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
|
||||
if s.signalCliMode == JsonRpc {
|
||||
type Request struct {
|
||||
GroupId string `json:"groupId"`
|
||||
GroupId string `json:"groupId"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
request := Request{GroupId: groupId}
|
||||
|
||||
if base64Avatar != nil {
|
||||
request.Avatar = avatarTmpPath
|
||||
}
|
||||
|
||||
request.Description = groupDescription
|
||||
|
||||
|
||||
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = jsonRpc2Client.getRaw("updateGroup", request)
|
||||
} else {
|
||||
_, err = s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}, "")
|
||||
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}
|
||||
if base64Avatar != nil {
|
||||
cmd = append(cmd, []string{"-a", avatarTmpPath}...)
|
||||
}
|
||||
|
||||
if groupDescription != nil {
|
||||
cmd = append(cmd, []string{"-d", *groupDescription}...)
|
||||
}
|
||||
_, err = s.cliClient.Execute(true, cmd, "")
|
||||
}
|
||||
|
||||
if avatarTmpPath != "" {
|
||||
cleanupTmpFiles([]string{avatarTmpPath})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -505,6 +505,58 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"description": "Update the state of a Signal Group.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Groups"
|
||||
],
|
||||
"summary": "Update the state of a Signal Group.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Group ID",
|
||||
"name": "groupid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Input Data",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.UpdateGroupRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "Delete the specified Signal Group.",
|
||||
"consumes": [
|
||||
@@ -1854,6 +1906,17 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.UpdateGroupRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"base64_avatar": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.UpdateProfileRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -489,6 +489,58 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"description": "Update the state of a Signal Group.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Groups"
|
||||
],
|
||||
"summary": "Update the state of a Signal Group.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Group ID",
|
||||
"name": "groupid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Input Data",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.UpdateGroupRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "Delete the specified Signal Group.",
|
||||
"consumes": [
|
||||
@@ -1838,6 +1890,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.UpdateGroupRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"base64_avatar": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.UpdateProfileRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -197,6 +197,13 @@ definitions:
|
||||
recipient:
|
||||
type: string
|
||||
type: object
|
||||
api.UpdateGroupRequest:
|
||||
properties:
|
||||
base64_avatar:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
type: object
|
||||
api.UpdateProfileRequest:
|
||||
properties:
|
||||
base64_avatar:
|
||||
@@ -634,6 +641,41 @@ paths:
|
||||
summary: List a Signal Group.
|
||||
tags:
|
||||
- Groups
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Update the state of a Signal Group.
|
||||
parameters:
|
||||
- description: Registered Phone Number
|
||||
in: path
|
||||
name: number
|
||||
required: true
|
||||
type: string
|
||||
- description: Group ID
|
||||
in: path
|
||||
name: groupid
|
||||
required: true
|
||||
type: string
|
||||
- description: Input Data
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api.UpdateGroupRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/api.Error'
|
||||
summary: Update the state of a Signal Group.
|
||||
tags:
|
||||
- Groups
|
||||
/v1/groups/{number}/{groupid}/admins:
|
||||
delete:
|
||||
consumes:
|
||||
|
||||
Reference in New Issue
Block a user