added following and followers lists, addresses issue #8

This commit is contained in:
Morgan McMillian 2016-11-12 07:57:24 -08:00
parent af24b6ae69
commit c581ff985f
8 changed files with 218 additions and 18 deletions

View file

@ -1,5 +1,5 @@
1 1
43 45
AboutPage.qml AboutPage.qml
AppCover.qml AppCover.qml
icons/at.png icons/at.png
@ -43,3 +43,5 @@ RefreshItem.qml
SettingsPage.qml SettingsPage.qml
StreamTab.qml StreamTab.qml
ThreadPage.qml ThreadPage.qml
UserItem.qml
UserPage.qml

View file

@ -187,15 +187,9 @@ Page {
text: qsTr("Posts") text: qsTr("Posts")
onClicked: { onClicked: {
var page = postPage.createObject() var page = postPage.createObject()
pnut.userStreamReceived.connect(page.loadThread); pnut.userStreamReceived.connect(page.loadThread)
pnut.getUserStream(user.id) pnut.getUserStream(user.id)
//page.follow.connect(pnut.followUser) nav.push(page)
//page.unfollow.connect(pnut.unfollowUser)
//page.block.connect(pnut.blockUser)
//page.unblock.connect(pnut.unblockUser)
//page.mute.connect(pnut.muteUser)
//page.unmute.connect(pnut.unmuteUser)
nav.push(page);
} }
} }
} }
@ -204,6 +198,14 @@ Page {
rightPadding: ui.sdu(.5) rightPadding: ui.sdu(.5)
Button { Button {
text: qsTr("Following") text: qsTr("Following")
onClicked: {
var page = userListPage.createObject()
// page.follow.connect(pnut.followUser)
// page.unfollow.connect(pnut.unfollowUser)
pnut.userListReceived.connect(page.loadThread)
pnut.getFollowing(user.id)
nav.push(page)
}
} }
} }
Container { Container {
@ -211,6 +213,14 @@ Page {
rightPadding: ui.sdu(1) rightPadding: ui.sdu(1)
Button { Button {
text: qsTr("Followers") text: qsTr("Followers")
onClicked: {
var page = userListPage.createObject()
// page.follow.connect(pnut.followUser)
// page.unfollow.connect(pnut.unfollowUser)
pnut.userListReceived.connect(page.loadThread)
pnut.getFollowers(user.id)
nav.push(page)
}
} }
} }
} }
@ -333,6 +343,10 @@ Page {
ComponentDefinition { ComponentDefinition {
id: postPage id: postPage
source: "ThreadPage.qml" source: "ThreadPage.qml"
},
ComponentDefinition {
id: userListPage
source: "UserPage.qml"
} }
] ]
} }

66
assets/UserItem.qml Normal file
View file

@ -0,0 +1,66 @@
import bb.cascades 1.4
import org.labsquare 1.0
Container {
id: useritem
property variant theme : Application.themeSupport.theme.colorTheme.style
property string lorem: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non enim tellus. Donec vestibulum enim urna, eget faucibus diam commodo a. Donec eget hendrerit metus. Pellentesque vehicula nisi nec vehicula ullamcorper. Aliquam a elit eget mi fringilla porta fermentum eget eros. Phasellus vestibulum nulla sed elit congue adipiscing. Cras imperdiet urna ac ipsum volutpat lobortis. Maecenas vehicula tortor at viverra convallis. Curabitur nibh massa, tristique id felis ut, venenatis faucibus dui. Donec fringilla, mi nec tincidunt dignissim, neque nunc semper mi, quis rutrum diam turpis sit amet erat. Cras a sodales nisi. Nunc sit amet diam sed lectus molestie cursus convallis et erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis vitae varius leo. Mauris eu leo a nunc bibendum rutrum euismod et ipsum. "
leftPadding: ui.sdu(3.0)
rightPadding: ui.sdu(3.0)
topPadding: ui.sdu(2.0)
Container {
layout: DockLayout {
}
Container {
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Container {
minWidth: ui.du(12)
background: (theme === VisualStyle.Bright) ? Color.create("#e9e9e9") : Color.create("#282828")
WebImageView {
id: avatar
url: ListItemData.content.avatar_image.link
maxWidth: ui.du(12)
maxHeight: ui.du(12)
//imageSource: "asset:///icons/laughing_man.png"
}
}
Container {
preferredWidth: 1440
leftMargin: ui.sdu(3.0)
Container {
Label {
id: username
text: ListItemData.username
textStyle.fontWeight: FontWeight.Bold
}
}
Container {
Label {
id: description
text: ListItemData.content.html
multiline: true
textFormat: TextFormat.Html
}
}
}
Container {
minWidth: ui.du(24)
verticalAlignment: VerticalAlignment.Center
Button {
text: (ListItemData.you_follow) ? qsTr("Unfollow") : qsTr("Follow")
onClicked: {
if (ListItemData.you_follow) {
useritem.ListItem.view.unfollow(ListItemData.id)
} else {
useritem.ListItem.view.follow(ListItemData.id)
}
}
}
}
}
}
}

79
assets/UserPage.qml Normal file
View file

