aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-17 13:46:02 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-17 13:46:02 +0300
commitb76c301145c543ebcdc5534d4f292b056aa51219 (patch)
tree569b66f60ee40f85c8ebc090c9162348a3b15567 /matrix
parentfe439f076ad3d76c459c9a76c4bbdcda5182ed85 (diff)
Add initial support for rendering replies
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go49
1 files changed, 39 insertions, 10 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 7856ac7..fe0bfff 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -334,13 +334,39 @@ func (c *Container) HandleRedaction(source EventSource, evt *mautrix.Event) {
return
}
- // TODO make this less hacky?
- message := roomView.ParseEvent(redactedEvt)
- if message != nil {
- roomView.AddMessage(message)
- if c.syncer.FirstSyncDone {
- c.ui.Render()
- }
+ roomView.AddRedaction(redactedEvt)
+ if c.syncer.FirstSyncDone {
+ c.ui.Render()
+ }
+}
+
+func (c *Container) HandleEdit(room *rooms.Room, editsID string, editEvent *event.Event) {
+ var origEvt *event.Event
+ err := c.history.Update(room, editsID, func(evt *event.Event) error {
+ evt.Gomuks.Edits = append(evt.Gomuks.Edits, editEvent)
+ origEvt = evt
+ return nil
+ })
+ if err != nil {
+ debug.Print("Failed to store edit in history db:", err)
+ }
+ if !c.config.AuthCache.InitialSyncDone {
+ return
+ }
+
+ roomView := c.ui.MainView().GetRoom(editEvent.RoomID)
+ if roomView == nil {
+ debug.Printf("Failed to handle edit event %v: No room view found.", editEvent)
+ return
+ }
+
+ if !room.Loaded() {
+ return
+ }
+
+ roomView.AddEdit(origEvt)
+ if c.syncer.FirstSyncDone {
+ c.ui.Render()
}
}
@@ -354,6 +380,11 @@ func (c *Container) HandleMessage(source EventSource, mxEvent *mautrix.Event) {
return
}
+ if editID := mxEvent.Content.GetRelatesTo().GetReplaceID(); len(editID) > 0 {
+ c.HandleEdit(room, editID, event.Wrap(mxEvent))
+ return
+ }
+
events, err := c.history.Append(room, []*mautrix.Event{mxEvent})
if err != nil {
debug.Printf("Failed to add event %s to history: %v", mxEvent.ID, err)
@@ -384,10 +415,8 @@ func (c *Container) HandleMessage(source EventSource, mxEvent *mautrix.Event) {
}
}
- // TODO switch to roomView.AddEvent
- message := roomView.ParseEvent(evt)
+ message := roomView.AddEvent(evt)
if message != nil {
- roomView.AddMessage(message)
roomView.MxRoom().LastReceivedMessage = message.Time()
if c.syncer.FirstSyncDone {
pushRules := c.PushRules().GetActions(roomView.MxRoom(), evt.Event).Should()