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

Commit

Permalink
Merge pull request #50 from t3chguy/develop
Browse files Browse the repository at this point in the history
Fix Spacing and add Date Separators [0.2.3]
  • Loading branch information
t3chguy authored Oct 4, 2017
2 parents 574b21a + c172123 commit 6d75d5b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
15 changes: 15 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ td.roomAvatar {
td.roomAvatar img {
height: 96px;
}
tr.dateSep {
background-color: lightblue;
text-align: center;
font-weight: bold;
}
td.nowrap {
white-space: nowrap;
width: 1px;
}
td.fullWidth {
white-space: nowrap;
}
Expand All @@ -66,6 +75,9 @@ table#roomHeader {
table#roomList img {
height: 60px;
}
table#timeline {
width: 100%;
}
table#timeline tr {
vertical-align: top;
}
Expand All @@ -76,6 +88,9 @@ td.rightAlign {
div.paginate {
text-align: center;
}
div.paginate h4 {
margin: 10px;
}
h2 {
margin: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/github.com/t3chguy/matrix-static/matrix-static.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package main
import (
"bytes"
"flag"
log "github.com/Sirupsen/logrus"
"github.com/disintegration/letteravatar"
"github.com/gin-contrib/cache"
"github.com/gin-contrib/cache/persistence"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/matrix-org/dugong"
log "github.com/Sirupsen/logrus"
"github.com/t3chguy/go-gin-prometheus"
"github.com/t3chguy/matrix-static/mxclient"
"github.com/t3chguy/matrix-static/sanitizer"
Expand Down
85 changes: 56 additions & 29 deletions src/github.com/t3chguy/matrix-static/templates/room-chat.qtpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@



{% code
func parseEventTimestamp(unixTime int) time.Time {
return time.Unix(0, int64(unixTime)*int64(time.Millisecond))
}
%}

{% func printTimestamp(unixTime int) %}
{%s time.Unix(0, int64(unixTime)*int64(time.Millisecond)).Format("2 Jan 2006 15:04:05") %}
{%s parseEventTimestamp(unixTime).Format("2 Jan 2006 15:04:05") %}
{% endfunc %}


Expand All @@ -32,11 +38,11 @@
return
}

func getMemberEventContent(ev gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
func getMemberEventContent(ev *gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
return convertContentToMEC(ev.Content, homeserverBaseUrl)
}

func getMemberEventPrevContent(ev gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
func getMemberEventPrevContent(ev *gomatrix.Event, homeserverBaseUrl string) MemberEventContent {
return convertContentToMEC(ev.PrevContent, homeserverBaseUrl)
}

Expand All @@ -59,7 +65,7 @@


{% stripspace %}
{% func (p *RoomChatPage) textForMRoomMemberEvent(ev gomatrix.Event) %}
{% func (p *RoomChatPage) textForMRoomMemberEvent(ev *gomatrix.Event) %}
{% code
content := getMemberEventContent(ev, p.HomeserverBaseURL)
prevContent := getMemberEventPrevContent(ev, p.HomeserverBaseURL)
Expand Down Expand Up @@ -118,7 +124,7 @@
{% endswitch %}
{% endfunc %}

{% func (p *RoomChatPage) textForMRoomMessageEvent(ev gomatrix.Event) %}
{% func (p *RoomChatPage) textForMRoomMessageEvent(ev *gomatrix.Event) %}
{% switch ev.Content["msgtype"] %}
{% case "m.image" %}
{% code
Expand Down Expand Up @@ -184,20 +190,20 @@
{% endswitch %}
{% endfunc %}

{% func (p *RoomChatPage) printStateChange(ev gomatrix.Event, key, thing string) %}
{% func (p *RoomChatPage) printStateChange(ev *gomatrix.Event, key, thing string) %}
{% code
prev := Str(ev.PrevContent[key])
cur := Str(ev.Content[key])
%}

{%= p.prettyPrintMember(ev.Sender) %}
{%= p.prettyPrintMember(ev.Sender) %}{% space %}

{% if cur != "" && prev == "" %}
set the {%s thing %} to "{%s cur %}".
set the {% space %}{%s thing %}{% space %} to "{%s cur %}".
{% elseif cur == "" && prev != "" %}
removed the {%s thing %} "{%s prev %}".
removed the {% space %}{%s thing %}{% space %} "{%s prev %}".
{% else %}
changed the {%s thing %} to "{%s cur %}" from "{%s prev %}".
changed the {% space %}{%s thing %}{% space %} to "{%s cur %}" from "{%s prev %}".
{% endif %}
{% endfunc %}

Expand All @@ -216,50 +222,75 @@
</a>
{% endfunc %}

{% func (p *RoomChatPage) printEvent(ev gomatrix.Event) %}
{% code
func needsDateSeparator(ev, prevEv *gomatrix.Event) bool {
if prevEv == nil {
return true
}
y1, m1, d1 := parseEventTimestamp(ev.Timestamp).Date()
y2, m2, d2 := parseEventTimestamp(prevEv.Timestamp).Date()
return y1 != y2 || m1 != m2 || d1 != d2
}
%}

{% func (p *RoomChatPage) printEvent(ev, prevEv *gomatrix.Event) %}
{% if needsDateSeparator(ev, prevEv) %}
<tr class="timestamp dateSep">
<td colspan="3">{%s parseEventTimestamp(ev.Timestamp).Format("2 Jan 2006") %}</td>
</tr>
{% endif %}

<tr>
{%= p.printPermalinkColumn(ev) %}
<td class="timestamp nowrap">
{% code
time := parseEventTimestamp(ev.Timestamp)
title := time.Format("2 Jan 2006 15:04:05")
%}
<a href="https://matrix.to/#/{%s p.RoomInfo.RoomID %}/{%s ev.ID %}" title="{%s title %}">
{%s time.Format("15:04:05") %}
</a>
</td>
{% switch ev.Type %}
{% case "m.room.message" %}
{% if ev.Content["msgtype"] == "m.emote" %}
<td class="fullWidth"></td>
<td></td>
<td>
*{% space %}{%= p.prettyPrintMember(ev.Sender) %}
{% space %}{%= p.textForMRoomMessageEvent(ev) %}
</td>
{% else %}
<td class="fullWidth">
<td class="nowrap">
{% if ev.Content["msgtype"] == "m.emote" %}*{% space %}{% endif %}
{%= p.prettyPrintMember(ev.Sender) %}
</td>
<td>{%= p.textForMRoomMessageEvent(ev) %}</td>
{% endif %}

{% case "m.room.member" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.textForMRoomMemberEvent(ev) %}</td>
{% case "m.room.name" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.printStateChange(ev, "name", "room name") %}</td>
{% case "m.room.topic" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.printStateChange(ev, "topic", "room topic") %}</td>
{% case "m.room.history_visibility" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.printStateChange(ev, "history_visibility", "history visibility") %}</td>
{% case "m.room.join_rules" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.printStateChange(ev, "join_rule", "join rule") %}</td>
{% case "m.room.avatar" %}
<td class="fullWidth"></td>
<td></td>
<td>
Room Avatar Renderer.
</td>
{% case "m.room.power_levels" %}
<td class="fullWidth"></td>
<td></td>
<td>{%= p.prettyPrintMember(ev.Sender) %} changed room power levels.</td>
{% case "im.vector.modular.widgets" %}
<td class="fullWidth"></td>
<td></td>
{% code
widgetName := StringerfaceFallback(ev.Content["name"], ev.PrevContent["name"], ev.Content["type"], ev.PrevContent["type"])
if widgetName == "" {
Expand All @@ -276,12 +307,6 @@
</tr>
{% endfunc %}

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



{% func (p *RoomChatPage) Title() %}
Expand Down Expand Up @@ -323,8 +348,10 @@
</tr>
</thead>
<tbody>
{% code var prevEv gomatrix.Event %}
{% for _, event := range p.Events %}
{%= p.printEvent(event) %}
{%= p.printEvent(&event, &prevEv) %}
{% code prevEv = event %}
{% endfor %}
</tbody>
</table>
Expand Down

0 comments on commit 6d75d5b

Please sign in to comment.