diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-04-14 11:50:18 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-04-14 11:50:18 +0300 |
commit | f5530ff99c62d0d97dfae352e922f8327ff418c1 (patch) | |
tree | cdc5dade10dde2209b7906ccd259c469285226c1 /ui | |
parent | 782ba0657a0bddc6ccb31b1792f3fbf4500a0087 (diff) |
Move message parsing to parser subpackage
Diffstat (limited to 'ui')
-rw-r--r-- | ui/messages/parser/htmlparser.go (renamed from ui/messages/htmlparser.go) | 2 | ||||
-rw-r--r-- | ui/messages/parser/htmltagarray.go (renamed from ui/messages/htmltagarray.go) | 2 | ||||
-rw-r--r-- | ui/messages/parser/parser.go (renamed from ui/messages/parser.go) | 17 | ||||
-rw-r--r-- | ui/view-main.go | 4 |
4 files changed, 13 insertions, 12 deletions
diff --git a/ui/messages/htmlparser.go b/ui/messages/parser/htmlparser.go index aa6211e..cb8f254 100644 --- a/ui/messages/htmlparser.go +++ b/ui/messages/parser/htmlparser.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -package messages +package parser import ( "fmt" diff --git a/ui/messages/htmltagarray.go b/ui/messages/parser/htmltagarray.go index 597f0c7..4cd4245 100644 --- a/ui/messages/htmltagarray.go +++ b/ui/messages/parser/htmltagarray.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -package messages +package parser // TagWithMeta is an open HTML tag with some metadata (e.g. list index, a href value). type TagWithMeta struct { diff --git a/ui/messages/parser.go b/ui/messages/parser/parser.go index 80ce5d6..939dd10 100644 --- a/ui/messages/parser.go +++ b/ui/messages/parser/parser.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -package messages +package parser import ( "fmt" @@ -24,12 +24,13 @@ import ( "maunium.net/go/gomuks/debug" "maunium.net/go/gomuks/interface" "maunium.net/go/gomuks/matrix/rooms" + "maunium.net/go/gomuks/ui/messages" "maunium.net/go/gomuks/ui/messages/tstring" "maunium.net/go/gomuks/ui/widget" "maunium.net/go/tcell" ) -func ParseEvent(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) UIMessage { +func ParseEvent(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage { member := room.GetMember(evt.Sender) if member != nil { evt.Sender = member.DisplayName @@ -51,7 +52,7 @@ func unixToTime(unix int64) time.Time { return timestamp } -func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) UIMessage { +func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage { msgtype, _ := evt.Content["msgtype"].(string) ts := unixToTime(evt.Timestamp) switch msgtype { @@ -59,10 +60,10 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) UIMessa format, hasFormat := evt.Content["format"].(string) if hasFormat && format == "org.matrix.custom.html" { text := ParseHTMLMessage(room, evt) - return NewExpandedTextMessage(evt.ID, evt.Sender, msgtype, text, ts) + return messages.NewExpandedTextMessage(evt.ID, evt.Sender, msgtype, text, ts) } else { text, _ := evt.Content["body"].(string) - return NewTextMessage(evt.ID, evt.Sender, msgtype, text, ts) + return messages.NewTextMessage(evt.ID, evt.Sender, msgtype, text, ts) } case "m.image": url, _ := evt.Content["url"].(string) @@ -70,7 +71,7 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) UIMessa if err != nil { debug.Printf("Failed to download %s: %v", url, err) } - return NewImageMessage(gmx, evt.ID, evt.Sender, msgtype, hs, id, data, ts) + return messages.NewImageMessage(gmx, evt.ID, evt.Sender, msgtype, hs, id, data, ts) } return nil } @@ -120,8 +121,8 @@ func getMembershipEventContent(evt *gomatrix.Event) (sender string, text tstring return } -func ParseMembershipEvent(evt *gomatrix.Event) UIMessage { +func ParseMembershipEvent(evt *gomatrix.Event) messages.UIMessage { sender, text := getMembershipEventContent(evt) ts := unixToTime(evt.Timestamp) - return NewExpandedTextMessage(evt.ID, sender, "m.room.membership", text, ts) + return messages.NewExpandedTextMessage(evt.ID, sender, "m.room.membership", text, ts) } diff --git a/ui/view-main.go b/ui/view-main.go index ccb3cc1..50304fc 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -31,7 +31,7 @@ import ( "maunium.net/go/gomuks/lib/notification" "maunium.net/go/gomuks/matrix/pushrules" "maunium.net/go/gomuks/matrix/rooms" - "maunium.net/go/gomuks/ui/messages" + "maunium.net/go/gomuks/ui/messages/parser" "maunium.net/go/gomuks/ui/widget" "maunium.net/go/tcell" "maunium.net/go/tview" @@ -465,5 +465,5 @@ func (view *MainView) LoadHistory(room string, initial bool) { } func (view *MainView) ParseEvent(roomView ifc.RoomView, evt *gomatrix.Event) ifc.Message { - return messages.ParseEvent(view.gmx, roomView.MxRoom(), evt) + return parser.ParseEvent(view.gmx, roomView.MxRoom(), evt) } |