-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream.go
65 lines (55 loc) · 1.67 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// +build go1.14
package notifsapp
import (
"context"
"fmt"
"html/template"
"io"
notifcomponent "github.com/shurcooL/home/internal/exp/app/notifsapp/component"
"github.com/shurcooL/home/internal/exp/service/notification"
"github.com/shurcooL/htmlg"
"github.com/shurcooL/users"
)
// renderStreamBodyInnerHTML renders the inner HTML of
// the <body> element of the notifications stream view.
// It's safe for concurrent use.
func renderStreamBodyInnerHTML(ctx context.Context, w io.Writer, gopherbot bool, notificationService notification.Service, authenticatedUser users.User, bodyTop template.HTML) error {
notifs, notifsError := notificationService.ListNotifications(ctx, notification.ListOptions{
All: true,
})
var error string
if notifsError != nil {
error = "There was a problem getting latest notifications."
if authenticatedUser.SiteAdmin {
error += "\n\n" + notifsError.Error()
}
}
_, err := io.WriteString(w, bodyPre)
if err != nil {
return err
}
_, err = io.WriteString(w, string(bodyTop))
if err != nil {
return err
}
// Render the tabnav.
err = htmlg.RenderComponents(w, notificationTabnav(streamTab))
if err != nil {
return fmt.Errorf("htmlg.RenderComponents: %v", err)
}
_, err = io.WriteString(w, `<div class="showNotifications"><label><input id="show" type="checkbox" checked>Show Notifications</label></div>`)
if err != nil {
return err
}
// Render the notification stream.
err = htmlg.RenderComponents(w, notifcomponent.Stream{
Notifications: notifs,
Error: error,
GopherBot: gopherbot,
})
if err != nil {
return fmt.Errorf("htmlg.RenderComponents: %v", err)
}
_, err = io.WriteString(w, bodyPost)
return err
}