Skip to content

Commit

Permalink
thread deep linking, ignore html errors, css has templating logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Mar 25, 2024
1 parent 4338cda commit abe1b90
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
21 changes: 19 additions & 2 deletions internal/viewer/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (v *Viewer) channelHandler(w http.ResponseWriter, r *http.Request, id strin
page := v.view()
page.Conversation = *ci
page.Messages = mm
template := "index.html"

template := "index.html" // for deep links
if isHXRequest(r) {
template = "hx_conversation"
}
Expand Down Expand Up @@ -134,7 +135,23 @@ func (v *Viewer) threadHandler(w http.ResponseWriter, r *http.Request, id string
page.Conversation = *ci
page.ThreadMessages = mm
page.ThreadID = ts
if err := v.tmpl.ExecuteTemplate(w, "hx_thread", page); err != nil {

var template string
if isHXRequest(r) {
template = "hx_thread"
} else {
template = "index.html"

// if we're deep linking, channel view might not contain the messages,
// so we need to fetch them.
msg, err := v.src.AllMessages(id)
if err != nil {
v.lg.Printf("error: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
page.Messages = msg
}
if err := v.tmpl.ExecuteTemplate(w, template, page); err != nil {
v.lg.Printf("error: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down
73 changes: 40 additions & 33 deletions internal/viewer/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ <h1>Slackdump Browser</h1>
</section>
<section id="thread" class="thread">
<!-- Thread messages go here -->
{{ if .ThreadMessages }}
{{ template "hx_thread" . }}
{{ end }}
</section>
</div>
</body>
Expand Down Expand Up @@ -112,7 +115,8 @@ <h2>{{ rendername .Conversation }}</h2>

{{define "hx_thread"}}
<h2>Thread: {{ .ThreadID }}</h2>
<p><a id="close-thread" href="#">Close Pane</a></p>
<p><a id="close-thread" href="#">[X]</a></p>
<p><a id="thread-link" href="{{.Conversation.ID}}/{{ .ThreadID }}">Link to this thread</a></p>
{{ range $i, $el := .ThreadMessages }}
<article class="message">
{{ template "render_message" $el }}
Expand Down Expand Up @@ -144,6 +148,36 @@ <h2>Thread: {{ .ThreadID }}</h2>
</div>
{{ end }}



{{ define "hx_user" }}
<h2>User: {{ displayname .ID }}</h2>
<p><a id="close-user" href="#">[X]</a></p>
<article class="user">
{{ if . }}
{{ displayname .ID }}<br>
<a href="mailto:{{ .Profile.Email}}" target="_blank">{{ .Profile.Email }}</a><br>
<a href="{{.Profile.Image512}}" target="_blank">
<img src="{{ .Profile.Image192}}" alt="{{ displayname .ID }}">
</a><br>
<ul>
{{ if .Profile.RealName }}<li>Real name: {{ .Profile.RealName }}</li>{{ end }}
{{ if .Profile.Skype }}<li>Skype: {{ .Profile.Skype }}</li>{{ end }}
{{ if .Profile.Team }}<li>Team: {{ .Profile.Team }}</li>{{ end }}
</ul>
{{ else }}
<p>Unknown</p>
{{ end }}
</article>
<script>
document.getElementById('close-user').addEventListener('click', function (e) {
e.preventDefault();
document.querySelector('.conversations').style.flex = '1';
document.querySelector('.thread').style.display = 'none';
});
</script>
{{ end }}

{{ define "hx_css" }}
<style>
body {
Expand Down Expand Up @@ -210,14 +244,15 @@ <h2>Thread: {{ .ThreadID }}</h2>
text-align: center;
}

.conversations,
.thread {
flex: 1;
.conversations {
flex: {{ if .ThreadID }}0 0 40%{{ else }}1{{ end }};
overflow-y: auto;
}

.thread {
display: none;
flex: 1;
overflow-y: auto;
display: {{ if .ThreadID }}block{{ else }}none{{ end }};
}

.message-timestamp,
Expand Down Expand Up @@ -246,31 +281,3 @@ <h2>Thread: {{ .ThreadID }}</h2>
}
</style>
{{ end }}

{{ define "hx_user" }}
<h2>User: {{ displayname .ID }}</h2>
<p><a id="close-user" href="#">Close pane</a></p>
<article class="user">
{{ if . }}
{{ displayname .ID }}<br>
<a href="mailto:{{ .Profile.Email}}" target="_blank">{{ .Profile.Email }}</a><br>
<a href="{{.Profile.Image512}}" target="_blank">
<img src="{{ .Profile.Image192}}" alt="{{ displayname .ID }}">
</a><br>
<ul>
{{ if .Profile.RealName }}<li>Real name: {{ .Profile.RealName }}</li>{{ end }}
{{ if .Profile.Skype }}<li>Skype: {{ .Profile.Skype }}</li>{{ end }}
{{ if .Profile.Team }}<li>Team: {{ .Profile.Team }}</li>{{ end }}
</ul>
{{ else }}
<p>Unknown</p>
{{ end }}
</article>
<script>
document.getElementById('close-user').addEventListener('click', function (e) {
e.preventDefault();
document.querySelector('.conversations').style.flex = '1';
document.querySelector('.thread').style.display = 'none';
});
</script>
{{ end }}

0 comments on commit abe1b90

Please sign in to comment.