Skip to content

Commit b39980e

Browse files
author
Bernhard B
committed
added possibility to update the group description & the avatar
see #417
1 parent 2474238 commit b39980e

File tree

5 files changed

+245
-4
lines changed

5 files changed

+245
-4
lines changed

src/api/api.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ type CreateGroupRequest struct {
4848
GroupLinkState string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"`
4949
}
5050

51+
type UpdateGroupRequest struct {
52+
Base64Avatar *string `json:"base64_avatar"`
53+
Description *string `json:"description"`
54+
}
55+
5156
type ChangeGroupMembersRequest struct {
5257
Members []string `json:"members"`
5358
}
@@ -1259,6 +1264,7 @@ func (a *Api) QuitGroup(c *gin.Context) {
12591264
// @Failure 400 {object} Error
12601265
// @Param number path string true "Registered Phone Number"
12611266
// @Param groupid path string true "Group ID"
1267+
// @Param data body UpdateGroupRequest true "Input Data"
12621268
// @Router /v1/groups/{number}/{groupid} [put]
12631269
func (a *Api) UpdateGroup(c *gin.Context) {
12641270
number := c.Param("number")
@@ -1274,7 +1280,15 @@ func (a *Api) UpdateGroup(c *gin.Context) {
12741280
return
12751281
}
12761282

1277-
err = a.signalClient.UpdateGroup(number, internalGroupId)
1283+
var req UpdateGroupRequest
1284+
err = c.BindJSON(&req)
1285+
if err != nil {
1286+
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
1287+
log.Error(err.Error())
1288+
return
1289+
}
1290+
1291+
err = a.signalClient.UpdateGroup(number, internalGroupId, req.Base64Avatar, req.Description)
12781292
if err != nil {
12791293
c.JSON(400, Error{Msg: err.Error()})
12801294
return

src/client/client.go

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,21 +1282,80 @@ func (s *SignalClient) QuitGroup(number string, groupId string) error {
12821282
return err
12831283
}
12841284

1285-
func (s *SignalClient) UpdateGroup(number string, groupId string) error {
1285+
func (s *SignalClient) UpdateGroup(number string, groupId string, base64Avatar *string, groupDescription *string) error {
12861286
var err error
1287+
var avatarTmpPath string = ""
1288+
if base64Avatar != nil {
1289+
u, err := uuid.NewV4()
1290+
if err != nil {
1291+
return err
1292+
}
1293+
1294+
avatarBytes, err := base64.StdEncoding.DecodeString(*base64Avatar)
1295+
if err != nil {
1296+
return errors.New("Couldn't decode base64 encoded avatar: " + err.Error())
1297+
}
1298+
1299+
fType, err := filetype.Get(avatarBytes)
1300+
if err != nil {
1301+
return err
1302+
}
1303+
1304+
avatarTmpPath = s.avatarTmpDir + u.String() + "." + fType.Extension
1305+
1306+
f, err := os.Create(avatarTmpPath)
1307+
if err != nil {
1308+
return err
1309+
}
1310+
defer f.Close()
1311+
1312+
if _, err := f.Write(avatarBytes); err != nil {
1313+
cleanupTmpFiles([]string{avatarTmpPath})
1314+
return err
1315+
}
1316+
if err := f.Sync(); err != nil {
1317+
cleanupTmpFiles([]string{avatarTmpPath})
1318+
return err
1319+
}
1320+
f.Close()
1321+
}
1322+
12871323
if s.signalCliMode == JsonRpc {
12881324
type Request struct {
1289-
GroupId string `json:"groupId"`
1325+
GroupId string `json:"groupId"`
1326+
Avatar string `json:"avatar,omitempty"`
1327+
Description *string `json:"description,omitempty"`
12901328
}
12911329
request := Request{GroupId: groupId}
1330+
1331+
if base64Avatar != nil {
1332+
request.Avatar = avatarTmpPath
1333+
}
1334+
1335+
request.Description = groupDescription
1336+
1337+
12921338
jsonRpc2Client, err := s.getJsonRpc2Client(number)
12931339
if err != nil {
12941340
return err
12951341
}
12961342
_, err = jsonRpc2Client.getRaw("updateGroup", request)
12971343
} else {
1298-
_, err = s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}, "")
1344+
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}
1345+
if base64Avatar != nil {
1346+
cmd = append(cmd, []string{"-a", avatarTmpPath}...)
1347+
}
1348+
1349+
if groupDescription != nil {
1350+
cmd = append(cmd, []string{"-d", *groupDescription}...)
1351+
}
1352+
_, err = s.cliClient.Execute(true, cmd, "")
12991353
}
1354+
1355+
if avatarTmpPath != "" {
1356+
cleanupTmpFiles([]string{avatarTmpPath})
1357+
}
1358+
13001359
return err
13011360
}
13021361

src/docs/docs.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,58 @@ var doc = `{
505505
}
506506
}
507507
},
508+
"put": {
509+
"description": "Update the state of a Signal Group.",
510+
"consumes": [
511+
"application/json"
512+
],
513+
"produces": [
514+
"application/json"
515+
],
516+
"tags": [
517+
"Groups"
518+
],
519+
"summary": "Update the state of a Signal Group.",
520+
"parameters": [
521+
{
522+
"type": "string",
523+
"description": "Registered Phone Number",
524+
"name": "number",
525+
"in": "path",
526+
"required": true
527+
},
528+
{
529+
"type": "string",
530+
"description": "Group ID",
531+
"name": "groupid",
532+
"in": "path",
533+
"required": true
534+
},
535+
{
536+
"description": "Input Data",
537+
"name": "data",
538+
"in": "body",
539+
"required": true,
540+
"schema": {
541+
"$ref": "#/definitions/api.UpdateGroupRequest"
542+
}
543+
}
544+
],
545+
"responses": {
546+
"204": {
547+
"description": "No Content",
548+
"schema": {
549+
"type": "string"
550+
}
551+
},
552+
"400": {
553+
"description": "Bad Request",
554+
"schema": {
555+
"$ref": "#/definitions/api.Error"
556+
}
557+
}
558+
}
559+
},
508560
"delete": {
509561
"description": "Delete the specified Signal Group.",
510562
"consumes": [
@@ -1854,6 +1906,17 @@ var doc = `{
18541906
}
18551907
}
18561908
},
1909+
"api.UpdateGroupRequest": {
1910+
"type": "object",
1911+
"properties": {
1912+
"base64_avatar": {
1913+
"type": "string"
1914+
},
1915+
"description": {
1916+
"type": "string"
1917+
}
1918+
}
1919+
},
18571920
"api.UpdateProfileRequest": {
18581921
"type": "object",
18591922
"properties": {

src/docs/swagger.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,58 @@
489489
}
490490
}
491491
},
492+
"put": {
493+
"description": "Update the state of a Signal Group.",
494+
"consumes": [
495+
"application/json"
496+
],
497+
"produces": [
498+
"application/json"
499+
],
500+
"tags": [
501+
"Groups"
502+
],
503+
"summary": "Update the state of a Signal Group.",
504+
"parameters": [
505+
{
506+
"type": "string",
507+
"description": "Registered Phone Number",
508+
"name": "number",
509+
"in": "path",
510+
"required": true
511+
},
512+
{
513+
"type": "string",
514+
"description": "Group ID",
515+
"name": "groupid",
516+
"in": "path",
517+
"required": true
518+
},
519+
{
520+
"description": "Input Data",
521+
"name": "data",
522+
"in": "body",
523+
"required": true,
524+
"schema": {
525+
"$ref": "#/definitions/api.UpdateGroupRequest"
526+
}
527+
}
528+
],
529+
"responses": {
530+
"204": {
531+
"description": "No Content",
532+
"schema": {
533+
"type": "string"
534+
}
535+
},
536+
"400": {
537+
"description": "Bad Request",
538+
"schema": {
539+
"$ref": "#/definitions/api.Error"
540+
}
541+
}
542+
}
543+
},
492544
"delete": {
493545
"description": "Delete the specified Signal Group.",
494546
"consumes": [
@@ -1838,6 +1890,17 @@
18381890
}
18391891
}
18401892
},
1893+
"api.UpdateGroupRequest": {
1894+
"type": "object",
1895+
"properties": {
1896+
"base64_avatar": {
1897+
"type": "string"
1898+
},
1899+
"description": {
1900+
"type": "string"
1901+
}
1902+
}
1903+
},
18411904
"api.UpdateProfileRequest": {
18421905
"type": "object",
18431906
"properties": {

src/docs/swagger.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ definitions:
197197
recipient:
198198
type: string
199199
type: object
200+
api.UpdateGroupRequest:
201+
properties:
202+
base64_avatar:
203+
type: string
204+
description:
205+
type: string
206+
type: object
200207
api.UpdateProfileRequest:
201208
properties:
202209
base64_avatar:
@@ -634,6 +641,41 @@ paths:
634641
summary: List a Signal Group.
635642
tags:
636643
- Groups
644+
put:
645+
consumes:
646+
- application/json
647+
description: Update the state of a Signal Group.
648+
parameters:
649+
- description: Registered Phone Number
650+
in: path
651+
name: number
652+
required: true
653+
type: string
654+
- description: Group ID
655+
in: path
656+
name: groupid
657+
required: true
658+
type: string
659+
- description: Input Data
660+
in: body
661+
name: data
662+
required: true
663+
schema:
664+
$ref: '#/definitions/api.UpdateGroupRequest'
665+
produces:
666+
- application/json
667+
responses:
668+
"204":
669+
description: No Content
670+
schema:
671+
type: string
672+
"400":
673+
description: Bad Request
674+
schema:
675+
$ref: '#/definitions/api.Error'
676+
summary: Update the state of a Signal Group.
677+
tags:
678+
- Groups
637679
/v1/groups/{number}/{groupid}/admins:
638680
delete:
639681
consumes:

0 commit comments

Comments
 (0)