@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 Morgan McMillian <gilag@monkeystew.com>
*
* This file is apart of the Goober application, a client for pnut.io
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import bb.cascades 1.4
Page {
signal follow(string uid)
signal unfollow(string uid)
signal block(string uid)
signal unblock(string uid)
signal mute(string uid)
signal unmute(string uid)
Container {
ListView {
id: userListView
dataModel: ArrayDataModel {
id: listModel
}
listItemComponents: [
ListItemComponent {
id: root
UserItem {}
}
]
function follow(uid) {
pnut.followUser(uid)
}
function unfollow(uid) {
pnut.unfollowUser(uid)
}
// function sendReply(text, pid) {
// pnut.sendReply(text, pid);
// }
// function getUserName() {
// return _app.setting("username")
// }
// function viewProfile(userobj) {
// var page = profilePage.createObject();
// page.user = userobj
// page.follow.connect(follow)
// page.unfollow.connect(unfollow)
// page.block.connect(block)
// page.unblock.connect(unblock)
// page.mute.connect(mute)
// page.unmute.connect(unmute)
// nav.push(page);
// }
// function ccOnReply() {
// if (_app.setting("cc") === "true") {
// return true
// } else {
// return false
// }
// }
}
}
function loadThread(data) {
listModel.append(data);
}
}

View file

@ -76,6 +76,8 @@ config_pri_assets {
$$quote($$BASEDIR/assets/SettingsPage.qml) \ $$quote($$BASEDIR/assets/SettingsPage.qml) \
$$quote($$BASEDIR/assets/StreamTab.qml) \ $$quote($$BASEDIR/assets/StreamTab.qml) \
$$quote($$BASEDIR/assets/ThreadPage.qml) \ $$quote($$BASEDIR/assets/ThreadPage.qml) \
$$quote($$BASEDIR/assets/UserItem.qml) \
$$quote($$BASEDIR/assets/UserPage.qml) \
$$quote($$BASEDIR/assets/icons/at.png) \ $$quote($$BASEDIR/assets/icons/at.png) \
$$quote($$BASEDIR/assets/icons/bell-slash.png) \ $$quote($$BASEDIR/assets/icons/bell-slash.png) \
$$quote($$BASEDIR/assets/icons/bell.png) \ $$quote($$BASEDIR/assets/icons/bell.png) \

View file

@ -228,6 +228,11 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
emit userStreamReceived(variant.toMap()["data"].toList()); emit userStreamReceived(variant.toMap()["data"].toList());
req_map.remove(id); req_map.remove(id);
} }
else if (endpoint == ":followers" || endpoint == ":following")
{
emit userListReceived(variant.toMap()["data"].toList());
req_map.remove(id);
}
else if (endpoint == ":logout") else if (endpoint == ":logout")
{ {
qDebug() << "Logout successful!"; qDebug() << "Logout successful!";
@ -498,3 +503,19 @@ void Pnut::getUserStream(QString uid)
req_map[++req_id] = ":userstream"; req_map[++req_id] = ":userstream";
getRequest(url, parameters, req_id); getRequest(url, parameters, req_id);
} }
void Pnut::getFollowers(QString uid)
{
QUrl url(PNUT_API_ROOT + "/users/" + uid + "/followers");
KQOAuthParameters parameters;
req_map[++req_id] = ":followers";
getRequest(url, parameters, req_id);
}
void Pnut::getFollowing(QString uid)
{
QUrl url(PNUT_API_ROOT + "/users/" + uid + "/following");
KQOAuthParameters parameters;
req_map[++req_id] = ":following";
getRequest(url, parameters, req_id);
}

View file

@ -86,6 +86,8 @@ public:
Q_INVOKABLE void deletePost(QString pid); Q_INVOKABLE void deletePost(QString pid);
Q_INVOKABLE void getPost(QString pid); Q_INVOKABLE void getPost(QString pid);
Q_INVOKABLE void getUserStream(QString uid); Q_INVOKABLE void getUserStream(QString uid);
Q_INVOKABLE void getFollowers(QString uid);
Q_INVOKABLE void getFollowing(QString uid);
public slots: public slots:
void onRequestReady(QByteArray data); void onRequestReady(QByteArray data);
@ -105,6 +107,7 @@ Q_SIGNALS:
void unmuteSuccess(QVariantMap user); void unmuteSuccess(QVariantMap user);
void postReceived(QVariantMap post); void postReceived(QVariantMap post);
void userStreamReceived(QVariantList stream); void userStreamReceived(QVariantList stream);
void userListReceived(QVariantList users);
private: private:
static const QString PNUT_API_ROOT; static const QString PNUT_API_ROOT;

View file

@ -84,13 +84,13 @@
<name>ProfilePage</name> <name>ProfilePage</name>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="127"/> <location filename="../assets/ProfilePage.qml" line="127"/>
<location filename="../assets/ProfilePage.qml" line="206"/> <location filename="../assets/ProfilePage.qml" line="200"/>
<source>Following</source> <source>Following</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="140"/> <location filename="../assets/ProfilePage.qml" line="140"/>
<location filename="../assets/ProfilePage.qml" line="213"/> <location filename="../assets/ProfilePage.qml" line="215"/>
<source>Followers</source> <source>Followers</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -106,32 +106,32 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="292"/> <location filename="../assets/ProfilePage.qml" line="302"/>
<source>Unfollow</source> <source>Unfollow</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="292"/> <location filename="../assets/ProfilePage.qml" line="302"/>
<source>Follow</source> <source>Follow</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="305"/> <location filename="../assets/ProfilePage.qml" line="315"/>
<source>Unmute</source> <source>Unmute</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="305"/> <location filename="../assets/ProfilePage.qml" line="315"/>
<source>Mute</source> <source>Mute</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="318"/> <location filename="../assets/ProfilePage.qml" line="328"/>
<source>Unblock</source> <source>Unblock</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/ProfilePage.qml" line="318"/> <location filename="../assets/ProfilePage.qml" line="328"/>
<source>Block</source> <source>Block</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -195,6 +195,19 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>UserItem</name>
<message>
<location filename="../assets/UserItem.qml" line="54"/>
<source>Unfollow</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/UserItem.qml" line="54"/>
<source>Follow</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>main</name> <name>main</name>
<message> <message>