(Un)follow other users from the AccountPopup

This commit is contained in:
Christian Muehlhaeuser 2019-05-09 01:00:02 +02:00
parent ba045960a0
commit 1acbf8bfe3
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
4 changed files with 45 additions and 2 deletions

View file

@ -164,6 +164,18 @@ func (mod *Account) Unlike(id string) error {
return err
}
// Follow follows another user
func (mod *Account) Follow(id string) error {
_, err := mod.client.AccountFollow(context.Background(), mastodon.ID(id))
return err
}
// Unfollow unfollows another user
func (mod *Account) Unfollow(id string) error {
_, err := mod.client.AccountUnfollow(context.Background(), mastodon.ID(id))
return err
}
// LoadConversation loads a message conversation
func (mod *Account) LoadConversation(id string) ([]accounts.MessageEvent, error) {
var r []accounts.MessageEvent

View file

@ -17,6 +17,7 @@ type UIBridge struct {
_ func(id string) `slot:"unshareButton"`
_ func(id string) `slot:"likeButton"`
_ func(id string) `slot:"unlikeButton"`
_ func(id string, follow bool) `slot:"followButton"`
_ func(id string) `slot:"loadConversation"`
_ func(id string) `slot:"loadAccount"`
@ -91,6 +92,7 @@ func setupQmlBridges() {
uiBridge.ConnectUnshareButton(unshare)
uiBridge.ConnectLikeButton(like)
uiBridge.ConnectUnlikeButton(unlike)
uiBridge.ConnectFollowButton(follow)
uiBridge.ConnectLoadConversation(loadConversation)
uiBridge.ConnectLoadAccount(loadAccount)

View file

@ -92,6 +92,25 @@ func unlike(id string) {
}
}
// follow changes the relationship to another user
func follow(id string, follow bool) {
if follow {
log.Println("Following:", id)
if err := tc.Follow(id); err != nil {
log.Println("Error following user:", err)
return
}
} else {
log.Println("Unfollowing:", id)
if err := tc.Unfollow(id); err != nil {
log.Println("Error unfollowing user:", err)
return
}
}
profileBridge.SetFollowing(follow)
}
// loadConversation loads a message thread
func loadConversation(id string) {
log.Println("Loading conversation:", id)

View file

@ -32,19 +32,29 @@ ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft
text: profile.name
font.pixelSize: 16
font.bold: true
elide: Label.ElideRight
}
Label {
text: profile.username
text: profile.username + (profile.followedBy ? " (follows you)" : "")
font.pixelSize: 16
opacity: 0.7
elide: Label.ElideRight
}
}
Button {
id: followButton
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
visible: profile.profileID != accountBridge.profileID
highlighted: true
text: profile.following ? qsTr("Unfollow") : qsTr("Follow")
onClicked: {
uiBridge.followButton(profile.profileID, !profile.following)
}
}
}
RowLayout {
anchors.horizontalCenter: parent.horizontalCenter