Skip to content

Commit

Permalink
userinfo: implement use_outdated_profiles config option
Browse files Browse the repository at this point in the history
Fixes #538
  • Loading branch information
tulir committed Aug 21, 2024
1 parent 31a4522 commit 7ad59f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/connector/chatinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (s *SignalClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (
if err != nil {
return nil, err
}
meta := ghost.Metadata.(*signalid.GhostMetadata)
if !s.Main.Config.UseOutdatedProfiles && meta.ProfileFetchedAt.After(contact.Profile.FetchedAt) {
return nil, nil
}
return s.contactToUserInfo(contact), nil
}

Expand All @@ -74,6 +78,14 @@ func (s *SignalClient) contactToUserInfo(contact *types.Recipient) *bridgev2.Use
ui := &bridgev2.UserInfo{
IsBot: &isBot,
Identifiers: []string{},
ExtraUpdates: func(ctx context.Context, ghost *bridgev2.Ghost) (changed bool) {
meta := ghost.Metadata.(*signalid.GhostMetadata)
if meta.ProfileFetchedAt.Before(contact.Profile.FetchedAt) {
changed = meta.ProfileFetchedAt.IsZero() && !contact.Profile.FetchedAt.IsZero()
meta.ProfileFetchedAt.Time = contact.Profile.FetchedAt
}
return false
},
}
if contact.E164 != "" {
ui.Identifiers = append(ui.Identifiers, "tel:"+contact.E164)
Expand Down
4 changes: 3 additions & 1 deletion pkg/connector/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func (s *SignalConnector) GetDBMetaTypes() database.MetaTypes {
Portal: func() any {
return &signalid.PortalMetadata{}
},
Ghost: nil,
Ghost: func() any {
return &signalid.GhostMetadata{}
},
Message: func() any {
return &signalid.MessageMetadata{}
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/signalid/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@

package signalid

import (
"go.mau.fi/util/jsontime"
)

type PortalMetadata struct {
Revision uint32 `json:"revision,omitempty"`
}

type MessageMetadata struct {
ContainsAttachments bool `json:"contains_attachments,omitempty"`
}

type GhostMetadata struct {
ProfileFetchedAt jsontime.UnixMilli `json:"profile_fetched_at"`
}

0 comments on commit 7ad59f2

Please sign in to comment.