mirror of
https://github.com/muesli/telephant
synced 2024-11-13 23:37:11 +00:00
Provide messageFromEvent for convenience
This commit is contained in:
parent
c3cc78dc67
commit
fd56f6d04a
1 changed files with 26 additions and 20 deletions
46
events.go
46
events.go
|
@ -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@:%_\+.~#?&//=]*)`)
|
||||
|
|
Loading…
Reference in a new issue