Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 6d75d5b

Browse files
authored
Merge pull request #50 from t3chguy/develop
Fix Spacing and add Date Separators [0.2.3]
2 parents 574b21a + c172123 commit 6d75d5b

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed

assets/css/main.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ td.roomAvatar {
5757
td.roomAvatar img {
5858
height: 96px;
5959
}
60+
tr.dateSep {
61+
background-color: lightblue;
62+
text-align: center;
63+
font-weight: bold;
64+
}
65+
td.nowrap {
66+
white-space: nowrap;
67+
width: 1px;
68+
}
6069
td.fullWidth {
6170
white-space: nowrap;
6271
}
@@ -66,6 +75,9 @@ table#roomHeader {
6675
table#roomList img {
6776
height: 60px;
6877
}
78+
table#timeline {
79+
width: 100%;
80+
}
6981
table#timeline tr {
7082
vertical-align: top;
7183
}
@@ -76,6 +88,9 @@ td.rightAlign {
7688
div.paginate {
7789
text-align: center;
7890
}
91+
div.paginate h4 {
92+
margin: 10px;
93+
}
7994
h2 {
8095
margin: 0;
8196
}

src/github.com/t3chguy/matrix-static/matrix-static.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package main
1717
import (
1818
"bytes"
1919
"flag"
20+
log "github.com/Sirupsen/logrus"
2021
"github.com/disintegration/letteravatar"
2122
"github.com/gin-contrib/cache"
2223
"github.com/gin-contrib/cache/persistence"
2324
"github.com/gin-contrib/pprof"
2425
"github.com/gin-gonic/gin"
2526
"github.com/matrix-org/dugong"
26-
log "github.com/Sirupsen/logrus"
2727
"github.com/t3chguy/go-gin-prometheus"
2828
"github.com/t3chguy/matrix-static/mxclient"
2929
"github.com/t3chguy/matrix-static/sanitizer"

src/github.com/t3chguy/matrix-static/templates/room-chat.qtpl

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55

66

77

8+
{% code
9+
func parseEventTimestamp(unixTime int) time.Time {
10+
return time.Unix(0, int64(unixTime)*int64(time.Millisecond))
11+
}
12+
%}
13+
814
{% func printTimestamp(unixTime int) %}
9-
{%s time.Unix(0, int64(unixTime)*int64(time.Millisecond)).Format("2 Jan 2006 15:04:05") %}
15+
{%s parseEventTimestamp(unixTime).Format("2 Jan 2006 15:04:05") %}
1016
{% endfunc %}
1117

1218

@@ -32,11 +38,11 @@
3238
return
3339
}
3440

35-
func getMemberEventContent(ev gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
41+
func getMemberEventContent(ev *gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
3642
return convertContentToMEC(ev.Content, homeserverBaseUrl)
3743
}
3844

39-
func getMemberEventPrevContent(ev gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
45+
func getMemberEventPrevContent(ev *gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
4046
return convertContentToMEC(ev.PrevContent, homeserverBaseUrl)
4147
}
4248

@@ -59,7 +65,7 @@
5965

6066

6167
{% stripspace %}
62-
{% func (p *RoomChatPage) textForMRoomMemberEvent(ev gomatrix.Event) %}
68+
{% func (p *RoomChatPage) textForMRoomMemberEvent(ev *gomatrix.Event) %}
6369
{% code
6470
content := getMemberEventContent(ev, p.HomeserverBaseURL)
6571
prevContent := getMemberEventPrevContent(ev, p.HomeserverBaseURL)
@@ -118,7 +124,7 @@
118124
{% endswitch %}
119125
{% endfunc %}
120126

121-
{% func (p *RoomChatPage) textForMRoomMessageEvent(ev gomatrix.Event) %}
127+
{% func (p *RoomChatPage) textForMRoomMessageEvent(ev *gomatrix.Event) %}
122128
{% switch ev.Content["msgtype"] %}
123129
{% case "m.image" %}
124130
{% code
@@ -184,20 +190,20 @@
184190
{% endswitch %}
185191
{% endfunc %}
186192

187-
{% func (p *RoomChatPage) printStateChange(ev gomatrix.Event, key, thing string) %}
193+
{% func (p *RoomChatPage) printStateChange(ev *gomatrix.Event, key, thing string) %}
188194
{% code
189195
prev := Str(ev.PrevContent[key])
190196
cur := Str(ev.Content[key])
191197
%}
192198

193-
{%= p.prettyPrintMember(ev.Sender) %}
199+
{%= p.prettyPrintMember(ev.Sender) %}{% space %}
194200

195201
{% if cur != "" && prev == "" %}
196-
set the {%s thing %} to "{%s cur %}".
202+
set the {% space %}{%s thing %}{% space %} to "{%s cur %}".
197203
{% elseif cur == "" && prev != "" %}
198-
removed the {%s thing %} "{%s prev %}".
204+
removed the {% space %}{%s thing %}{% space %} "{%s prev %}".
199205
{% else %}
200-
changed the {%s thing %} to "{%s cur %}" from "{%s prev %}".
206+
changed the {% space %}{%s thing %}{% space %} to "{%s cur %}" from "{%s prev %}".
201207
{% endif %}
202208
{% endfunc %}
203209

@@ -216,50 +222,75 @@
216222
</a>
217223
{% endfunc %}
218224

219-
{% func (p *RoomChatPage) printEvent(ev gomatrix.Event) %}
225+
{% code
226+
func needsDateSeparator(ev, prevEv *gomatrix.Event) bool {
227+
if prevEv == nil {
228+
return true
229+
}
230+
y1, m1, d1 := parseEventTimestamp(ev.Timestamp).Date()
231+
y2, m2, d2 := parseEventTimestamp(prevEv.Timestamp).Date()
232+
return y1 != y2 || m1 != m2 || d1 != d2
233+
}
234+
%}
235+
236+
{% func (p *RoomChatPage) printEvent(ev, prevEv *gomatrix.Event) %}
237+
{% if needsDateSeparator(ev, prevEv) %}
238+
<tr class="timestamp dateSep">
239+
<td colspan="3">{%s parseEventTimestamp(ev.Timestamp).Format("2 Jan 2006") %}</td>
240+
</tr>
241+
{% endif %}
242+
220243
<tr>
221-
{%= p.printPermalinkColumn(ev) %}
244+
<td class="timestamp nowrap">
245+
{% code
246+
time := parseEventTimestamp(ev.Timestamp)
247+
title := time.Format("2 Jan 2006 15:04:05")
248+
%}
249+
<a href="https://matrix.to/#/{%s p.RoomInfo.RoomID %}/{%s ev.ID %}" title="{%s title %}">
250+
{%s time.Format("15:04:05") %}
251+
</a>
252+
</td>
222253
{% switch ev.Type %}
223254
{% case "m.room.message" %}
224255
{% if ev.Content["msgtype"] == "m.emote" %}
225-
<td class="fullWidth"></td>
256+
<td></td>
226257
<td>
227258
*{% space %}{%= p.prettyPrintMember(ev.Sender) %}
228259
{% space %}{%= p.textForMRoomMessageEvent(ev) %}
229260
</td>
230261
{% else %}
231-
<td class="fullWidth">
262+
<td class="nowrap">
232263
{% if ev.Content["msgtype"] == "m.emote" %}*{% space %}{% endif %}
233264
{%= p.prettyPrintMember(ev.Sender) %}
234265
</td>
235266
<td>{%= p.textForMRoomMessageEvent(ev) %}</td>
236267
{% endif %}
237268

238269
{% case "m.room.member" %}
239-
<td class="fullWidth"></td>
270+
<td></td>
240271
<td>{%= p.textForMRoomMemberEvent(ev) %}</td>
241272
{% case "m.room.name" %}
242-
<td class="fullWidth"></td>
273+
<td></td>
243274
<td>{%= p.printStateChange(ev, "name", "room name") %}</td>
244275
{% case "m.room.topic" %}
245-
<td class="fullWidth"></td>
276+
<td></td>
246277
<td>{%= p.printStateChange(ev, "topic", "room topic") %}</td>
247278
{% case "m.room.history_visibility" %}
248-
<td class="fullWidth"></td>
279+
<td></td>
249280
<td>{%= p.printStateChange(ev, "history_visibility", "history visibility") %}</td>
250281
{% case "m.room.join_rules" %}
251-
<td class="fullWidth"></td>
282+
<td></td>
252283
<td>{%= p.printStateChange(ev, "join_rule", "join rule") %}</td>
253284
{% case "m.room.avatar" %}
254-
<td class="fullWidth"></td>
285+
<td></td>
255286
<td>
256287
Room Avatar Renderer.
257288
</td>
258289
{% case "m.room.power_levels" %}
259-
<td class="fullWidth"></td>
290+
<td></td>
260291
<td>{%= p.prettyPrintMember(ev.Sender) %} changed room power levels.</td>
261292
{% case "im.vector.modular.widgets" %}
262-
<td class="fullWidth"></td>
293+
<td></td>
263294
{% code
264295
widgetName := StringerfaceFallback(ev.Content["name"], ev.PrevContent["name"], ev.Content["type"], ev.PrevContent["type"])
265296
if widgetName == "" {
@@ -276,12 +307,6 @@
276307
</tr>
277308
{% endfunc %}
278309

279-
{% func (p *RoomChatPage) printPermalinkColumn(ev gomatrix.Event) %}
280-
<td class="timestamp fullWidth">
281-
<a href="https://matrix.to/#/{%s p.RoomInfo.RoomID %}/{%s ev.ID %}">{%= printTimestamp(ev.Timestamp) %}</a>
282-
</td>
283-
{% endfunc %}
284-
285310

286311

287312
{% func (p *RoomChatPage) Title() %}
@@ -323,8 +348,10 @@
323348
</tr>
324349
</thead>
325350
<tbody>
351+
{% code var prevEv gomatrix.Event %}
326352
{% for _, event := range p.Events %}
327-
{%= p.printEvent(event) %}
353+
{%= p.printEvent(&event, &prevEv) %}
354+
{% code prevEv = event %}
328355
{% endfor %}
329356
</tbody>
330357
</table>

0 commit comments

Comments
 (0)