diff options
author | smagnin <simon.magnin-feysot@smagnin.org> | 2020-04-07 01:26:02 +0200 |
---|---|---|
committer | smagnin <simon.magnin-feysot@smagnin.org> | 2020-04-07 01:26:02 +0200 |
commit | f0e5e0022f565034393a8d5f0afcbd21470284c3 (patch) | |
tree | ca3b3996e487fe43d9f34716d60626fb4dc15331 /ui/messages | |
parent | 3ddf85763d6dfe8c5ddecf5022f571e93b9a2a63 (diff) |
add text for video message
Diffstat (limited to 'ui/messages')
-rw-r--r-- | ui/messages/parser.go | 3 | ||||
-rw-r--r-- | ui/messages/videomessage.go | 92 |
2 files changed, 95 insertions, 0 deletions
diff --git a/ui/messages/parser.go b/ui/messages/parser.go index 75c564e..ce5827a 100644 --- a/ui/messages/parser.go +++ b/ui/messages/parser.go @@ -144,6 +144,9 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.Event debug.Printf("Failed to download %s: %v", evt.Content.URL, err) } return NewImageMessage(matrix, evt, displayname, evt.Content.Body, hs, id, data) + case "m.video": + _, hs, id, _ := matrix.Download(evt.Content.URL) + return NewVideoMessage(matrix, evt, displayname, evt.Content.Body, hs, id) } return nil } diff --git a/ui/messages/videomessage.go b/ui/messages/videomessage.go new file mode 100644 index 0000000..d5b87f8 --- /dev/null +++ b/ui/messages/videomessage.go @@ -0,0 +1,92 @@ +// gomuks - A terminal Matrix client written in Go. +// Copyright (C) 2019 Tulir Asokan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +package messages + +import ( + "fmt" + + "maunium.net/go/gomuks/matrix/event" + "maunium.net/go/mauview" + + "maunium.net/go/gomuks/config" + "maunium.net/go/gomuks/interface" + "maunium.net/go/gomuks/ui/messages/tstring" +) + +type VideoMessage struct { + Body string + Homeserver string + FileID string + buffer []tstring.TString + + matrix ifc.MatrixContainer +} + +// NewVideoMessage creates a new VideoMessage object with the provided values and the default state. +func NewVideoMessage(matrix ifc.MatrixContainer, evt *event.Event, displayname string, body, homeserver, fileID string) *UIMessage { + return newUIMessage(evt, displayname, &VideoMessage{ + Body: body, + Homeserver: homeserver, + FileID: fileID, + matrix: matrix, + }) +} + +func (msg *VideoMessage) Clone() MessageRenderer { + return &VideoMessage{ + Body: msg.Body, + Homeserver: msg.Homeserver, + FileID: msg.FileID, + matrix: msg.matrix, + } +} + +func (msg *VideoMessage) NotificationContent() string { + return "Sent a video" +} + +func (msg *VideoMessage) PlainText() string { + return fmt.Sprintf("%s: %s", msg.Body, msg.matrix.GetDownloadURL(msg.Homeserver, msg.FileID)) +} + +func (msg *VideoMessage) String() string { + return fmt.Sprintf(`&messages.VideoMessage{Body="%s", Homeserver="%s", FileID="%s"}`, msg.Body, msg.Homeserver, msg.FileID) +} + +func (msg *VideoMessage) Path() string { + return msg.matrix.GetCachePath(msg.Homeserver, msg.FileID) +} + +func (msg *VideoMessage) RegisterMatrix(matrix ifc.MatrixContainer) { + msg.matrix = matrix +} + +// Print only Plain Text +func (msg *VideoMessage) CalculateBuffer(prefs config.UserPreferences, width int, uiMsg *UIMessage) { + msg.buffer = calculateBufferWithText(prefs, tstring.NewTString(msg.PlainText()), width, uiMsg) + return +} + +func (msg *VideoMessage) Height() int { + return len(msg.buffer) +} + +func (msg *VideoMessage) Draw(screen mauview.Screen) { + for y, line := range msg.buffer { + line.Draw(screen, 0, y) + } +} |