Skip to content
Snippets Groups Projects
Unverified Commit cca17856 authored by Sumner Evans's avatar Sumner Evans
Browse files

sync: add limit configurations

parent 85ca2b6b
No related branches found
No related tags found
No related merge requests found
Pipeline #16594 passed
......@@ -31,6 +31,11 @@ var ExampleConfig string
type Config struct {
DisplaynameTemplate string `yaml:"displayname_template"`
displaynameTemplate *template.Template `yaml:"-"`
Sync struct {
UpdateLimit int `yaml:"update_limit"`
CreateLimit int `yaml:"create_limit"`
} `yaml:"sync"`
}
type umConfig Config
......@@ -50,6 +55,8 @@ func (c *Config) PostProcess() (err error) {
func upgradeConfig(helper up.Helper) {
helper.Copy(up.Str, "displayname_template")
helper.Copy(up.Int, "sync", "update_limit")
helper.Copy(up.Int, "sync", "create_limit")
}
func (lc *LinkedInConnector) GetConfig() (string, any, up.Upgrader) {
......
......@@ -2,3 +2,12 @@
# .FirstName is replaced with the first name
# .LastName is replaced with the last name
displayname_template: "{{ with .Organization }}{{ . }}{{ else }}{{ .FirstName }} {{ .LastName }}{{ end }} (LinkedIn)"
sync:
# Number of most recently active dialogs to check when syncing chats.
# Set to 0 to remove limit.
update_limit: 0
# Number of most recently active dialogs to create portals for when syncing
# chats.
# Set to 0 to remove limit.
create_limit: 10
......@@ -17,6 +17,7 @@ func (l *LinkedInClient) syncConversations(ctx context.Context) {
lastUsedUpdatedBefore := time.Time{}
updatedBefore := time.Now()
var updated, created int
for {
log := log.With().
Time("updated_before", updatedBefore).
......@@ -45,13 +46,25 @@ func (l *LinkedInClient) syncConversations(ctx context.Context) {
updatedBefore = conv.LastActivityAt.Time
}
portalKey := l.makePortalKey(conv.EntityURN)
portal, err := l.main.Bridge.GetPortalByKey(ctx, portalKey)
if err != nil {
log.Err(err).Msg("Failed to get portal")
continue
}
meta := simplevent.EventMeta{
LogContext: func(c zerolog.Context) zerolog.Context {
return c.Str("update", "sync")
},
PortalKey: l.makePortalKey(conv.EntityURN),
CreatePortal: true,
PortalKey: portalKey,
CreatePortal: l.main.Config.Sync.CreateLimit == 0 || created <= l.main.Config.Sync.CreateLimit,
}
if portal == nil || portal.MXID == "" {
created++
}
updated++
var latestMessageTS time.Time
for _, msg := range conv.Messages.Elements {
......@@ -64,6 +77,11 @@ func (l *LinkedInClient) syncConversations(ctx context.Context) {
EventMeta: meta.WithType(bridgev2.RemoteEventChatResync),
LatestMessageTS: latestMessageTS,
})
if l.main.Config.Sync.UpdateLimit > 0 && updated >= l.main.Config.Sync.UpdateLimit {
log.Info().Msg("Update limit reached")
return
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment