"net/http"
"os"
"path/filepath"
+ "strings"
"time"
"web/config"
sessionRepo := repository.NewSessionRepository(sessionDB)
appRepo := repository.NewAppRepository(appDB)
+ customCSS := config.CustomCSS
+ if !strings.HasPrefix(customCSS, "http://") &&
+ !strings.HasPrefix(customCSS, "https://") {
+ customCSS = "/static/" + customCSS
+ }
+
var logger *log.Logger
if len(config.Logfile) < 1 {
logger = log.New(os.Stdout, "", log.LstdFlags)
logger = log.New(lf, "", log.LstdFlags)
}
- s := service.NewService(config.ClientName, config.ClientScope, config.ClientWebsite, renderer, sessionRepo, appRepo)
+ s := service.NewService(config.ClientName, config.ClientScope, config.ClientWebsite, customCSS, renderer, sessionRepo, appRepo)
s = service.NewAuthService(sessionRepo, appRepo, s)
s = service.NewLoggingService(logger, s)
handler := service.NewHandler(s, config.StaticDirectory)
clientName string
clientScope string
clientWebsite string
+ customCSS string
renderer renderer.Renderer
sessionRepo model.SessionRepository
appRepo model.AppRepository
}
func NewService(clientName string, clientScope string, clientWebsite string,
- renderer renderer.Renderer, sessionRepo model.SessionRepository,
+ customCSS string, renderer renderer.Renderer, sessionRepo model.SessionRepository,
appRepo model.AppRepository) Service {
return &service{
clientName: clientName,
clientScope: clientScope,
clientWebsite: clientWebsite,
+ customCSS: customCSS,
renderer: renderer,
sessionRepo: sessionRepo,
appRepo: appRepo,
DefaultVisibility: c.Session.Settings.DefaultVisibility,
}
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
HasPrev: hasPrev,
PrevLink: prevLink,
PostContext: postContext,
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderTimelinePage(ctx, client, data)
addToReplyMap(replyMap, statuses[i].InReplyToID, statuses[i].ID, i+1)
}
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
Statuses: statuses,
PostContext: postContext,
ReplyMap: replyMap,
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderThreadPage(ctx, client, data)
nextLink = "/notifications?max_id=" + pg.MaxID
}
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
Notifications: notifications,
HasNext: hasNext,
NextLink: nextLink,
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderNotificationPage(ctx, client, data)
if err != nil {
nextLink = "/user/" + id + "?max_id=" + pg.MaxID
}
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
Statuses: statuses,
HasNext: hasNext,
NextLink: nextLink,
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderUserPage(ctx, client, data)
}
func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
data := &renderer.AboutData{
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderAboutPage(ctx, client, data)
if err != nil {
}
func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
- navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
+ commonData, err := svc.getCommonData(ctx, client, c)
if err != nil {
return
}
data := &renderer.EmojiData{
Emojis: emojis,
- NavbarData: navbarData,
+ CommonData: commonData,
}
err = svc.renderer.RenderEmojiPage(ctx, client, data)
return
}
-func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.NavbarData, err error) {
- notifications, err := c.GetNotifications(ctx, nil)
- if err != nil {
- return
+func (svc *service) getCommonData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.CommonData, err error) {
+ data = new(renderer.CommonData)
+
+ data.HeaderData = &renderer.HeaderData{
+ Title: "Web",
+ NotificationCount: 0,
+ CustomCSS: svc.customCSS,
}
- var notificationCount int
- for i := range notifications {
- if notifications[i].Pleroma != nil && !notifications[i].Pleroma.IsSeen {
- notificationCount++
+ if c != nil && c.Session.IsLoggedIn() {
+ notifications, err := c.GetNotifications(ctx, nil)
+ if err != nil {
+ return nil, err
}
- }
- u, err := c.GetAccountCurrentUser(ctx)
- if err != nil {
- return
- }
+ var notificationCount int
+ for i := range notifications {
+ if notifications[i].Pleroma != nil && !notifications[i].Pleroma.IsSeen {
+ notificationCount++
+ }
+ }
+
+ u, err := c.GetAccountCurrentUser(ctx)
+ if err != nil {
+ return nil, err
+ }
+
+ data.NavbarData = &renderer.NavbarData{
+ User: u,
+ NotificationCount: notificationCount,
+ }
- data = &renderer.NavbarData{
- User: u,
- NotificationCount: notificationCount,
+ data.HeaderData.NotificationCount = notificationCount
}
return