extended list contacts GET endpoint

* exposed some more fields

see #675
This commit is contained in:
Bernhard B
2025-03-29 22:33:37 +01:00
parent e452205c38
commit bf929a3aa1
4 changed files with 168 additions and 2 deletions

View File

@@ -188,6 +188,20 @@ type ListInstalledStickerPacksResponse struct {
Author string `json:"author"`
}
type ContactProfile struct {
GivenName string `json:"given_name"`
FamilyName string `json:"lastname"`
About string `json:"about"`
HasAvatar bool `json:"has_avatar"`
LastUpdatedTimestamp int64 `json:"last_updated_timestamp"`
}
type Nickname struct {
Name string `json:"name"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
}
type ListContactsResponse struct {
Number string `json:"number"`
Uuid string `json:"uuid"`
@@ -197,6 +211,10 @@ type ListContactsResponse struct {
Color string `json:"color"`
Blocked bool `json:"blocked"`
MessageExpiration string `json:"message_expiration"`
Note string `json:"note"`
Profile ContactProfile `json:"profile"`
GivenName string `json:"given_name"`
Nickname Nickname `json:"nickname"`
}
func cleanupTmpFiles(paths []string) {
@@ -2193,6 +2211,14 @@ func (s *SignalClient) AddStickerPack(number string, packId string, packKey stri
}
func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, error) {
type SignalCliProfileResponse struct {
LastUpdateTimestamp int64 `json:"lastUpdateTimestamp"`
GivenName string `json:"givenName"`
FamilyName string `json:"familyName"`
About string `json:"about"`
HasAvatar bool `json:"hasAvatar"`
}
type ListContactsSignlCliResponse struct {
Number string `json:"number"`
Uuid string `json:"uuid"`
@@ -2202,6 +2228,12 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
Color string `json:"color"`
Blocked bool `json:"blocked"`
MessageExpiration string `json:"messageExpiration"`
Note string `json:"note"`
GivenName string `json:"givenName"`
Profile SignalCliProfileResponse `json:"profile"`
Nickname string `json:"nickName"`
NickGivenName string `json:"nickGivenName"`
NickFamilyName string `json:"nickFamilyName"`
}
resp := []ListContactsResponse{}
@@ -2229,11 +2261,12 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
var signalCliResp []ListContactsSignlCliResponse
err = json.Unmarshal([]byte(rawData), &signalCliResp)
if err != nil {
log.Error("Couldn't list contacts", err.Error())
return resp, errors.New("Couldn't process request - invalid signal-cli response")
}
for _, value := range signalCliResp {
resp = append(resp, ListContactsResponse{
entry := ListContactsResponse{
Number: value.Number,
Uuid: value.Uuid,
Name: value.Name,
@@ -2242,7 +2275,18 @@ func (s *SignalClient) ListContacts(number string) ([]ListContactsResponse, erro
Color: value.Color,
Blocked: value.Blocked,
MessageExpiration: value.MessageExpiration,
})
Note: value.Note,
GivenName: value.GivenName,
}
entry.Profile.About = value.Profile.About
entry.Profile.HasAvatar = value.Profile.HasAvatar
entry.Profile.LastUpdatedTimestamp = value.Profile.LastUpdateTimestamp
entry.Profile.GivenName = value.Profile.GivenName
entry.Profile.FamilyName = value.Profile.FamilyName
entry.Nickname.Name = value.Nickname
entry.Nickname.GivenName = value.NickGivenName
entry.Nickname.FamilyName = value.NickFamilyName
resp = append(resp, entry)
}
return resp, nil

View File

@@ -2594,6 +2594,26 @@ const docTemplate = `{
}
}
},
"client.ContactProfile": {
"type": "object",
"properties": {
"about": {
"type": "string"
},
"given_name": {
"type": "string"
},
"has_avatar": {
"type": "boolean"
},
"last_updated_timestamp": {
"type": "integer"
},
"lastname": {
"type": "string"
}
}
},
"client.GroupEntry": {
"type": "object",
"properties": {
@@ -2670,15 +2690,27 @@ const docTemplate = `{
"color": {
"type": "string"
},
"given_name": {
"type": "string"
},
"message_expiration": {
"type": "string"
},
"name": {
"type": "string"
},
"nickname": {
"$ref": "#/definitions/client.Nickname"
},
"note": {
"type": "string"
},
"number": {
"type": "string"
},
"profile": {
"$ref": "#/definitions/client.ContactProfile"
},
"profile_name": {
"type": "string"
},
@@ -2710,6 +2742,20 @@ const docTemplate = `{
}
}
},
"client.Nickname": {
"type": "object",
"properties": {
"family_name": {
"type": "string"
},
"given_name": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"client.SetUsernameResponse": {
"type": "object",
"properties": {

View File

@@ -2591,6 +2591,26 @@
}
}
},
"client.ContactProfile": {
"type": "object",
"properties": {
"about": {
"type": "string"
},
"given_name": {
"type": "string"
},
"has_avatar": {
"type": "boolean"
},
"last_updated_timestamp": {
"type": "integer"
},
"lastname": {
"type": "string"
}
}
},
"client.GroupEntry": {
"type": "object",
"properties": {
@@ -2667,15 +2687,27 @@
"color": {
"type": "string"
},
"given_name": {
"type": "string"
},
"message_expiration": {
"type": "string"
},
"name": {
"type": "string"
},
"nickname": {
"$ref": "#/definitions/client.Nickname"
},
"note": {
"type": "string"
},
"number": {
"type": "string"
},
"profile": {
"$ref": "#/definitions/client.ContactProfile"
},
"profile_name": {
"type": "string"
},
@@ -2707,6 +2739,20 @@
}
}
},
"client.Nickname": {
"type": "object",
"properties": {
"family_name": {
"type": "string"
},
"given_name": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"client.SetUsernameResponse": {
"type": "object",
"properties": {

View File

@@ -309,6 +309,19 @@ definitions:
type: string
type: array
type: object
client.ContactProfile:
properties:
about:
type: string
given_name:
type: string
has_avatar:
type: boolean
last_updated_timestamp:
type: integer
lastname:
type: string
type: object
client.GroupEntry:
properties:
admins:
@@ -359,12 +372,20 @@ definitions:
type: boolean
color:
type: string
given_name:
type: string
message_expiration:
type: string
name:
type: string
nickname:
$ref: '#/definitions/client.Nickname'
note:
type: string
number:
type: string
profile:
$ref: '#/definitions/client.ContactProfile'
profile_name:
type: string
username:
@@ -385,6 +406,15 @@ definitions:
url:
type: string
type: object
client.Nickname:
properties:
family_name:
type: string
given_name:
type: string
name:
type: string
type: object
client.SetUsernameResponse:
properties:
username: