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

Commit 6d345ed

Browse files
authored
Merge pull request #57 from t3chguy/develop
0.2.4
2 parents 6d75d5b + a068caa commit 6d345ed

File tree

12 files changed

+89
-22
lines changed

12 files changed

+89
-22
lines changed

assets/css/main.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ h2 {
9696
}
9797
span.redacted {
9898
color: red;
99+
}
100+
tr.evHighlight {
101+
background-color: yellow;
99102
}

src/github.com/t3chguy/matrix-static/job-room-aliases.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ func (job RoomAliasesJob) Work(w *Worker) {
4444
job.pageSize,
4545
job.page,
4646
}
47+
room.Access()
4748
}

src/github.com/t3chguy/matrix-static/job-room-events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ func (job RoomEventsJob) Work(w *Worker) {
5252
atBottomEnd,
5353
err,
5454
}
55+
room.Access()
5556
}

src/github.com/t3chguy/matrix-static/job-room-forwardpaginate.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,33 @@
1414

1515
package main
1616

17+
import (
18+
log "github.com/Sirupsen/logrus"
19+
"sync"
20+
"time"
21+
)
22+
1723
// This Job has no Resp.
1824

19-
type RoomForwardPaginateJob struct{}
25+
type RoomForwardPaginateJob struct {
26+
wg *sync.WaitGroup
27+
}
28+
29+
const LastAccessDiscardDuration = 30 * time.Minute
2030

2131
func (job RoomForwardPaginateJob) Work(w *Worker) {
32+
// discard old rooms first
33+
numRoomsBefore := len(w.rooms)
34+
for id, room := range w.rooms {
35+
if room.LastAccess.Before(time.Now().Add(-LastAccessDiscardDuration)) {
36+
delete(w.rooms, id)
37+
}
38+
}
39+
numRoomsAfter := len(w.rooms)
40+
log.WithField("worker", w.ID).WithField("numRooms", numRoomsAfter).Infof("Removed %d rooms", numRoomsBefore-numRoomsAfter)
41+
2242
for _, room := range w.rooms {
2343
room.ForwardPaginateRoom()
2444
}
45+
job.wg.Done()
2546
}

src/github.com/t3chguy/matrix-static/job-room-memberinfo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ func (job RoomMemberInfoJob) Work(w *Worker) {
5959
memberInfo,
6060
err,
6161
}
62+
room.Access()
6263
}

src/github.com/t3chguy/matrix-static/job-room-members.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ func (job RoomMembersJob) Work(w *Worker) {
5050
job.pageSize,
5151
job.page,
5252
}
53+
room.Access()
5354
}

src/github.com/t3chguy/matrix-static/job-room-powerlevels.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ func (job RoomPowerLevelsJob) Work(w *Worker) {
3535
room.RoomInfo(),
3636
powerLevels,
3737
}
38+
room.Access()
3839
}

