forked from lubuwest/Friendiqa
v.0.5
This commit is contained in:
parent
63dfb9b197
commit
d48847d183
135 changed files with 8879 additions and 3693 deletions
|
@ -51,6 +51,7 @@ signals:
|
|||
|
||||
public slots:
|
||||
void setAlarm(int time);
|
||||
void notify(QString title, QString text, int id);
|
||||
|
||||
private:
|
||||
int m_time;
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//#include <QtAndroidExtras/QAndroidJniObject>
|
||||
//#include <QtAndroidExtras/QAndroidJniEnvironment>
|
||||
#include "alarm.h"
|
||||
#include <QtCore/QDebug>
|
||||
#include "AndroidNative/systemdispatcher.h"
|
||||
|
@ -45,38 +43,20 @@ ALARM::ALARM(QObject *parent) : QObject(parent){}
|
|||
|
||||
void ALARM::setAlarm(int interval)
|
||||
{
|
||||
qDebug() << interval;
|
||||
QVariantMap message;
|
||||
message["value"] = interval;
|
||||
AndroidNative::SystemDispatcher::instance()->loadClass("androidnative.Util");
|
||||
AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.setSchedule", message);
|
||||
//AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.stopService", message);
|
||||
// auto activity = QtAndroid::androidActivity();
|
||||
// auto packageManager = activity.callObjectMethod("getPackageManager",
|
||||
// "()Landroid/content/pm/PackageManager;");
|
||||
|
||||
// auto activityIntent = packageManager.callObjectMethod("getLaunchIntentForPackage",
|
||||
// "(Ljava/lang/String;)Landroid/content/Intent;",
|
||||
// activity.callObjectMethod("getPackageName",
|
||||
// "()Ljava/lang/String;").object());
|
||||
|
||||
// auto pendingIntent = QAndroidJniObject::callStaticObjectMethod("android/app/PendingIntent", "getActivity",
|
||||
// "(Landroid/content/Context;ILandroid/content/Intent;I)Landroid/app/PendingIntent;",
|
||||
// activity.object(), jint(0), activityIntent.object(),
|
||||
// QAndroidJniObject::getStaticField<jint>("android/content/Intent",
|
||||
// "FLAG_ACTIVITY_CLEAR_TOP"));
|
||||
|
||||
// auto alarmManager = activity.callObjectMethod("getSystemService",
|
||||
// "(Ljava/lang/String;)Ljava/lang/Object;",
|
||||
// QAndroidJniObject::getStaticObjectField("android/content/Context",
|
||||
// "ALARM_SERVICE",
|
||||
// "Ljava/lang/String;").object());
|
||||
|
||||
// alarmManager.callMethod<void>("set",
|
||||
// "(IJLandroid/app/PendingIntent;)V",
|
||||
// QAndroidJniObject::getStaticField<jint>("android/app/AlarmManager", "RTC"),
|
||||
// jlong(QDateTime::currentMSecsSinceEpoch() + 100), pendingIntent.object());
|
||||
|
||||
|
||||
AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.stopService", message);
|
||||
}
|
||||
|
||||
void ALARM::notify(QString title, QString text, int id)
|
||||
{
|
||||
//qDebug() << "notify "<< title << text;
|
||||
QVariantMap message;
|
||||
message["title"] = title;
|
||||
message["message"] = text;
|
||||
message["id"] = id;
|
||||
AndroidNative::SystemDispatcher::instance()->loadClass("androidnative.Util");
|
||||
AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.setNotification", message);
|
||||
}
|
||||
|
|
73
source-android/common/alarmlinux.cpp
Normal file
73
source-android/common/alarmlinux.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
// This file is part of Friendiqa
|
||||
// https://git.friendi.ca/lubuwest/Friendiqa
|
||||
// Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations including
|
||||
// the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for all
|
||||
// of the code used other than OpenSSL. If you modify file(s) with this
|
||||
// exception, you may extend this exception to your version of the
|
||||
// file(s), but you are not obligated to do so. If you do not wish to do
|
||||
// so, delete this exception statement from your version. If you delete
|
||||
// this exception statement from all source files in the program, then
|
||||
// also delete it here.
|
||||
//
|
||||
// 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/>.
|
||||
|
||||
//#include <QtAndroidExtras/QAndroidJniObject>
|
||||
//#include <QtAndroidExtras/QAndroidJniEnvironment>
|
||||
#include "alarm.h"
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtDBus/QtDBus>
|
||||
//#include "AndroidNative/systemdispatcher.h"
|
||||
|
||||
ALARM *ALARM::instance()
|
||||
{
|
||||
static ALARM alarm;
|
||||
return &alarm;
|
||||
}
|
||||
|
||||
ALARM::ALARM(QObject *parent) : QObject(parent){}
|
||||
|
||||
void ALARM::setAlarm(int interval)
|
||||
{
|
||||
qDebug() << interval;
|
||||
QVariantMap message;
|
||||
message["value"] = interval;
|
||||
// AndroidNative::SystemDispatcher::instance()->loadClass("androidnative.Util");
|
||||
// AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.setSchedule", message);
|
||||
//AndroidNative::SystemDispatcher::instance()->dispatch("androidnative.Util.stopService", message);
|
||||
}
|
||||
|
||||
void ALARM::notify(QString title, QString text, int id)
|
||||
{
|
||||
qDebug() << title << text;
|
||||
QVariantMap message;
|
||||
message["title"] = title;
|
||||
message["message"] = text;
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusInterface dbus_iface("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", bus);
|
||||
QString appname="Friendiqa";
|
||||
uint v=12321;
|
||||
if (dbus_iface.isValid()){
|
||||
|
||||
dbus_iface.call("Notify",appname,v,"",title,text,"","",5000);
|
||||
}
|
||||
// AndroidNative::SystemDispatcher::instance()->dispatch("Notifier.notify", message);
|
||||
}
|
|
@ -32,17 +32,15 @@
|
|||
#include <QApplication>
|
||||
#include <QtQml/QQmlEngine>
|
||||
#include <QAndroidService>
|
||||
#include <QtAndroid>
|
||||
#include <QtQuick>
|
||||
#include "xhr.h"
|
||||
#include "updatenews.h"
|
||||
#include "filesystem.h"
|
||||
#include "remoteauthasyncimageprovider.h"
|
||||
#include "alarm.h"
|
||||
#include "AndroidNative/systemdispatcher.h"
|
||||
#include "AndroidNative/environment.h"
|
||||
//#include "AndroidNative/environment.h"
|
||||
//#include "AndroidNative/debug.h"
|
||||
#include "AndroidNative/mediascannerconnection.h"
|
||||
//#include "AndroidNative/mediascannerconnection.h"
|
||||
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
@ -66,13 +64,11 @@ int main(int argc, char *argv[]) {
|
|||
UPDATENEWS* updatenews= UPDATENEWS::instance();
|
||||
updatenews->setDatabase();
|
||||
updatenews->login();
|
||||
updatenews->timeline();
|
||||
updatenews->startsync();
|
||||
app.connect (updatenews,SIGNAL(quitapp()),&app,SLOT(quit()));
|
||||
//QtAndroid::androidService().callMethod<void>("stopSelf");
|
||||
return app.exec();
|
||||
}
|
||||
else{
|
||||
|
||||
QApplication app(argc, argv);
|
||||
QQuickView view;
|
||||
QTranslator qtTranslator;
|
||||
|
@ -87,8 +83,8 @@ int main(int argc, char *argv[]) {
|
|||
view.rootContext()->setContextProperty("filesystem", filesystem);
|
||||
ALARM* alarm = ALARM::instance();
|
||||
view.rootContext()->setContextProperty("alarm", alarm);
|
||||
// UPDATENEWS* updatenews = UPDATENEWS::instance();
|
||||
// view.rootContext()->setContextProperty("updatenews", updatenews);
|
||||
UPDATENEWS* updatenews = UPDATENEWS::instance();
|
||||
view.rootContext()->setContextProperty("updatenews", updatenews);
|
||||
view.setSource(QUrl("qrc:/qml/friendiqa.qml"));
|
||||
view.show();
|
||||
view.connect(view.rootContext()->engine(), SIGNAL(quit()), &app, SLOT(quit()));
|
||||
|
|
|
@ -100,130 +100,304 @@ void UPDATENEWS::login()
|
|||
m_imagedir=query.value(3).toString();
|
||||
xhr.setImagedir(m_imagedir);
|
||||
QString isActive=query.value(7).toString();
|
||||
m_updateInterval=query.value(5).toInt();
|
||||
m_api="/api/statuses/friends_timeline";
|
||||
xhr.setApi(m_api);
|
||||
}
|
||||
//m_updateInterval=query.value(5).toInt();
|
||||
|
||||
|
||||
QSqlQuery syncquery("SELECT * FROM globaloptions",m_db);
|
||||
// QSqlQuery delquery("DELETE FROM globaloptions WHERE k='sync_interval'",m_db);
|
||||
// delquery.exec();
|
||||
m_updateInterval=0;
|
||||
syncindex=0;
|
||||
synclist.clear();
|
||||
//QSqlQuery syncquery("SELECT * FROM globaloptions WHERE k like 'sync_%' AND v=1",m_db);
|
||||
while (syncquery.next()){
|
||||
if (syncquery.value(0).toString()=="syncinterval"){
|
||||
m_updateInterval=syncquery.value(1).toInt();
|
||||
}
|
||||
if (syncquery.value(0).toString().left(5)=="sync_" && syncquery.value(1).toInt()==1){
|
||||
synclist.append(syncquery.value(0).toString());
|
||||
//qDebug() << " sync " << syncquery.value(0).toString() << " " <<syncquery.value(1).toString();
|
||||
}
|
||||
if (syncquery.value(0).toString().left(7)=="notify_" && syncquery.value(1).toInt()==1){
|
||||
notifylist.append(syncquery.value(0).toString());
|
||||
//qDebug() << " notify " << syncquery.value(0).toString() << " " <<syncquery.value(1).toString();
|
||||
}
|
||||
}
|
||||
// QSqlQuery notifyquery("SELECT * FROM globaloptions WHERE k like 'notify_%' AND v=1",m_db);
|
||||
//qDebug() << "size " << notifyquery.size();
|
||||
// while (notifyquery.next()){
|
||||
// notifylist.append(syncquery.value(0).toString());
|
||||
// qDebug() << " notify " << syncquery.value(0).toString();
|
||||
//}
|
||||
}
|
||||
|
||||
void UPDATENEWS::startsync()
|
||||
{ //qDebug()<<"Friendiqa start syncing " <<synclist.length()<<" index "<<syncindex;
|
||||
QObject::connect(&xhr,SIGNAL(success(QByteArray,QString)),this,SLOT(store(QByteArray,QString)));
|
||||
QObject::connect(&xhr,SIGNAL(error(QString,QString,QString,int)),this,SLOT(showError(QString,QString,QString,int)));
|
||||
if (syncindex<synclist.length()){
|
||||
if (synclist[syncindex]=="sync_Timeline"){
|
||||
timeline();
|
||||
} else if (synclist[syncindex]=="sync_Replies") {
|
||||
replies();
|
||||
} else if (synclist[syncindex]=="sync_DirectMessages") {
|
||||
directmessages();
|
||||
} else if (synclist[syncindex]=="sync_Notifications") {
|
||||
notifications();
|
||||
}
|
||||
} else if (syncindex==synclist.length()) {
|
||||
m_api="";
|
||||
if(m_updateInterval!=0){
|
||||
syncindex=0;
|
||||
synclist.clear();
|
||||
m_db.close();
|
||||
m_db.removeDatabase(m_db.connectionName());
|
||||
emit quitapp();
|
||||
alarm.setAlarm(m_updateInterval);
|
||||
m_updateInterval=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UPDATENEWS::timeline()
|
||||
{
|
||||
qDebug()<<"Friendiqa start timeline";
|
||||
QSqlQuery query("SELECT status_id FROM news WHERE username='"+ username +"' ORDER BY status_id DESC LIMIT 1",m_db);
|
||||
if (query.isActive() && query.isSelect()){query.first();};
|
||||
QString lastid=query.value(0).toString();
|
||||
m_api="/api/statuses/friends_timeline";
|
||||
xhr.clearParams();
|
||||
xhr.setParam("since_id",lastid);
|
||||
xhr.setUrl(m_url);
|
||||
xhr.setApi(m_api);
|
||||
QSqlQuery query("SELECT status_id FROM news WHERE messagetype=0 AND username='"+ username +"' ORDER BY status_id DESC LIMIT 1",m_db);
|
||||
if (query.isActive() && query.isSelect()){
|
||||
if (query.first()){
|
||||
QString lastid=query.value(0).toString();
|
||||
xhr.setParam("since_id",lastid);
|
||||
}
|
||||
}
|
||||
xhr.setParam("count","50");
|
||||
xhr.get();
|
||||
QObject::connect(&xhr,SIGNAL(success(QByteArray,QString)),this,SLOT(store(QByteArray,QString)));
|
||||
QObject::connect(&xhr,SIGNAL(error(QString,QString,QString,int)),this,SLOT(showError(QString,QString,QString,int)));
|
||||
QObject::connect(&xhr, SIGNAL(downloaded(QString, QString, QString, int)), this, SLOT(updateImageLocation(QString,QString, QString, int)));
|
||||
}
|
||||
|
||||
|
||||
//void UPDATENEWS::startservice(QString type,QVariantMap map)
|
||||
//{
|
||||
// qDebug ()<<"Friediqa start service "<<type;
|
||||
// if (type=="androidnativeServiceStarted"){
|
||||
// setDatabase();
|
||||
// login();
|
||||
// timeline();
|
||||
// }
|
||||
//}
|
||||
|
||||
void UPDATENEWS::store(QByteArray serverreply,QString apiname)
|
||||
void UPDATENEWS::replies()
|
||||
{
|
||||
QJsonDocument news;
|
||||
qDebug()<<apiname << news;
|
||||
QJsonParseError jsonerror;
|
||||
news=QJsonDocument::fromJson(serverreply,&jsonerror);
|
||||
if (news.isArray()){
|
||||
for (int i=0; i < news.array().count();i++){
|
||||
QJsonValue newsitem=news[i];
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("INSERT INTO news (username,messagetype,text,created_at,in_reply_to_status_id,source,status_id,in_reply_to_user_id,geo,favorited,uid,statusnet_html,statusnet_conversation_id,friendica_activities,friendica_activities_self,attachments,friendica_owner) " "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
query.bindValue(0,username);
|
||||
query.bindValue(1,"0");
|
||||
query.bindValue(2, newsitem["text"].toString().toUtf8().toBase64());
|
||||
QString sourcedate=newsitem["created_at"].toString();
|
||||
QString formateddate=sourcedate.mid(0,3)+", "+sourcedate.mid(8,3)+sourcedate.mid(4,3)+sourcedate.mid(25,5)+sourcedate.mid(10,15);
|
||||
query.bindValue(3,QDateTime::fromString(formateddate,Qt::RFC2822Date).toMSecsSinceEpoch() );
|
||||
if(newsitem["in_reply_to_status_id"]!=QJsonValue::Null){query.bindValue(4, newsitem["in_reply_to_status_id"].toInt());};
|
||||
query.bindValue(5,newsitem["source"]);
|
||||
query.bindValue(6,newsitem["id"].toInt());
|
||||
if(newsitem["in_reply_to_user_id"]!=QJsonValue::Null){ query.bindValue(7,newsitem["in_reply_to_user_id"].toInt());};
|
||||
query.bindValue(8,newsitem["geo"]);
|
||||
query.bindValue( 9, newsitem["favorited"].toInt());
|
||||
query.bindValue(10, newsitem["user"]["id"].toInt());
|
||||
query.bindValue(11, newsitem["statusnet_html"].toString().toUtf8().toBase64());
|
||||
query.bindValue(12, newsitem["statusnet_conversation_id"].toInt());
|
||||
QJsonArray likeArray;QJsonArray dislikeArray;QJsonArray attendyesArray;QJsonArray attendnoArray;QJsonArray attendmaybeArray;
|
||||
if (newsitem.toObject().contains("friendica_activities")){
|
||||
for (int a=0; a < newsitem["friendica_activities"]["like"].toArray().count();a++){
|
||||
likeArray.append(newsitem["friendica_activities"]["like"][a]["url"].toString());
|
||||
}
|
||||
for (int b=0; b < newsitem["friendica_activities"]["dislike"].toArray().count();b++){
|
||||
dislikeArray.append(newsitem["friendica_activities"]["dislike"][b]["url"].toString());
|
||||
}
|
||||
for (int c=0; c < newsitem["friendica_activities"]["attendyes"].toArray().count();c++){
|
||||
attendyesArray.append(newsitem["friendica_activities"]["attendyes"][c]["url"].toString());
|
||||
}
|
||||
for (int d=0; d < newsitem["friendica_activities"]["attendno"].toArray().count();d++){
|
||||
attendnoArray.append(newsitem["friendica_activities"]["attendno"][d]["url"].toString());
|
||||
}
|
||||
for (int e = 0; e < newsitem["friendica_activities"]["attendmaybe"].toArray().count();e++){
|
||||
attendmaybeArray.append(newsitem["friendica_activities"]["attendmaybe"][e]["url"].toString());
|
||||
}
|
||||
};
|
||||
QJsonArray friendica_activities; friendica_activities={likeArray,dislikeArray,attendyesArray,attendnoArray,attendmaybeArray};
|
||||
QJsonDocument activities; activities.setArray(friendica_activities);
|
||||
query.bindValue(13,activities.toJson(QJsonDocument::Compact).toBase64());
|
||||
query.bindValue(14,"[]");
|
||||
|
||||
if (newsitem["attachments"]!=QJsonValue::Undefined){
|
||||
query.bindValue(15, QJsonDocument(newsitem["attachments"].toArray()).toJson(QJsonDocument::Compact).toBase64());
|
||||
};
|
||||
|
||||
query.bindValue(16, newsitem["friendica_owner"]["url"]);
|
||||
query.exec() ;
|
||||
m_api="/api/statuses/replies";
|
||||
xhr.clearParams();
|
||||
xhr.setUrl(m_url);
|
||||
xhr.setApi(m_api);
|
||||
QSqlQuery query("SELECT status_id FROM news WHERE messagetype=3 AND username='"+ username +"' ORDER BY status_id DESC LIMIT 1",m_db);
|
||||
if (query.isActive() && query.isSelect()){
|
||||
if (query.first()){
|
||||
QString lastid=query.value(0).toString();
|
||||
xhr.setParam("since_id",lastid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qDebug()<< "Friendiqa updatenews error";
|
||||
emit this->error(m_api,QTextCodec::codecForName("utf-8")->toUnicode(serverreply));
|
||||
if(m_updateInterval!=0){
|
||||
m_db.close();
|
||||
m_db.removeDatabase(m_db.connectionName());
|
||||
emit quitapp();
|
||||
alarm.setAlarm(m_updateInterval);
|
||||
};
|
||||
xhr.setParam("count","50");
|
||||
xhr.get();
|
||||
QObject::connect(&xhr,SIGNAL(success(QByteArray,QString)),this,SLOT(store(QByteArray,QString)));
|
||||
QObject::connect(&xhr,SIGNAL(error(QString,QString,QString,int)),this,SLOT(showError(QString,QString,QString,int)));
|
||||
QObject::connect(&xhr, SIGNAL(downloaded(QString, QString, QString, int)), this, SLOT(updateImageLocation(QString,QString, QString, int)));
|
||||
}
|
||||
|
||||
void UPDATENEWS::directmessages()
|
||||
{
|
||||
m_api="/api/direct_messages/all";
|
||||
xhr.clearParams();
|
||||
xhr.setUrl(m_url);
|
||||
xhr.setApi(m_api);
|
||||
QSqlQuery query("SELECT status_id FROM news WHERE messagetype=1 AND username='"+ username +"' ORDER BY status_id DESC LIMIT 1",m_db);
|
||||
if (query.isActive() && query.isSelect()){
|
||||
if (query.first()){
|
||||
QString lastid=query.value(0).toString();
|
||||
xhr.setParam("since_id",lastid);
|
||||
}
|
||||
}
|
||||
xhr.get();
|
||||
QObject::connect(&xhr,SIGNAL(success(QByteArray,QString)),this,SLOT(store(QByteArray,QString)));
|
||||
QObject::connect(&xhr,SIGNAL(error(QString,QString,QString,int)),this,SLOT(showError(QString,QString,QString,int)));
|
||||
QObject::connect(&xhr, SIGNAL(downloaded(QString, QString, QString, int)), this, SLOT(updateImageLocation(QString,QString, QString, int)));
|
||||
}
|
||||
|
||||
void UPDATENEWS::notifications()
|
||||
{
|
||||
m_api="/api/friendica/notifications";
|
||||
xhr.clearParams();
|
||||
xhr.setUrl(m_url);
|
||||
xhr.setApi(m_api);
|
||||
xhr.get();
|
||||
QObject::connect(&xhr,SIGNAL(success(QByteArray,QString)),this,SLOT(store(QByteArray,QString)));
|
||||
QObject::connect(&xhr,SIGNAL(error(QString,QString,QString,int)),this,SLOT(showError(QString,QString,QString,int)));
|
||||
QObject::connect(&xhr, SIGNAL(downloaded(QString, QString, QString, int)), this, SLOT(updateImageLocation(QString,QString, QString, int)));
|
||||
}
|
||||
|
||||
|
||||
void UPDATENEWS::store(QByteArray serverreply,QString apiname)
|
||||
{ if (apiname!=m_api || xhr.downloadtype()!=""){} else {
|
||||
QJsonDocument news;
|
||||
//qDebug()<<apiname << serverreply;
|
||||
QJsonParseError jsonerror;
|
||||
news=QJsonDocument::fromJson(serverreply,&jsonerror);
|
||||
if (news.isArray()){
|
||||
for (int i=0; i < news.array().count();i++){
|
||||
QJsonValue newsitem=news[i];
|
||||
if (apiname=="/api/friendica/notifications"){
|
||||
QSqlQuery testquery("SELECT status_id FROM news WHERE status_id=" + QString::number(newsitem["id"].toInt()) + " AND messagetype=2 AND username='"+ username +"'",m_db);
|
||||
if (testquery.first()) {continue;}
|
||||
}
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("INSERT INTO news (username,messagetype,text,created_at,in_reply_to_status_id,source,status_id,in_reply_to_user_id,geo,favorited,uid,statusnet_html,statusnet_conversation_id,friendica_activities,friendica_activities_self,attachments,friendica_owner) " "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
query.bindValue(0,username);
|
||||
query.bindValue(1,"0");
|
||||
query.bindValue(2, newsitem["text"].toString().toUtf8().toBase64());
|
||||
QString sourcedate=newsitem["created_at"].toString();
|
||||
QString formateddate=sourcedate.mid(0,3)+", "+sourcedate.mid(8,3)+sourcedate.mid(4,3)+sourcedate.mid(25,5)+sourcedate.mid(10,15);
|
||||
query.bindValue(3,QDateTime::fromString(formateddate,Qt::RFC2822Date).toMSecsSinceEpoch() );
|
||||
if(newsitem["in_reply_to_status_id"]!=QJsonValue::Null){query.bindValue(4, newsitem["in_reply_to_status_id"].toInt());}
|
||||
query.bindValue(5,newsitem["source"]);
|
||||
query.bindValue(6,newsitem["id"].toInt());
|
||||
if(newsitem["in_reply_to_user_id"]!=QJsonValue::Null){ query.bindValue(7,newsitem["in_reply_to_user_id"].toInt());}
|
||||
query.bindValue(8,newsitem["geo"]);
|
||||
query.bindValue( 9, newsitem["favorited"].toInt());
|
||||
query.bindValue(10, newsitem["user"]["id"].toInt());
|
||||
query.bindValue(11, newsitem["statusnet_html"].toString().toUtf8().toBase64());
|
||||
query.bindValue(12, newsitem["statusnet_conversation_id"].toInt());
|
||||
QJsonArray likeArray;QJsonArray dislikeArray;QJsonArray attendyesArray;QJsonArray attendnoArray;QJsonArray attendmaybeArray;
|
||||
if (newsitem.toObject().contains("friendica_activities")){
|
||||
for (int a=0; a < newsitem["friendica_activities"]["like"].toArray().count();a++){
|
||||
likeArray.append(newsitem["friendica_activities"]["like"][a]["url"].toString());
|
||||
}
|
||||
for (int b=0; b < newsitem["friendica_activities"]["dislike"].toArray().count();b++){
|
||||
dislikeArray.append(newsitem["friendica_activities"]["dislike"][b]["url"].toString());
|
||||
}
|
||||
for (int c=0; c < newsitem["friendica_activities"]["attendyes"].toArray().count();c++){
|
||||
attendyesArray.append(newsitem["friendica_activities"]["attendyes"][c]["url"].toString());
|
||||
}
|
||||
for (int d=0; d < newsitem["friendica_activities"]["attendno"].toArray().count();d++){
|
||||
attendnoArray.append(newsitem["friendica_activities"]["attendno"][d]["url"].toString());
|
||||
}
|
||||
for (int e = 0; e < newsitem["friendica_activities"]["attendmaybe"].toArray().count();e++){
|
||||
attendmaybeArray.append(newsitem["friendica_activities"]["attendmaybe"][e]["url"].toString());
|
||||
}
|
||||
}
|
||||
QJsonArray friendica_activities; friendica_activities={likeArray,dislikeArray,attendyesArray,attendnoArray,attendmaybeArray};
|
||||
QJsonDocument activities; activities.setArray(friendica_activities);
|
||||
query.bindValue(13,activities.toJson(QJsonDocument::Compact).toBase64());
|
||||
query.bindValue(14,"[]");
|
||||
|
||||
if (newsitem["attachments"]!=QJsonValue::Undefined){
|
||||
query.bindValue(15, QJsonDocument(newsitem["attachments"].toArray()).toJson(QJsonDocument::Compact).toBase64());
|
||||
}else {
|
||||
query.bindValue(15, "");
|
||||
}
|
||||
|
||||
if (newsitem["friendica_author"]!=QJsonValue::Undefined){
|
||||
query.bindValue(16, newsitem["friendica_author"]["url"]);
|
||||
}else {
|
||||
query.bindValue(16, newsitem["user"]["url"]);
|
||||
}
|
||||
|
||||
if (apiname=="/api/statuses/replies"){
|
||||
query.bindValue(1,"3");
|
||||
}
|
||||
if (apiname == "/api/direct_messages/all"){
|
||||
query.bindValue(1,"1");
|
||||
query.bindValue(5,"Friendica");
|
||||
if(newsitem["recipient"]["id"]!=QJsonValue::Null){ query.bindValue(7,newsitem["recipient"]["id"].toInt());}
|
||||
query.bindValue(10, newsitem["sender_id"].toInt());
|
||||
query.bindValue(11, newsitem["text"].toString().toUtf8().toBase64());
|
||||
if(newsitem["friendica_parent_uri"]!=QJsonValue::Null){ query.bindValue(12,newsitem["friendica_parent_uri"]);}
|
||||
query.bindValue(16, newsitem["sender"]["url"]);
|
||||
}
|
||||
if (apiname == "/api/friendica/notifications"){
|
||||
query.bindValue(1,"2");
|
||||
query.bindValue(3,QDateTime::fromString(newsitem["date"].toString(),"yyyy-MM-dd hh:mm:ss").toMSecsSinceEpoch());
|
||||
query.bindValue(5,"Friendica");
|
||||
QJsonObject cleancontact= findNotificationContact(newsitem["url"].toString());
|
||||
query.bindValue(10, cleancontact["id"].toInt());
|
||||
query.bindValue(11, newsitem["msg_html"].toString().toUtf8().toBase64());
|
||||
if(newsitem["parent"]!=QJsonValue::Null){ query.bindValue(12,newsitem["parent"]);}
|
||||
query.bindValue(16, newsitem["url"]);
|
||||
}
|
||||
|
||||
if(!(query.exec())) {qDebug()<<query.lastError();}
|
||||
|
||||
// notifications
|
||||
if (apiname=="/api/statuses/friends_timeline"){
|
||||
if(notifylist.contains("notify_Timeline")){
|
||||
alarm.notify("Home: "+ newsitem["user"]["name"].toString(),newsitem["text"].toString(),0);
|
||||
}
|
||||
}
|
||||
if (apiname=="/api/statuses/replies"){
|
||||
if(notifylist.contains("notify_Replies")){
|
||||
alarm.notify("Replies: "+newsitem["user"]["name"].toString(),newsitem["text"].toString(),1);
|
||||
}
|
||||
}
|
||||
if (apiname=="/api/direct_messages/all"){
|
||||
if(notifylist.contains("notify_DirectMessages")){
|
||||
alarm.notify("DirectMessage: "+newsitem["sender"]["name"].toString(),newsitem["text"].toString(),2);
|
||||
}
|
||||
}
|
||||
if (apiname=="/api/friendica/notifications"){
|
||||
if(notifylist.contains("notify_Notifications")){
|
||||
alarm.notify("Notification: "+newsitem["name"].toString(),newsitem["text"].toString(),3);
|
||||
}
|
||||
}
|
||||
}
|
||||
QList<QJsonValue> newcontacts=findNewContacts(news);
|
||||
//qDebug()<< "new contacts count " << newcontacts.size();
|
||||
if (newcontacts.size()>0){
|
||||
updateContacts(newcontacts);
|
||||
startImagedownload();
|
||||
|
||||
} else {
|
||||
if(m_updateInterval!=0){
|
||||
syncindex+=1;
|
||||
startsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
qDebug()<< "Friendiqa updatenews error " << serverreply;
|
||||
emit this->error(m_api,QTextCodec::codecForName("utf-8")->toUnicode(serverreply));
|
||||
syncindex+=1;
|
||||
startsync();
|
||||
}
|
||||
}
|
||||
QList<QJsonValue> newcontacts=findNewContacts(news);
|
||||
updateContacts(newcontacts);
|
||||
startImagedownload();
|
||||
connect(&xhr, SIGNAL(downloaded(QString, QString, QString, int)), this, SLOT(updateImageLocation(QString,QString, QString, int)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UPDATENEWS::updateImageLocation(QString downloadtype,QString imageurl, QString filename, int index){
|
||||
if (downloadtype=="contactlist"){
|
||||
QSqlQuery testquery("SELECT profile_image FROM contacts WHERE profile_image_url ='"+imageurl+ "' AND username = '" +username+"'",m_db);
|
||||
testquery.exec();
|
||||
testquery.first();
|
||||
//qDebug()<< "update imageurl for " <<imageurl << " from " <<testquery.value(0).toString() <<" to "<< filename <<" index " << index << " newcontactnames.length " <<newcontactnames.length();
|
||||
QSqlQuery query("UPDATE contacts SET profile_image='"+ filename +"' WHERE profile_image_url ='"+imageurl+ "' AND username = '" +username+"'",m_db);
|
||||
query.exec();
|
||||
if (index==(newcontactnames.length()-1)){
|
||||
newcontactnames.clear();
|
||||
newcontactimagelinks.clear();
|
||||
if(m_updateInterval!=0){
|
||||
m_db.close();
|
||||
m_db.removeDatabase(m_db.connectionName());
|
||||
emit quitapp();
|
||||
alarm.setAlarm(m_updateInterval);
|
||||
};
|
||||
syncindex+=1;
|
||||
startsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject UPDATENEWS::findNotificationContact(QString contacturl){
|
||||
QSqlQuery query("SELECT id,url FROM contacts WHERE url='"+contacturl+"' AND username='"+ username+"'",m_db);
|
||||
query.first();
|
||||
QJsonObject contact{
|
||||
{"id", query.value(0).toInt()},
|
||||
{"url", query.value(1).toString()}
|
||||
};
|
||||
return contact;
|
||||
}
|
||||
|
||||
QList <QJsonValue> UPDATENEWS::findNewContacts(QJsonDocument news){
|
||||
QSqlQuery query("SELECT profile_image_url FROM contacts",m_db);
|
||||
QList<QString> imageurls;
|
||||
|
@ -231,46 +405,46 @@ QList <QJsonValue> UPDATENEWS::findNewContacts(QJsonDocument news){
|
|||
imageurls.append(query.value(0).toString());
|
||||
}
|
||||
QList<QJsonValue> newcontacts;
|
||||
qDebug()<<"updatenews findcontacts count "<<news.array().count();
|
||||
//qDebug()<<"updatenews findcontacts news count "<<news.array().count();
|
||||
|
||||
for (int i=0; i<news.array().count();i++){
|
||||
//main contacts
|
||||
if(imageurls.contains(news[i]["user"]["profile_image_url"].toString()) || newcontactimagelinks.contains(news[i]["user"]["profile_image_url"].toString())){
|
||||
if(imageurls.contains(news[i]["user"]["profile_image_url"].toString().section('?',0,0)) || newcontactimagelinks.contains(news[i]["user"]["profile_image_url"].toString().section('?',0,0))){
|
||||
}
|
||||
else{
|
||||
newcontacts.append(news[i]["user"]);
|
||||
newcontactimagelinks.append(news[i]["user"]["profile_image_url"].toString());
|
||||
newcontactimagelinks.append(news[i]["user"]["profile_image_url"].toString().section('?',0,0));
|
||||
newcontactnames.append(news[i]["user"]["screen_name"].toString());
|
||||
}
|
||||
//like/dislike contacts
|
||||
if (news[i].toObject().contains("friendica_activities") ){
|
||||
for (int a=0; a < news[i]["friendica_activities"]["like"].toArray().count();a++){
|
||||
if(imageurls.contains(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString()) || newcontactimagelinks.contains(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString())){
|
||||
if(imageurls.contains(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString().section('?',0,0)) || newcontactimagelinks.contains(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString().section('?',0,0))){
|
||||
}
|
||||
else{
|
||||
newcontacts.append(news[i]["friendica_activities"]["like"][a]);
|
||||
newcontactimagelinks.append(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString());
|
||||
newcontactimagelinks.append(news[i]["friendica_activities"]["like"][a]["profile_image_url"].toString().section('?',0,0));
|
||||
newcontactnames.append(news[i]["friendica_activities"][a]["screen_name"].toString());
|
||||
}
|
||||
}
|
||||
for (int b=0; b < news[i]["friendica_activities"]["dislike"].toArray().count();b++){
|
||||
if(imageurls.contains(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString()) || newcontactimagelinks.contains(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString())){
|
||||
if(imageurls.contains(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString().section('?',0,0)) || newcontactimagelinks.contains(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString().section('?',0,0))){
|
||||
}
|
||||
else{
|
||||
newcontacts.append(news[i]["friendica_activities"]["dislike"][b]);
|
||||
newcontactimagelinks.append(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString());
|
||||
newcontactimagelinks.append(news[i]["friendica_activities"]["dislike"][b]["profile_image_url"].toString().section('?',0,0));
|
||||
newcontactnames.append(news[i]["friendica_activities"][b]["screen_name"].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
//owner contacts
|
||||
if (news[i].toObject().contains("friendica_owner") ){
|
||||
if(imageurls.contains(news[i]["friendica_owner"]["profile_image_url"].toString()) || newcontactimagelinks.contains(news[i]["friendica_owner"]["profile_image_url"].toString())){
|
||||
if (news[i].toObject().contains("friendica_author") ){
|
||||
if(imageurls.contains(news[i]["friendica_author"]["profile_image_url"].toString().section('?',0,0)) || newcontactimagelinks.contains(news[i]["friendica_owner"]["profile_image_url"].toString().section('?',0,0))){
|
||||
}
|
||||
else{
|
||||
newcontacts.append(news[i]["friendica_owner"]);
|
||||
newcontactimagelinks.append(news[i]["friendica_owner"]["profile_image_url"].toString());
|
||||
newcontactnames.append(news[i]["friendica_owner"]["screen_name"].toString());
|
||||
newcontacts.append(news[i]["friendica_author"]);
|
||||
newcontactimagelinks.append(news[i]["friendica_author"]["profile_image_url"].toString().section('?',0,0));
|
||||
newcontactnames.append(news[i]["friendica_author"]["screen_name"].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -296,8 +470,8 @@ void UPDATENEWS::updateContacts(QList<QJsonValue> contacts){
|
|||
query.bindValue(2, contact["screen_name"]);
|
||||
query.bindValue(3, contact["location"]);
|
||||
query.bindValue(4, currentTime);
|
||||
query.bindValue(5, contact["profile_image_url"]);
|
||||
if(contact["description"].isNull() ){query.bindValue(6,"");}else{query.bindValue(6, contact["description"].toString().toUtf8().toBase64());};
|
||||
query.bindValue(5, contact["profile_image_url"].toString().section('?',0,0));
|
||||
if(contact["description"].isNull() ){query.bindValue(6,"");}else{query.bindValue(6, contact["description"].toString().toUtf8().toBase64());}
|
||||
query.bindValue(7,contact["protected"].toBool());
|
||||
query.bindValue(8,contact["followers_count"].toInt());
|
||||
query.bindValue(9,contact["friends_count"].toInt());
|
||||
|
@ -317,7 +491,7 @@ void UPDATENEWS::updateContacts(QList<QJsonValue> contacts){
|
|||
query.bindValue(21,contact["network"]);
|
||||
qint64 timestamp=0;
|
||||
QString timestamphelper=contact["profile_image_url"].toString();
|
||||
try {timestamp=timestamphelper.mid(timestamphelper.indexOf("?ts")+4,timestamphelper.length()).toUInt();} catch(...){};
|
||||
try {timestamp=timestamphelper.mid(timestamphelper.indexOf("?ts")+4,timestamphelper.length()).toUInt();} catch(...){}
|
||||
query.bindValue(22,timestamp);
|
||||
}
|
||||
|
||||
|
@ -334,8 +508,8 @@ void UPDATENEWS::updateContacts(QList<QJsonValue> contacts){
|
|||
query.bindValue(3, contact["screen_name"]);
|
||||
query.bindValue(4, contact["location"]);
|
||||
query.bindValue(5, currentTime);
|
||||
query.bindValue(6, contact["profile_image_url"]);
|
||||
if(contact["description"].isNull() ){query.bindValue(7,"");}else{query.bindValue(7, contact["description"].toString().toUtf8().toBase64());};
|
||||
query.bindValue(6, contact["profile_image_url"].toString().section('?',0,0));
|
||||
if(contact["description"].isNull() ){query.bindValue(7,"");}else{query.bindValue(7, contact["description"].toString().toUtf8().toBase64());}
|
||||
query.bindValue(8,"none");
|
||||
query.bindValue(9, contact["url"].toString());
|
||||
query.bindValue(10,contact["protected"].toBool());
|
||||
|
@ -358,19 +532,12 @@ void UPDATENEWS::updateContacts(QList<QJsonValue> contacts){
|
|||
query.bindValue(25, 0);
|
||||
qint64 timestamp=0;
|
||||
QString timestamphelper=contact["profile_image_url"].toString();
|
||||
try {timestamp=timestamphelper.mid(timestamphelper.indexOf("?ts")+4,timestamphelper.length()).toUInt();} catch(...){};
|
||||
try {timestamp=timestamphelper.mid(timestamphelper.indexOf("?ts")+4,timestamphelper.length()).toUInt();} catch(...){}
|
||||
query.bindValue(26,timestamp);
|
||||
|
||||
}
|
||||
query.exec() ;
|
||||
}
|
||||
emit this->success(m_api);
|
||||
if ((contacts.count()==0) && (m_updateInterval!=0)){
|
||||
m_db.close();
|
||||
m_db.removeDatabase(m_db.connectionName());
|
||||
emit quitapp();
|
||||
alarm.setAlarm(m_updateInterval);
|
||||
};
|
||||
}
|
||||
|
||||
QString UPDATENEWS::url() const
|
||||
|
@ -380,6 +547,7 @@ QString UPDATENEWS::url() const
|
|||
|
||||
void UPDATENEWS::startImagedownload()
|
||||
{
|
||||
//qDebug() << "start image download";
|
||||
xhr.setDownloadtype("contactlist");
|
||||
xhr.setFilelist(newcontactimagelinks);
|
||||
xhr.setContactlist(newcontactnames);
|
||||
|
@ -389,11 +557,12 @@ void UPDATENEWS::startImagedownload()
|
|||
|
||||
void UPDATENEWS::showError(QString data, QString url,QString api, int code )
|
||||
{
|
||||
qDebug() << "showerror " << api << " data " << data;
|
||||
emit this->error(api,data);
|
||||
if(m_updateInterval!=0){
|
||||
m_db.close();
|
||||
m_db.removeDatabase(m_db.connectionName());
|
||||
emit quitapp();
|
||||
alarm.setAlarm(m_updateInterval);
|
||||
};
|
||||
if (api!=m_api || xhr.downloadtype()!=""){} else{
|
||||
if(m_updateInterval!=0){
|
||||
syncindex+=1;
|
||||
startsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include <QSqlDatabase>
|
||||
#include "xhr.h"
|
||||
#include "alarm.h"
|
||||
#include "AndroidNative/systemdispatcher.h"
|
||||
//#include "AndroidNative/systemdispatcher.h"
|
||||
|
||||
class UPDATENEWS : public QObject
|
||||
{
|
||||
|
@ -64,6 +64,10 @@ public slots:
|
|||
void setDatabase();
|
||||
void login();
|
||||
void timeline();
|
||||
void replies();
|
||||
void startsync();
|
||||
void directmessages();
|
||||
void notifications();
|
||||
//void startservice(QString type,QVariantMap map);
|
||||
void startImagedownload();
|
||||
void updateImageLocation(QString downloadtype,QString imageurl, QString filename, int index);
|
||||
|
@ -76,8 +80,12 @@ private:
|
|||
QString m_imagedir;
|
||||
QString m_login;
|
||||
QString username;
|
||||
int syncindex;
|
||||
QSqlDatabase m_db;
|
||||
QList<QString> synclist;
|
||||
QList <QString> notifylist;
|
||||
QList<QJsonValue> findNewContacts(QJsonDocument news);
|
||||
QJsonObject findNotificationContact(QString imagelink);
|
||||
int m_updateInterval;
|
||||
//void timeline();
|
||||
//void store(QByteArray serverreply,QString apiname);
|
||||
|
|
|
@ -154,7 +154,7 @@ QString XHR::downloadtype() const
|
|||
return m_downloadtype;
|
||||
}
|
||||
|
||||
QString XHR::networktype() const
|
||||
QString XHR::networktype()
|
||||
{
|
||||
return nc.bearerTypeFamily() + nc.bearerTypeName();
|
||||
}
|
||||
|
@ -184,7 +184,6 @@ void XHR::download()
|
|||
request.setRawHeader("Authorization", headerData.toLocal8Bit());
|
||||
}
|
||||
request.setUrl(requrl);
|
||||
//qDebug() << requrl;
|
||||
reply = manager.get(request);
|
||||
reply->ignoreSslErrors();
|
||||
connect(reply, &QNetworkReply::readyRead,this, &XHR::onReadyRead);
|
||||
|
@ -202,10 +201,11 @@ void XHR::get()
|
|||
while(i.hasNext()) {
|
||||
i.next();
|
||||
query.addQueryItem(i.key(), i.value());
|
||||
//qDebug()<<i.key() << " value "<< i.value();
|
||||
}
|
||||
|
||||
QUrl requrl(m_url+m_api);
|
||||
//qDebug() << requrl;
|
||||
//qDebug() << "API "<< requrl<<m_api;
|
||||
requrl.setQuery(query);
|
||||
QByteArray loginData = m_login.toLocal8Bit().toBase64();
|
||||
QString headerData = "Basic " + loginData;
|
||||
|
@ -229,7 +229,7 @@ void XHR::getlist()
|
|||
else {
|
||||
XHR::setUrl(m_filelist.at(dlindex));}
|
||||
XHR::download();
|
||||
} else {dlindex=0;}
|
||||
} else {dlindex=0;m_downloadtype="";m_contactlist.clear();m_filelist.clear();}
|
||||
}
|
||||
|
||||
|
||||
|
@ -297,6 +297,7 @@ void XHR::onReplySuccess()
|
|||
|
||||
void XHR::onRequestFinished()
|
||||
{
|
||||
qDebug()<<"download requestFinished ";
|
||||
// Save the file here
|
||||
if (buffer.isNull()){qDebug() << "File empty"<<m_url; buffer.clear(); emit this->error(m_downloadtype,m_url,m_api,1);}
|
||||
else if (m_downloadtype=="picturelist") {
|
||||
|
|
|
@ -49,7 +49,7 @@ class XHR : public QObject
|
|||
Q_PROPERTY(QList<QString> contactlist READ contactlist WRITE setContactlist NOTIFY contactlistChanged)
|
||||
Q_PROPERTY(QList<QString> filelist READ filelist WRITE setFilelist NOTIFY filelistChanged)
|
||||
Q_PROPERTY(QString downloadtype READ downloadtype WRITE setDownloadtype NOTIFY downloadtypeChanged)
|
||||
Q_PROPERTY(QString networktype READ networktype NOTIFY networktypeChanged)
|
||||
Q_PROPERTY(QString networktype READ networktype() NOTIFY networktypeChanged)
|
||||
|
||||
|
||||
public:
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
QList<QString> filelist() const;
|
||||
QString imagedir() const;
|
||||
QString downloadtype() const;
|
||||
QString networktype() const;
|
||||
QString networktype();
|
||||
|
||||
signals:
|
||||
void urlChanged();
|
||||
|
@ -98,6 +98,7 @@ public slots:
|
|||
void get();
|
||||
void getlist();
|
||||
void download();
|
||||
|
||||
// void networktype();
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue