Add toot visibility setting, fixes #63

This commit is contained in:
Elen Eisendle 2020-04-18 15:16:16 +02:00 committed by Christian Muehlhaeuser
parent c60b4b3ead
commit a05749a0c6
13 changed files with 121 additions and 23 deletions

View file

@ -70,7 +70,7 @@ func postLimitCount(body string) int {
// reply is used to post a new message
// if replyid is > 0, it's send as a reply
func reply(replyid string, message string) {
func reply(replyid string, message string, visibility string) {
var attachments []string
for _, v := range attachmentModel.Attachments() {
attachments = append(attachments, v.ID)
@ -78,11 +78,11 @@ func reply(replyid string, message string) {
var err error
if replyid != "" {
log.Println("Sending reply to:", replyid, attachments, message)
err = tc.Reply(replyid, message, attachments)
log.Println("Sending reply to:", replyid, attachments, message, visibility)
err = tc.Reply(replyid, message, visibility, attachments)
} else {
log.Println("Posting:", attachments, message)
err = tc.Post(message, attachments)
log.Println("Posting:", attachments, message, visibility)
err = tc.Post(message, visibility, attachments)
}
if err != nil {
accountBridge.SetError(err.Error())

View file

@ -28,6 +28,7 @@ type Post struct {
RepliesCount int64
LikesCount int64
SharesCount int64
Visibility string
}
// User describes a user object

View file

@ -198,9 +198,10 @@ func (mod *Account) Logo() string {
}
// Post posts a new status
func (mod *Account) Post(message string, attachments []string) error {
func (mod *Account) Post(message string, visibility string, attachments []string) error {
t := &mastodon.Toot{
Status: message,
Status: message,
Visibility: visibility,
}
for _, v := range attachments {
t.MediaIDs = append(t.MediaIDs, mastodon.ID(v))
@ -211,9 +212,10 @@ func (mod *Account) Post(message string, attachments []string) error {
}
// Reply posts a new reply-status
func (mod *Account) Reply(replyid string, message string, attachments []string) error {
func (mod *Account) Reply(replyid string, message string, visibility string, attachments []string) error {
t := &mastodon.Toot{
Status: message,
Visibility: visibility,
InReplyToID: mastodon.ID(replyid),
}
for _, v := range attachments {
@ -573,6 +575,7 @@ func (mod *Account) handleNotification(n *mastodon.Notification, notify bool) {
RepliesCount: n.Status.RepliesCount,
LikesCount: n.Status.FavouritesCount,
SharesCount: n.Status.ReblogsCount,
Visibility: n.Status.Visibility,
},
}
ev.Post.Liked, _ = n.Status.Favourited.(bool)
@ -697,6 +700,7 @@ func (mod *Account) handleStatus(s *mastodon.Status) accounts.MessageEvent {
RepliesCount: s.RepliesCount,
LikesCount: s.FavouritesCount,
SharesCount: s.ReblogsCount,
Visibility: s.Visibility,
},
}
ev.Post.Liked, _ = s.Favourited.(bool)

View file

@ -14,18 +14,18 @@ type UIBridge struct {
_ func(body string) int `slot:"postLimitCount"`
_ func(replyid string, message string) `slot:"postButton"`
_ func(id string) `slot:"deleteButton"`
_ func(id string) `slot:"shareButton"`
_ func(id string) `slot:"unshareButton"`
_ func(id string) `slot:"likeButton"`
_ func(id string) `slot:"unlikeButton"`
_ func(id string, follow bool) `slot:"followButton"`
_ func(url string) `slot:"uploadAttachment"`
_ func(id string) `slot:"loadConversation"`
_ func(id string) `slot:"loadAccount"`
_ func(token string) `slot:"search"`
_ func(token string) `slot:"tag"`
_ func(replyid string, message string, visibility string) `slot:"postButton"`
_ func(id string) `slot:"deleteButton"`
_ func(id string) `slot:"shareButton"`
_ func(id string) `slot:"unshareButton"`
_ func(id string) `slot:"likeButton"`
_ func(id string) `slot:"unlikeButton"`
_ func(id string, follow bool) `slot:"followButton"`
_ func(url string) `slot:"uploadAttachment"`
_ func(id string) `slot:"loadConversation"`
_ func(id string) `slot:"loadAccount"`
_ func(token string) `slot:"search"`
_ func(token string) `slot:"tag"`
_ func(idx int64) `slot:"closePane"`

View file

@ -49,6 +49,7 @@ const (
SharesCount
LikesCount
Editing
Visibility
)
// MessageModel holds a collection of messages
@ -103,6 +104,7 @@ func (m *MessageModel) init() {
RepliesCount: core.NewQByteArray2("repliescount", -1),
SharesCount: core.NewQByteArray2("sharescount", -1),
LikesCount: core.NewQByteArray2("likescount", -1),
Visibility: core.NewQByteArray2("visibility", -1),
})
m.ConnectData(m.data)
@ -295,6 +297,10 @@ func (m *MessageModel) data(index *core.QModelIndex, role int) *core.QVariant {
{
return core.NewQVariant1(p.LikesCount)
}
case Visibility:
{
return core.NewQVariant1(p.Visibility)
}
default:
{

View file

@ -49,6 +49,7 @@ type Message struct {
RepliesCount int64
SharesCount int64
LikesCount int64
Visibility string
}
var (
@ -174,6 +175,7 @@ func messageFromEvent(event accounts.MessageEvent) *Message {
p.RepliesCount = event.Post.RepliesCount
p.SharesCount = event.Post.SharesCount
p.LikesCount = event.Post.LikesCount
p.Visibility = event.Post.Visibility
// parse attachments
p.MediaPreview = []string{}

View file

@ -8,6 +8,7 @@ Popup {
id: popup
property var message
property var visibility
modal: true
focus: true
@ -16,6 +17,14 @@ Popup {
anchors.centerIn: mainWindow.overlay
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Component.onCompleted: {
if (message != null) {
visibility = message.visibility
} else {
visibility = "public"
}
}
FileDialog {
id: imageFileDialog
title: "Please choose an image"
@ -156,7 +165,62 @@ Popup {
}
RowLayout {
Layout.alignment: Qt.AlignRight
RoundButton {
id: scopePrivateButton
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
highlighted: visibility === "direct"
icon.name: "scope-private"
icon.source: "images/scope-private.svg"
onClicked: {
visibility = "direct"
}
}
RoundButton {
id: scopeFollowersButton
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
highlighted: visibility === "private"
icon.name: "scope-followers"
icon.source: "images/scope-followers.svg"
onClicked: {
visibility = "private"
}
}
RoundButton {
id: scopeUnlistedButton
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
highlighted: visibility === "unlisted"
icon.name: "scope-unlisted"
icon.source: "images/scope-unlisted.svg"
onClicked: {
visibility = "unlisted"
}
}
RoundButton {
id: scopePublicButton
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
highlighted: visibility === "public"
icon.name: "scope-public"
icon.source: "images/scope-public.svg"
onClicked: {
visibility = "public"
}
}
Item {
// fills all the empty space so the following items align right
Layout.fillWidth: true
}
Label {
id: remCharsLabel
@ -184,10 +248,10 @@ Popup {
msg = "@" + message.author + " " + msg
}
uiBridge.postButton(msgid, msg)
uiBridge.postButton(msgid, msg, visibility)
messageArea.clear()
}
}
}
}
}
}

View file

@ -309,6 +309,22 @@ ColumnLayout {
// spacer item
Layout.fillWidth: true
}
ImageButton {
source: {
switch (message.visibility) {
case "direct":
return "images/scope-private.svg"
case "private":
return "images/scope-followers.svg"
case "unlisted":
return "images/scope-unlisted.svg"
default:
return "images/scope-public.svg"
}
}
animationDuration: 200
sourceSize.height: 16
}
ImageButton {
source: "images/reply.png"
animationDuration: 200

View file

@ -0,0 +1 @@
The scope-* icons are part of the Material Icons from https://material.io/ and licensed under Apache 2.0.

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="48px" height="48px"><path d="M0 0h24v24H0z" fill="none"/><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/></svg>

After

Width:  |  Height:  |  Size: 380 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="48px" height="48px"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/><path d="M0 0h24v24H0z" fill="none"/></svg>

After

Width:  |  Height:  |  Size: 264 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>

After

Width:  |  Height:  |  Size: 438 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="48px" height="48px"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 17c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm6-9h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6h1.9c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm0 12H6V10h12v10z"/></svg>

After

Width:  |  Height:  |  Size: 386 B