399 lines
14 KiB
QML
399 lines
14 KiB
QML
/*
|
|
* 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
|
|
import com.monkeystew.pnut 1.0
|
|
import com.monkeystew.qtimer 1.0
|
|
import com.netimage 1.0
|
|
|
|
NavigationPane {
|
|
id: nav
|
|
|
|
property alias title: titleBar.title
|
|
property string stream_type
|
|
property string endpoint
|
|
property int unread: -1
|
|
property bool refreshpull: false
|
|
property bool active
|
|
property bool at_end: false
|
|
|
|
signal openLogin()
|
|
signal closeLogin()
|
|
|
|
Page {
|
|
titleBar: TitleBar {
|
|
id: titleBar
|
|
}
|
|
Container {
|
|
ListView {
|
|
id: streamView
|
|
property variant listImageManager: feedImageManager
|
|
property bool fetching: false
|
|
dataModel: ArrayDataModel {
|
|
id: postModel
|
|
}
|
|
leadingVisual: RefreshItem {
|
|
onRefresh: {
|
|
refreshpull = true
|
|
pnut.getStream(endpoint, Pnut.STREAM_NEWER);
|
|
}
|
|
}
|
|
listItemComponents: [
|
|
ListItemComponent {
|
|
id: root
|
|
PostItem {}
|
|
}
|
|
]
|
|
onTriggered: {
|
|
if (!postModel.data(indexPath).is_deleted) {
|
|
var page = threadPage.createObject();
|
|
pnut.threadReceived.connect(page.loadThread);
|
|
pnut.getThread(postModel.data(indexPath).thread_id);
|
|
page.follow.connect(pnut.followUser)
|
|
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);
|
|
}
|
|
}
|
|
function viewProfile(userobj) {
|
|
var page = profilePage.createObject();
|
|
page.user = userobj
|
|
//pnut.userStreamReceived.connect(page.loadThread)
|
|
//pnut.getUserStream(userobj.id)
|
|
page.follow.connect(pnut.followUser)
|
|
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)
|
|
//page.getPosts.connect(pnut.getUserStream)
|
|
nav.push(page);
|
|
}
|
|
function sendReply(text, pid) {
|
|
pnut.sendReply(text, pid);
|
|
}
|
|
function getUserName() {
|
|
return _app.setting("username");
|
|
}
|
|
function addBookmark(pid) {
|
|
pnut.setBookmark(pid);
|
|
}
|
|
function delBookmark(pid) {
|
|
pnut.deleteBookmark(pid);
|
|
}
|
|
function repost(pid) {
|
|
pnut.repost(pid);
|
|
}
|
|
function delRepost(pid) {
|
|
pnut.deleteRepost(pid);
|
|
}
|
|
function delPost(pid) {
|
|
pnut.deletePost(pid);
|
|
}
|
|
function getPost(pid) {
|
|
pnut.getPost(pid)
|
|
}
|
|
function ccOnReply() {
|
|
if (_app.setting("cc") === "true") {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
function hidePhoto() {
|
|
if (_app.setting("hidephoto") === "true") {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
function hideAvatar() {
|
|
if (_app.setting("hideavatar") === "true") {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
function copyText(text) {
|
|
_app.copyText(text)
|
|
}
|
|
function showImage(filename) {
|
|
_app.showImage(filename)
|
|
}
|
|
attachedObjects: [
|
|
ListScrollStateHandler {
|
|
onAtEndChanged: {
|
|
streamView.fetching = false
|
|
if (atEnd) {
|
|
if (!streamView.fetching && pnut.beforeId != 0) {
|
|
streamView.fetching = true
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
}
|
|
}
|
|
}
|
|
onAtBeginningChanged: {
|
|
if (atBeginning) {
|
|
unread = 0
|
|
nav.parent.unreadContentCount = unread
|
|
}
|
|
}
|
|
},
|
|
NetImageManager {
|
|
id: feedImageManager
|
|
cacheId: "feedImageManager"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
actions: [
|
|
ActionItem {
|
|
title: qsTr("New Post")
|
|
ActionBar.placement: ActionBarPlacement.Signature
|
|
onTriggered: {
|
|
newPostSheet.open();
|
|
newPostSheet.input.requestFocus();
|
|
}
|
|
imageSource: "asset:///icons/ic_compose.png"
|
|
shortcuts: [
|
|
SystemShortcut {
|
|
type: SystemShortcuts.CreateNew
|
|
}
|
|
]
|
|
},
|
|
ActionItem {
|
|
title: qsTr("To Top")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
//refreshpull = true
|
|
//pnut.getStream(endpoint, Pnut.STREAM_NEWER);
|
|
streamView.scrollToPosition(ScrollPosition.Beginning, ScrollAnimation.None);
|
|
}
|
|
imageSource: "asset:///icons/ic_to_top.png"
|
|
shortcuts: [
|
|
SystemShortcut {
|
|
type: SystemShortcuts.JumpToTop
|
|
}
|
|
]
|
|
},
|
|
ActionItem {
|
|
title: qsTr("Reload")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
reload()
|
|
}
|
|
imageSource: "asset:///icons/ic_reload.png"
|
|
shortcuts: [
|
|
Shortcut {
|
|
key: "l"
|
|
}
|
|
]
|
|
},
|
|
ActionItem {
|
|
title: qsTr("To Bottom")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
streamView.scrollToPosition(ScrollPosition.End, ScrollAnimation.None);
|
|
//pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
}
|
|
imageSource: "asset:///icons/ic_to_bottom.png"
|
|
shortcuts: [
|
|
SystemShortcut {
|
|
type: SystemShortcuts.JumpToBottom
|
|
}
|
|
]
|
|
}
|
|
]
|
|
actionBarAutoHideBehavior: ActionBarAutoHideBehavior.HideOnScroll
|
|
actionBarVisibility: ChromeVisibility.Overlay
|
|
}
|
|
attachedObjects: [
|
|
ComponentDefinition {
|
|
id: threadPage
|
|
source: "ThreadPage.qml"
|
|
},
|
|
ComponentDefinition {
|
|
id: profilePage
|
|
source: "ProfilePage.qml"
|
|
},
|
|
NewPostSheet {
|
|
id: newPostSheet
|
|
onSendPost: {
|
|
console.log("send: " + text)
|
|
pnut.sendPost(text)
|
|
}
|
|
},
|
|
WebViewSheet {
|
|
id: webViewSheet
|
|
},
|
|
QTimer {
|
|
id: timer
|
|
interval: 30000
|
|
onTimeout: {
|
|
pnut.getStream(endpoint, Pnut.STREAM_NEWER);
|
|
}
|
|
},
|
|
Pnut {
|
|
id: pnut
|
|
|
|
onStreamReceived: {
|
|
|
|
// stream.forEach(function(post) {
|
|
// if (post.is_deleted) {
|
|
// console.log("got a deleted post")
|
|
// }
|
|
// })
|
|
|
|
switch (rtype) {
|
|
case Pnut.STREAM_OLDER:
|
|
//streamView.scrollToPosition(ScrollPosition.End, ScrollAnimation.None);
|
|
if (stream.length < 50) {
|
|
at_end = true
|
|
}
|
|
postModel.append(stream);
|
|
break;
|
|
case Pnut.STREAM_NEWER:
|
|
postModel.insert(0, stream);
|
|
if (stream.length > 0) {
|
|
update_app_cover(stream.length)
|
|
}
|
|
if (refreshpull) {
|
|
refreshpull = false
|
|
streamView.scrollToPosition(ScrollPosition.Beginning, ScrollAnimation.None);
|
|
}
|
|
break;
|
|
}
|
|
pnut.beforeId = postModel.value(postModel.size() - 1).id;
|
|
pnut.sinceId = postModel.value(0).id;
|
|
}
|
|
|
|
onPostReceived: {
|
|
var idx
|
|
for (var i = 0; i< postModel.size(); i++) {
|
|
if (postModel.value(i).id === post.id) {
|
|
idx = i
|
|
break
|
|
}
|
|
}
|
|
postModel.replace(idx, post)
|
|
}
|
|
|
|
onAuthorizationRequired: {
|
|
console.log("__Got a auth required thingy")
|
|
openLogin()
|
|
timer.stop();
|
|
}
|
|
|
|
onAuthorizationReceived: {
|
|
console.log("-- THIS --")
|
|
webViewSheet.close()
|
|
closeLogin()
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
timer.start();
|
|
console.log("__Should be closed now")
|
|
}
|
|
|
|
onOpenBrowser: {
|
|
//console.log("-- open browser --")
|
|
webViewSheet.url = url
|
|
webViewSheet.open()
|
|
}
|
|
|
|
onFollowSuccess: update_user_page(user)
|
|
|
|
onUnfollowSuccess: update_user_page(user)
|
|
|
|
onBlockSuccess: update_user_page(user)
|
|
|
|
onUnblockSuccess: update_user_page(user)
|
|
|
|
onMuteSuccess: update_user_page(user)
|
|
|
|
onUnmuteSuccess: update_user_page(user)
|
|
|
|
function update_user_page(user) {
|
|
nav.top.user = user
|
|
reload()
|
|
}
|
|
|
|
function update_app_cover(count) {
|
|
if (count > 0 && unread >=0) {
|
|
unread += count
|
|
} else {
|
|
unread = 0
|
|
}
|
|
nav.parent.unreadContentCount = unread
|
|
}
|
|
}
|
|
]
|
|
onPopTransitionEnded: {
|
|
page.destroy();
|
|
}
|
|
onCreationCompleted: {
|
|
setEndpoint()
|
|
if (_app.setting("access_token") && _app.setting("access_token").length > 0) {
|
|
console.log("__I think I'm authenticated")
|
|
pnut.getUserInfo()
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER)
|
|
timer.start();
|
|
} else {
|
|
console.log("__I am not authenticated yet")
|
|
openLogin()
|
|
timer.stop()
|
|
}
|
|
}
|
|
function setEndpoint() {
|
|
switch (stream_type) {
|
|
case "Home":
|
|
var hometype = (_app.setting("unified") === "true") ? "unified" : "me"
|
|
endpoint = "/posts/streams/" + hometype
|
|
break;
|
|
case "Mentions":
|
|
endpoint = "/users/me/mentions"
|
|
break;
|
|
case "Bookmarks":
|
|
endpoint = "/users/me/bookmarks"
|
|
break;
|
|
case "Global":
|
|
default:
|
|
endpoint = "/posts/streams/global"
|
|
break;
|
|
}
|
|
}
|
|
function login() {
|
|
pnut.authorize()
|
|
}
|
|
function logout() {
|
|
pnut.logout()
|
|
}
|
|
function reload() {
|
|
setEndpoint()
|
|
postModel.clear()
|
|
pnut.beforeId = 0
|
|
pnut.sinceId = 0
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
}
|
|
function createPost(text) {
|
|
newPostSheet.open()
|
|
newPostSheet.text = text
|
|
newPostSheet.input.requestFocus();
|
|
}
|
|
}
|