~f4814n/frost

528722a8f48c8bc6978e31e24a914e7fa4c64e0f — Fabian Geiselhart 10 months ago dd5581f
RoomView: Basic encryption support
1 files changed, 28 insertions(+), 13 deletions(-)

M cmd/frost/room_view.go
M cmd/frost/room_view.go => cmd/frost/room_view.go +28 -13
@@ 125,6 125,8 @@ func (r *RoomView) update() {
			switch event.(type) {
			// EphemeralEvents should not be added to the room History
			case matrix.EphemeralEvent:
			case matrix.ToDeviceEvent:
			case matrix.AccountDataEvent:
			default:
				r.roomHistory.AddEvent(event)
			}


@@ 239,7 241,7 @@ func (e event) Layout(gtx Gtx) Dims {
	case matrix.RoomEvent:
		return e.layoutRoomEvent(gtx)
	default:
		panic("Unknown event type. What is going on?")
		panic(fmt.Sprintf("Should not have event in room history: %#v", e.Event))
	}
}



@@ 393,20 395,33 @@ func (e event) layoutRoomEvent(gtx Gtx) Dims {
}

func (e event) layoutRoomEventContent(gtx Gtx, msgWidth *int) Dims {
	var content layout.Widget
	switch e.Event.Base().Type {
	case "m.room.message":
		lbl := material.Body2(theme, e.Event.(matrix.RoomEvent).Content["body"].(string))
		if e.Own {
			lbl.Color = rgb(0x000000)
		} else {
			lbl.Color = rgb(0xffffff)
		}
		content = lbl.Layout
	default:
		lbl := material.Body1(theme, "[Unformattable Event]")
	var (
		err error
		content layout.Widget
	)

	e.Event, err = e.Event.(matrix.RoomEvent).Decrypted()


	if err != nil {
		lbl := material.Body2(theme, err.Error())
		lbl.Color = rgb(0xff0000)
		content = lbl.Layout
	} else {
		switch e.Event.Base().Type {
		case "m.room.message":
			lbl := material.Body2(theme, e.Event.(matrix.RoomEvent).Content["body"].(string))
			if e.Own {
				lbl.Color = rgb(0x000000)
			} else {
				lbl.Color = rgb(0xffffff)
			}
			content = lbl.Layout
		default:
			lbl := material.Body1(theme, "[Unformattable Event]")
			lbl.Color = rgb(0xff0000)
			content = lbl.Layout
		}
	}

	dims := content(gtx)