Parse mentions in MessageModel

This commit is contained in:
Christian Muehlhaeuser 2020-04-07 03:32:25 +02:00
parent 17f894950d
commit e18cf3f83d
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
2 changed files with 34 additions and 5 deletions

View file

@ -32,6 +32,9 @@ const (
Reply
ReplyToID
ReplyToAuthor
MentionIDs
MentionNames
Mentions
Forward
Mention
Like
@ -84,6 +87,9 @@ func (m *MessageModel) init() {
Reply: core.NewQByteArray2("reply", -1),
ReplyToID: core.NewQByteArray2("replytoid", -1),
ReplyToAuthor: core.NewQByteArray2("replytoauthor", -1),
MentionIDs: core.NewQByteArray2("mentionids", -1),
MentionNames: core.NewQByteArray2("mentionnames", -1),
Mentions: core.NewQByteArray2("mentions", -1),
Forward: core.NewQByteArray2("forward", -1),
Mention: core.NewQByteArray2("mention", -1),
Like: core.NewQByteArray2("like", -1),
@ -221,6 +227,22 @@ func (m *MessageModel) data(index *core.QModelIndex, role int) *core.QVariant {
{
return core.NewQVariant1(p.ReplyToAuthor)
}
case MentionIDs:
{
return core.NewQVariant1(p.MentionIDs)
}
case MentionNames:
{
return core.NewQVariant1(p.MentionNames)
}
case Mentions:
{
var s string
for _, v := range p.MentionNames {
s += "@" + v + " "
}
return core.NewQVariant1(s)
}
case Forward:
{
return core.NewQVariant1(p.Forward)

View file

@ -33,6 +33,8 @@ type Message struct {
Reply bool
ReplyToID string
ReplyToAuthor string
MentionIDs []string
MentionNames []string
Forward bool
Mention bool
Like bool
@ -176,11 +178,16 @@ func messageFromEvent(event accounts.MessageEvent) *Message {
// parse attachments
p.MediaPreview = []string{}
p.MediaURL = []string{}
if len(event.Media) > 0 {
for _, v := range event.Media {
p.MediaPreview = append(p.MediaPreview, v.Preview)
p.MediaURL = append(p.MediaURL, v.URL)
}
for _, v := range event.Media {
p.MediaPreview = append(p.MediaPreview, v.Preview)
p.MediaURL = append(p.MediaURL, v.URL)
}
p.MentionIDs = []string{}
p.MentionNames = []string{}
for _, v := range event.Post.Mentions {
p.MentionIDs = append(p.MentionIDs, v.ID)
p.MentionNames = append(p.MentionNames, v.Name)
}
}