Provide messageFromEvent for convenience

This commit is contained in:
Christian Muehlhaeuser 2019-05-05 18:18:35 +02:00
parent c3cc78dc67
commit fd56f6d04a
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E

View file

@ -12,6 +12,31 @@ func linkify(in []byte) []byte {
return []byte(fmt.Sprintf("<a style=\"text-decoration: none; color: orange;\" href=\"%s\">%s</a>", in, in))
}
func messageFromEvent(event accounts.MessageEvent) *Message {
var p = NewMessage(nil)
p.MessageID = event.Post.MessageID
p.PostURL = event.Post.URL
p.Name = event.Post.AuthorName
p.Author = event.Post.Author
p.AuthorURL = event.Post.AuthorURL
p.Avatar = event.Post.Avatar
p.Body = strings.TrimSpace(event.Post.Body)
p.CreatedAt = event.Post.CreatedAt
p.Reply = event.Reply
p.ReplyToID = event.Post.ReplyToID
p.ReplyToAuthor = event.Post.ReplyToAuthor
p.Mention = event.Mention
p.Like = event.Like
p.Forward = event.Forward
p.Actor = event.Post.Actor
p.ActorName = event.Post.ActorName
if len(event.Media) > 0 {
p.Media = event.Media[0]
}
return p
}
// handleEvents handles incoming events and puts them into the right models
func handleEvents(eventsIn chan interface{}, messages *MessageModel, notifications *MessageModel) {
for {
@ -39,26 +64,7 @@ func handleEvents(eventsIn chan interface{}, messages *MessageModel, notificatio
// spw := &spew.ConfigState{Indent: " ", DisableCapacities: true, DisablePointerAddresses: true}
// log.Println("Message received:", spw.Sdump(event))
var p = NewMessage(nil)
p.MessageID = event.Post.MessageID
p.PostURL = event.Post.URL
p.Name = event.Post.AuthorName
p.Author = event.Post.Author
p.AuthorURL = event.Post.AuthorURL
p.Avatar = event.Post.Avatar
p.Body = strings.TrimSpace(event.Post.Body)
p.CreatedAt = event.Post.CreatedAt
p.Reply = event.Reply
p.ReplyToID = event.Post.ReplyToID
p.ReplyToAuthor = event.Post.ReplyToAuthor
p.Mention = event.Mention
p.Like = event.Like
p.Forward = event.Forward
p.Actor = event.Post.Actor
p.ActorName = event.Post.ActorName
if len(event.Media) > 0 {
p.Media = event.Media[0]
}
p := messageFromEvent(event)
// markup links
/* re, err := regexp.Compile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,16}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)`)