Move message parsing to parser subpackage
This commit is contained in:
parent
782ba0657a
commit
f5530ff99c
@ -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"
|
@ -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 {
|
@ -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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user