src/github.com/t3chguy/matrix-static/job-room-servers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ func (job RoomServersJob) Work(w *Worker) {
4444
job.pageSize,
4545
job.page,
4646
}
47+
room.Access()
4748
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"os"
3535
"path/filepath"
3636
"strconv"
37+
"sync"
3738
"time"
3839
"unicode"
3940
"unicode/utf8"
@@ -176,6 +177,13 @@ func main() {
176177

177178
roomRouter := publicRouter.Group("/room/:roomID/")
178179
{
180+
roomRouter.GET("/$:eventID", func(c *gin.Context) {
181+
eventID := c.Param("eventID")
182+
roomID := c.Param("roomID")
183+
184+
c.Redirect(http.StatusTemporaryRedirect, "/room/"+roomID+"/?anchor=$"+eventID+"&highlight")
185+
})
186+
179187
// Load room worker into request object so that we can do any clean up etc here
180188
roomRouter.Use(func(c *gin.Context) {
181189
roomID := c.Param("roomID")
@@ -244,6 +252,7 @@ func main() {
244252
}
245253

246254
events := mxclient.ReverseEventsCopy(jobResult.Events)
255+
_, highlight := c.GetQuery("highlight")
247256

248257
templates.WritePageTemplate(c.Writer, &templates.RoomChatPage{
249258
RoomInfo: jobResult.RoomInfo,
@@ -258,6 +267,7 @@ func main() {
258267

259268
Sanitizer: sanitizerFn,
260269
HomeserverBaseURL: client.HomeserverURL.String(),
270+
Highlight: highlight,
261271
})
262272
})
263273

@@ -362,13 +372,17 @@ func startPublicRoomListTimer(worldReadableRooms *mxclient.WorldReadableRooms) {
362372
}
363373
}
364374

365-
const LazyForwardPaginateRooms = time.Minute
375+
const LazyForwardPaginateRooms = 2 * time.Minute
366376

367377
func startForwardPaginator(workers *Workers) {
368-
t := time.NewTicker(LazyForwardPaginateRooms)
378+
//t := time.NewTicker(LazyForwardPaginateRooms)
379+
wg := sync.WaitGroup{}
369380
for {
370-
<-t.C
381+
//<-t.C
382+
time.Sleep(LazyForwardPaginateRooms)
383+
wg.Add(int(workers.numWorkers))
371384
log.Info("Forward paginating all loaded rooms")
372-
workers.JobForAllWorkers(RoomForwardPaginateJob{})
385+
workers.JobForAllWorkers(RoomForwardPaginateJob{&wg})
386+
wg.Wait()
373387
}
374388
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"github.com/matrix-org/gomatrix"
2020
"github.com/t3chguy/matrix-static/utils"
21+
"time"
2122
)
2223

2324
type RoomInfo struct {
@@ -46,6 +47,12 @@ type Room struct {
4647
latestRoomState RoomState
4748

4849
HasReachedHistoricEndOfTimeline bool
50+
51+
LastAccess time.Time
52+
}
53+
54+
func (r *Room) Access() {
55+
r.LastAccess = time.Now()
4956
}
5057

5158
// ForwardPaginateRoom queries the API for any events newer than the latest one currently in the timeline and appends them.
@@ -197,6 +204,7 @@ func (m *Client) NewRoom(roomID string) (*Room, error) {
197204
backPaginationToken: resp.Messages.Start,
198205
eventList: filteredEventList,
199206
latestRoomState: *NewRoomState(m),
207+
LastAccess: time.Now(),
200208
}
201209

202210
for _, event := range resp.State {

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,26 @@ func ShouldHideEvent(ev gomatrix.Event) bool {
6868
// m.room.aliases
6969
// m.room.canonical_alias
7070

71-
if ev.Type == "m.room.history_visibility" ||
72-
ev.Type == "m.room.join_rules" ||
73-
ev.Type == "m.room.member" ||
74-
ev.Type == "m.room.power_levels" ||
75-
ev.Type == "m.room.message" ||
76-
ev.Type == "m.room.name" ||
77-
ev.Type == "m.room.topic" ||
78-
ev.Type == "m.room.avatar" {
79-
return false
80-
}
71+
if ev.StateKey == nil {
72+
// Message Event
73+
if ev.Type == "m.room.message" {
74+
return false
75+
}
76+
} else {
77+
// State Event
78+
if ev.Type == "m.room.history_visibility" ||
79+
ev.Type == "m.room.join_rules" ||
80+
ev.Type == "m.room.member" ||
81+
ev.Type == "m.room.power_levels" ||
82+
ev.Type == "m.room.name" ||
83+
ev.Type == "m.room.topic" ||
84+
ev.Type == "m.room.avatar" {
85+
return false
86+
}
8187

82-
if ev.Type == "im.vector.modular.widgets" {
83-
return false
88+
if ev.Type == "im.vector.modular.widgets" {
89+
return false
90+
}
8491
}
8592

8693
return true

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
AtTopEnd bool
5858
AtBottomEnd bool
5959

60-
Sanitizer *sanitizer.Sanitizer
60+
Sanitizer *sanitizer.Sanitizer
6161
HomeserverBaseURL string
62+
Highlight bool
6263
}
6364
%}
6465

@@ -233,14 +234,18 @@
233234
}
234235
%}
235236

236-
{% func (p *RoomChatPage) printEvent(ev, prevEv *gomatrix.Event) %}
237+
{% func (p *RoomChatPage) printEvent(ev, prevEv *gomatrix.Event, highlight bool) %}
237238
{% if needsDateSeparator(ev, prevEv) %}
238239
<tr class="timestamp dateSep">
239240
<td colspan="3">{%s parseEventTimestamp(ev.Timestamp).Format("2 Jan 2006") %}</td>
240241
</tr>
241242
{% endif %}
242243

244+
{% if highlight %}
245+
<tr class="evHighlight">
246+
{% else %}
243247
<tr>
248+
{% endif %}
244249
<td class="timestamp nowrap">
245250
{% code
246251
time := parseEventTimestamp(ev.Timestamp)
@@ -348,9 +353,12 @@
348353
</tr>
349354
</thead>
350355
<tbody>
351-
{% code var prevEv gomatrix.Event %}
352-
{% for _, event := range p.Events %}
353-
{%= p.printEvent(&event, &prevEv) %}
356+
{% code
357+
var prevEv gomatrix.Event
358+
numEvents := len(p.Events)
359+
%}
360+
{% for i, event := range p.Events %}
361+
{%= p.printEvent(&event, &prevEv, i == numEvents - 1) %}
354362
{% code prevEv = event %}
355363
{% endfor %}
356364
</tbody>

0 commit comments

Comments
 (0)