@@ -29,6 +29,14 @@ const signalCliV2GroupError = "Cannot create a V2 group as self does not have a
2929
3030const endpointNotSupportedInJsonRpcMode = "This endpoint is not supported in JSON-RPC mode."
3131
32+ type AvatarType int
33+
34+ const (
35+ GroupAvatar AvatarType = iota + 1
36+ ContactAvatar
37+ ProfileAvatar
38+ )
39+
3240type GroupPermission int
3341
3442const (
@@ -1323,21 +1331,33 @@ func (s *SignalClient) GetGroup(number string, groupId string) (*GroupEntry, err
13231331 return nil , nil
13241332}
13251333
1326- func (s * SignalClient ) GetGroupAvatar (number string , groupId string ) ([]byte , error ) {
1334+ func (s * SignalClient ) GetAvatar (number string , id string , avatarType AvatarType ) ([]byte , error ) {
13271335 var err error
13281336 var rawData string
13291337
1330- internalGroupId , err := ConvertGroupIdToInternalGroupId (groupId )
1331- if err != nil {
1332- return []byte {}, errors .New ("Invalid group id" )
1338+ if avatarType == GroupAvatar {
1339+ id , err = ConvertGroupIdToInternalGroupId (id )
1340+ if err != nil {
1341+ return []byte {}, errors .New ("Invalid group id" )
1342+ }
13331343 }
13341344
13351345 if s .signalCliMode == JsonRpc {
13361346 type Request struct {
1337- GroupId string `json:"groupId"`
1347+ GroupId string `json:"groupId,omitempty"`
1348+ Contact string `json:"contact,omitempty"`
1349+ Profile string `json:"profile,omitempty"`
13381350 }
13391351
1340- request := Request {GroupId : internalGroupId }
1352+ var request Request
1353+
1354+ if avatarType == GroupAvatar {
1355+ request .GroupId = id
1356+ } else if avatarType == ContactAvatar {
1357+ request .Contact = id
1358+ } else if avatarType == ProfileAvatar {
1359+ request .Profile = id
1360+ }
13411361
13421362 jsonRpc2Client , err := s .getJsonRpc2Client ()
13431363 if err != nil {
@@ -1351,8 +1371,21 @@ func (s *SignalClient) GetGroupAvatar(number string, groupId string) ([]byte, er
13511371 return []byte {}, err
13521372 }
13531373 } else {
1354- rawData , err = s .cliClient .Execute (true , []string {"--config" , s .signalCliConfig , "-o" , "json" , "-a" , number , "getAvatar" , "-g" , internalGroupId }, "" )
1374+ cmd := []string {"--config" , s .signalCliConfig , "-o" , "json" , "-a" , number , "getAvatar" }
1375+
1376+ if avatarType == GroupAvatar {
1377+ cmd = append (cmd , []string {"-g" , id }... )
1378+ } else if avatarType == ContactAvatar {
1379+ cmd = append (cmd , []string {"--contact" , id }... )
1380+ } else if avatarType == ProfileAvatar {
1381+ cmd = append (cmd , []string {"--profile" , id }... )
1382+ }
1383+
1384+ rawData , err = s .cliClient .Execute (true , cmd , "" )
13551385 if err != nil {
1386+ if strings .Contains (err .Error (), "Could not find avatar" ) {
1387+ return []byte {}, & NotFoundError {Description : "No avatar found." }
1388+ }
13561389 return []byte {}, err
13571390 }
13581391 }
@@ -2528,6 +2561,21 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
25282561 return resp , nil
25292562}
25302563
2564+ func (s * SignalClient ) ListContact (number string , uuid string ) (ListContactsResponse , error ) {
2565+ contacts , err := s .ListContacts (number )
2566+ if err != nil {
2567+ return ListContactsResponse {}, err
2568+ }
2569+
2570+ for _ , contact := range contacts {
2571+ if contact .Uuid == uuid {
2572+ return contact , nil
2573+ }
2574+ }
2575+
2576+ return ListContactsResponse {}, & NotFoundError {Description : "No contact with that id (" + uuid + ") found" }
2577+ }
2578+
25312579func (s * SignalClient ) SetPin (number string , registrationLockPin string ) error {
25322580 if s .signalCliMode == JsonRpc {
25332581 type Request struct {
@@ -2544,11 +2592,10 @@ func (s *SignalClient) SetPin(number string, registrationLockPin string) error {
25442592 }
25452593 } else {
25462594 cmd := []string {"--config" , s .signalCliConfig , "-o" , "json" , "-a" , number , "setPin" , registrationLockPin }
2547- rawData , err := s .cliClient .Execute (true , cmd , "" )
2595+ _ , err := s .cliClient .Execute (true , cmd , "" )
25482596 if err != nil {
25492597 return err
25502598 }
2551- log .Info (string (rawData ))
25522599 }
25532600 return nil
25542601}
0 commit comments