Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73e07e9

Browse files
committed
feat(notifications): improve logo_url and app_name fetching moving it to notifications package
1 parentb552267 commit73e07e9

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

‎cli/server.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,36 +1309,6 @@ func templateHelpers(options *coderd.Options) map[string]any {
13091309
returnmap[string]any{
13101310
"base_url":func()string {returnoptions.AccessURL.String() },
13111311
"current_year":func()string {returnstrconv.Itoa(time.Now().Year()) },
1312-
"logo_url":func()string {
1313-
ctx,cancel:=context.WithTimeout(context.Background(),1*time.Second)
1314-
defercancel()
1315-
1316-
logoURL,err:=options.Database.GetLogoURL(ctx)
1317-
iferr!=nil {
1318-
iferrors.Is(err,sql.ErrNoRows) {
1319-
returnnotifications.NotificationsDefaultLogoURL
1320-
}
1321-
1322-
return""
1323-
}
1324-
1325-
returnlogoURL
1326-
},
1327-
"app_name":func()string {
1328-
ctx,cancel:=context.WithTimeout(context.Background(),1*time.Second)
1329-
defercancel()
1330-
1331-
appName,err:=options.Database.GetApplicationName(ctx)
1332-
iferr!=nil {
1333-
iferrors.Is(err,sql.ErrNoRows) {
1334-
returnnotifications.NotificationsDefaultAppName
1335-
}
1336-
1337-
return""
1338-
}
1339-
1340-
returnappName
1341-
},
13421312
}
13431313
}
13441314

‎coderd/notifications/notifier.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package notifications
22

33
import (
44
"context"
5+
"database/sql"
56
"encoding/json"
7+
"errors"
68
"sync"
79
"text/template"
810

@@ -23,8 +25,8 @@ import (
2325
)
2426

2527
const (
26-
NotificationsDefaultLogoURL="https://coder.com/coder-logo-horizontal.png"
27-
NotificationsDefaultAppName="Coder"
28+
notificationsDefaultLogoURL="https://coder.com/coder-logo-horizontal.png"
29+
notificationsDefaultAppName="Coder"
2830
)
2931

3032
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
@@ -228,6 +230,30 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification
228230
returnnil,xerrors.Errorf("failed to resolve handler %q",msg.Method)
229231
}
230232

233+
appName,err:=n.store.GetApplicationName(ctx)
234+
iferr!=nil {
235+
if!errors.Is(err,sql.ErrNoRows) {
236+
returnnil,xerrors.Errorf("get application name: %w",err)
237+
}
238+
appName=notificationsDefaultAppName
239+
}
240+
241+
logoURL,err:=n.store.GetLogoURL(ctx)
242+
iferr!=nil {
243+
if!errors.Is(err,sql.ErrNoRows) {
244+
returnnil,xerrors.Errorf("get logo URL: %w",err)
245+
}
246+
logoURL=notificationsDefaultLogoURL
247+
}
248+
249+
helpers:=make(template.FuncMap)
250+
fork,v:=rangen.helpers {
251+
helpers[k]=v
252+
}
253+
254+
helpers["app_name"]=func()string {returnappName }
255+
helpers["logo_url"]=func()string {returnlogoURL }
256+
231257
vartitle,bodystring
232258
iftitle,err=render.GoTemplate(msg.TitleTemplate,payload,n.helpers);err!=nil {
233259
returnnil,xerrors.Errorf("render title: %w",err)

‎coderd/notifications/spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Store interface {
2222
FetchNewMessageMetadata(ctx context.Context,arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error)
2323
GetNotificationMessagesByStatus(ctx context.Context,arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage,error)
2424
GetNotificationsSettings(ctx context.Context) (string,error)
25+
GetApplicationName(ctx context.Context) (string,error)
26+
GetLogoURL(ctx context.Context) (string,error)
2527
}
2628

2729
// Handler is responsible for preparing and delivering a notification by a given method.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp