Support for content warnings and spoiler texts

This commit is contained in:
Christian Muehlhaeuser 2019-06-02 15:31:21 +02:00
parent 5532064e71
commit 7d57627d3d
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
5 changed files with 43 additions and 2 deletions

View file

@ -7,6 +7,8 @@ import "time"
type Post struct {
MessageID string
Body string
Sensitive bool
Warning string
Author string
AuthorURL string
AuthorName string

View file

@ -460,6 +460,8 @@ func (mod *Account) handleNotification(n *mastodon.Notification, notify bool) {
Post: accounts.Post{
MessageID: string(n.Status.ID),
Body: parseBody(n.Status),
Sensitive: n.Status.Sensitive,
Warning: n.Status.SpoilerText,
Author: n.Account.Acct,
AuthorName: n.Account.DisplayName,
AuthorURL: n.Account.URL,
@ -575,6 +577,8 @@ func (mod *Account) handleStatus(s *mastodon.Status) accounts.MessageEvent {
Post: accounts.Post{
MessageID: string(s.ID),
Body: parseBody(s),
Sensitive: s.Sensitive,
Warning: s.SpoilerText,
Author: s.Account.Acct,
AuthorName: s.Account.DisplayName,
AuthorURL: s.Account.URL,

View file

@ -22,6 +22,8 @@ const (
AuthorID
Avatar
Body
Sensitive
Warning
CreatedAt
Actor
ActorName
@ -68,6 +70,8 @@ func (m *MessageModel) init() {
AuthorID: core.NewQByteArray2("authorid", -1),
Avatar: core.NewQByteArray2("avatar", -1),
Body: core.NewQByteArray2("body", -1),
Sensitive: core.NewQByteArray2("sensitive", -1),
Warning: core.NewQByteArray2("warning", -1),
CreatedAt: core.NewQByteArray2("createdat", -1),
Actor: core.NewQByteArray2("actor", -1),
ActorName: core.NewQByteArray2("actorname", -1),
@ -167,6 +171,14 @@ func (m *MessageModel) data(index *core.QModelIndex, role int) *core.QVariant {
{
return core.NewQVariant14(p.Body)
}
case Sensitive:
{
return core.NewQVariant11(p.Sensitive)
}
case Warning:
{
return core.NewQVariant14(p.Warning)
}
case CreatedAt:
{
return core.NewQVariant14(humanize.Time(p.CreatedAt))

View file

@ -24,6 +24,8 @@ type Message struct {
AuthorID string
Avatar string
Body string
Sensitive bool
Warning string
CreatedAt time.Time
Actor string
ActorName string
@ -139,6 +141,8 @@ func messageFromEvent(event accounts.MessageEvent) *Message {
p.AuthorID = event.Post.AuthorID
p.Avatar = event.Post.Avatar
p.Body = strings.TrimSpace(event.Post.Body)
p.Sensitive = event.Post.Sensitive
p.Warning = event.Post.Warning
p.CreatedAt = event.Post.CreatedAt
p.ReplyToID = event.Post.ReplyToID
p.ReplyToAuthor = event.Post.ReplyToAuthor

View file

@ -9,6 +9,7 @@ import "componentCreator.js" as ComponentCreator
ColumnLayout {
property bool fadeMedia
property bool showActionButtons: true
property bool showSensitiveContent: false
property var message: model
property bool following: message.following
@ -210,7 +211,25 @@ ColumnLayout {
// anchors.bottom: parent.bottom
spacing: 4
Label {
visible: message.body.length > 0
visible: message.sensitive && message.warning.length > 0
text: message.warning
font.pointSize: 11
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
Button {
visible: message.sensitive && !showSensitiveContent
Layout.alignment: Qt.AlignHCenter
highlighted: true
text: qsTr("Show Content")
onClicked: {
showSensitiveContent = !showSensitiveContent
}
}
Label {
visible: message.body.length > 0 && (!message.sensitive || showSensitiveContent)
text: "<style>a:link { visibility: hidden; text-decoration: none; color: " + Material.accent + "; }</style>" + message.body
textFormat: Text.RichText
font.pointSize: 11
@ -247,7 +266,7 @@ ColumnLayout {
Flow {
id: flowgrid
visible: message.mediapreview.length > 0
visible: message.mediapreview.length > 0 && (!message.sensitive || showSensitiveContent)
Layout.fillWidth: true
Layout.topMargin: 4