mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:36:30 +02:00
Tray Notifier Checkpoint
* Add app launch * Add authentication for auth-related calls * Refactor notifications code
This commit is contained in:
parent
499c0594c7
commit
d5f756c79d
10 changed files with 341 additions and 178 deletions
|
@ -3427,7 +3427,13 @@ void Application::handleSandboxStatus(QNetworkReply* reply) {
|
||||||
int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY);
|
int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY);
|
||||||
QString addressLookupString;
|
QString addressLookupString;
|
||||||
if (urlIndex != -1) {
|
if (urlIndex != -1) {
|
||||||
addressLookupString = arguments().value(urlIndex + 1);
|
QUrl url(arguments().value(urlIndex + 1));
|
||||||
|
if (url.scheme() == URL_SCHEME_HIFIAPP) {
|
||||||
|
QmlCommerce commerce;
|
||||||
|
commerce.openSystemApp(url.path());
|
||||||
|
} else {
|
||||||
|
addressLookupString = arguments().value(urlIndex + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QString SENT_TO_PREVIOUS_LOCATION = "previous_location";
|
static const QString SENT_TO_PREVIOUS_LOCATION = "previous_location";
|
||||||
|
@ -7674,6 +7680,9 @@ void Application::openUrl(const QUrl& url) const {
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
if (url.scheme() == URL_SCHEME_HIFI) {
|
if (url.scheme() == URL_SCHEME_HIFI) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||||
|
} else if (url.scheme() == URL_SCHEME_HIFIAPP) {
|
||||||
|
QmlCommerce commerce;
|
||||||
|
commerce.openSystemApp(url.path());
|
||||||
} else {
|
} else {
|
||||||
// address manager did not handle - ask QDesktopServices to handle
|
// address manager did not handle - ask QDesktopServices to handle
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
|
|
|
@ -47,6 +47,16 @@ QmlCommerce::QmlCommerce() {
|
||||||
_appsPath = PathUtils::getAppDataPath() + "Apps/";
|
_appsPath = PathUtils::getAppDataPath() + "Apps/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlCommerce::openSystemApp(const QString& appPath) {
|
||||||
|
|
||||||
|
QUrl appUrl = PathUtils::qmlUrl(appPath);
|
||||||
|
|
||||||
|
auto tablet = dynamic_cast<TabletProxy*>(
|
||||||
|
DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system"));
|
||||||
|
tablet->loadQMLSource(appUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void QmlCommerce::getWalletStatus() {
|
void QmlCommerce::getWalletStatus() {
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
wallet->getWalletStatus();
|
wallet->getWalletStatus();
|
||||||
|
@ -353,7 +363,7 @@ bool QmlCommerce::openApp(const QString& itemHref) {
|
||||||
// Read from the file to know what .html or .qml document to open
|
// Read from the file to know what .html or .qml document to open
|
||||||
QFile appFile(_appsPath + "/" + appHref.fileName());
|
QFile appFile(_appsPath + "/" + appHref.fileName());
|
||||||
if (!appFile.open(QIODevice::ReadOnly)) {
|
if (!appFile.open(QIODevice::ReadOnly)) {
|
||||||
qCDebug(commerce) << "Couldn't open local .app.json file.";
|
qCDebug(commerce) << "Couldn't open local .app.json file:" << _appsPath << "/" << appHref.fileName();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());
|
QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll());
|
||||||
|
|
|
@ -24,6 +24,7 @@ class QmlCommerce : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlCommerce();
|
QmlCommerce();
|
||||||
|
void openSystemApp(const QString& appPath);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void walletStatusResult(uint walletStatus);
|
void walletStatusResult(uint walletStatus);
|
||||||
|
|
|
@ -176,7 +176,7 @@ int main(int argc, const char* argv[]) {
|
||||||
if (socket.waitForConnected(LOCAL_SERVER_TIMEOUT_MS)) {
|
if (socket.waitForConnected(LOCAL_SERVER_TIMEOUT_MS)) {
|
||||||
if (parser.isSet(urlOption)) {
|
if (parser.isSet(urlOption)) {
|
||||||
QUrl url = QUrl(parser.value(urlOption));
|
QUrl url = QUrl(parser.value(urlOption));
|
||||||
if (url.isValid() && url.scheme() == URL_SCHEME_HIFI) {
|
if (url.isValid() && (url.scheme() == URL_SCHEME_HIFI || url.scheme() == URL_SCHEME_HIFIAPP)) {
|
||||||
qDebug() << "Writing URL to local socket";
|
qDebug() << "Writing URL to local socket";
|
||||||
socket.write(url.toString().toUtf8());
|
socket.write(url.toString().toUtf8());
|
||||||
if (!socket.waitForBytesWritten(5000)) {
|
if (!socket.waitForBytesWritten(5000)) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace NetworkingConstants {
|
||||||
|
|
||||||
const QString URL_SCHEME_ABOUT = "about";
|
const QString URL_SCHEME_ABOUT = "about";
|
||||||
const QString URL_SCHEME_HIFI = "hifi";
|
const QString URL_SCHEME_HIFI = "hifi";
|
||||||
|
const QString URL_SCHEME_HIFIAPP = "hifiapp";
|
||||||
const QString URL_SCHEME_QRC = "qrc";
|
const QString URL_SCHEME_QRC = "qrc";
|
||||||
const QString URL_SCHEME_FILE = "file";
|
const QString URL_SCHEME_FILE = "file";
|
||||||
const QString URL_SCHEME_HTTP = "http";
|
const QString URL_SCHEME_HTTP = "http";
|
||||||
|
|
|
@ -41,6 +41,11 @@ const ProcessGroupStates = hfprocess.ProcessGroupStates;
|
||||||
const hfApp = require('./modules/hf-app.js');
|
const hfApp = require('./modules/hf-app.js');
|
||||||
const GetBuildInfo = hfApp.getBuildInfo;
|
const GetBuildInfo = hfApp.getBuildInfo;
|
||||||
const StartInterface = hfApp.startInterface;
|
const StartInterface = hfApp.startInterface;
|
||||||
|
const getRootHifiDataDirectory = hfApp.getRootHifiDataDirectory;
|
||||||
|
const getDomainServerClientResourcesDirectory = hfApp.getDomainServerClientResourcesDirectory;
|
||||||
|
const getAssignmentClientResourcesDirectory = hfApp.getAssignmentClientResourcesDirectory;
|
||||||
|
const getApplicationDataDirectory = hfApp.getApplicationDataDirectory;
|
||||||
|
|
||||||
|
|
||||||
const osType = os.type();
|
const osType = os.type();
|
||||||
|
|
||||||
|
@ -55,32 +60,7 @@ const HOME_CONTENT_URL = "http://cdn.highfidelity.com/content-sets/home-tutorial
|
||||||
|
|
||||||
const buildInfo = GetBuildInfo();
|
const buildInfo = GetBuildInfo();
|
||||||
|
|
||||||
function getRootHifiDataDirectory(local) {
|
|
||||||
var organization = buildInfo.organization;
|
|
||||||
if (osType == 'Windows_NT') {
|
|
||||||
if (local) {
|
|
||||||
return path.resolve(osHomeDir(), 'AppData/Local', organization);
|
|
||||||
} else {
|
|
||||||
return path.resolve(osHomeDir(), 'AppData/Roaming', organization);
|
|
||||||
}
|
|
||||||
} else if (osType == 'Darwin') {
|
|
||||||
return path.resolve(osHomeDir(), 'Library/Application Support', organization);
|
|
||||||
} else {
|
|
||||||
return path.resolve(osHomeDir(), '.local/share/', organization);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDomainServerClientResourcesDirectory() {
|
|
||||||
return path.join(getRootHifiDataDirectory(), '/domain-server');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAssignmentClientResourcesDirectory() {
|
|
||||||
return path.join(getRootHifiDataDirectory(), '/assignment-client');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getApplicationDataDirectory(local) {
|
|
||||||
return path.join(getRootHifiDataDirectory(local), '/Server Console');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update lock filepath
|
// Update lock filepath
|
||||||
const UPDATER_LOCK_FILENAME = ".updating";
|
const UPDATER_LOCK_FILENAME = ".updating";
|
||||||
|
@ -352,8 +332,8 @@ const HifiNotifications = hfNotifications.HifiNotifications;
|
||||||
const HifiNotificationType = hfNotifications.NotificationType;
|
const HifiNotificationType = hfNotifications.NotificationType;
|
||||||
|
|
||||||
var pendingNotifications = {}
|
var pendingNotifications = {}
|
||||||
function notificationCallback(notificationType) {
|
function notificationCallback(notificationType, pending = true) {
|
||||||
pendingNotifications[notificationType] = true;
|
pendingNotifications[notificationType] = pending;
|
||||||
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +404,7 @@ var labels = {
|
||||||
goto: {
|
goto: {
|
||||||
label: 'Goto',
|
label: 'Goto',
|
||||||
click: function() {
|
click: function() {
|
||||||
StartInterface("");
|
StartInterface("hifiapp:hifi/tablet/TabletAddressDialog.qml");
|
||||||
pendingNotifications[HifiNotificationType.GOTO] = false;
|
pendingNotifications[HifiNotificationType.GOTO] = false;
|
||||||
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
||||||
}
|
}
|
||||||
|
@ -432,7 +412,7 @@ var labels = {
|
||||||
people: {
|
people: {
|
||||||
label: 'People',
|
label: 'People',
|
||||||
click: function() {
|
click: function() {
|
||||||
StartInterface("");
|
StartInterface("hifiapp:hifi/Pal.qml");
|
||||||
pendingNotifications[HifiNotificationType.PEOPLE] = false;
|
pendingNotifications[HifiNotificationType.PEOPLE] = false;
|
||||||
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
||||||
}
|
}
|
||||||
|
@ -440,7 +420,7 @@ var labels = {
|
||||||
wallet: {
|
wallet: {
|
||||||
label: 'Wallet',
|
label: 'Wallet',
|
||||||
click: function() {
|
click: function() {
|
||||||
StartInterface("");
|
StartInterface("hifiapp:hifi/commerce/wallet/Wallet.qml");
|
||||||
pendingNotifications[HifiNotificationType.WALLET] = false;
|
pendingNotifications[HifiNotificationType.WALLET] = false;
|
||||||
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
||||||
}
|
}
|
||||||
|
@ -448,7 +428,7 @@ var labels = {
|
||||||
marketplace: {
|
marketplace: {
|
||||||
label: 'Marketplace',
|
label: 'Marketplace',
|
||||||
click: function() {
|
click: function() {
|
||||||
StartInterface("");
|
StartInterface("hifiapp:hifi/commerce/purchases/Purchases.qml");
|
||||||
pendingNotifications[HifiNotificationType.MARKETPLACE] = false;
|
pendingNotifications[HifiNotificationType.MARKETPLACE] = false;
|
||||||
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED);
|
||||||
}
|
}
|
||||||
|
|
135
server-console/src/modules/hf-acctinfo.js
Normal file
135
server-console/src/modules/hf-acctinfo.js
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const request = require('request');
|
||||||
|
const extend = require('extend');
|
||||||
|
const util = require('util');
|
||||||
|
const events = require('events');
|
||||||
|
const childProcess = require('child_process');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const hfApp = require('./hf-app.js');
|
||||||
|
const getInterfaceDataDirectory = hfApp.getInterfaceDataDirectory;
|
||||||
|
|
||||||
|
|
||||||
|
const VariantTypes = {
|
||||||
|
USER_TYPE: 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
function AccountInfo() {
|
||||||
|
|
||||||
|
var accountInfoPath = path.join(getInterfaceDataDirectory(), '/AccountInfo.bin');
|
||||||
|
this.rawData = null;
|
||||||
|
this.parseOffset = 0;
|
||||||
|
try {
|
||||||
|
this.rawData = fs.readFileSync(accountInfoPath);
|
||||||
|
|
||||||
|
this.data = this._parseMap();
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
|
log.debug("AccountInfo file not found: " + accountInfoPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountInfo.prototype = {
|
||||||
|
|
||||||
|
accessToken: function(metaverseUrl) {
|
||||||
|
return this.data[metaverseUrl]["accessToken"]["token"];
|
||||||
|
},
|
||||||
|
_parseUInt32: function () {
|
||||||
|
if (!this.rawData || (this.rawData.length - this.parseOffset < 4)) {
|
||||||
|
throw "Expected uint32";
|
||||||
|
}
|
||||||
|
var result = this.rawData.readUInt32BE(this.parseOffset);
|
||||||
|
this.parseOffset += 4;
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
_parseMap: function() {
|
||||||
|
var result = {};
|
||||||
|
var n = this._parseUInt32();
|
||||||
|
for(var i = 0; i < n; i++) {
|
||||||
|
var key = this._parseQString();
|
||||||
|
result[key] = this._parseVariant();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
_parseVariant: function() {
|
||||||
|
var varType = this._parseUInt32();
|
||||||
|
var isNull = this.rawData[this.parseOffset++];
|
||||||
|
|
||||||
|
switch(varType) {
|
||||||
|
case VariantTypes.USER_TYPE:
|
||||||
|
//user type
|
||||||
|
var userTypeName = this._parseByteArray().toString('ascii').slice(0,-1);
|
||||||
|
if(userTypeName == "DataServerAccountInfo") {
|
||||||
|
return this._parseDataServerAccountInfo();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw "Unknown custom type " + userTypeName;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_parseByteArray: function() {
|
||||||
|
var length = this._parseUInt32();
|
||||||
|
if (length == 0xffffffff) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var result = this.rawData.slice(this.parseOffset, this.parseOffset+length);
|
||||||
|
this.parseOffset += length;
|
||||||
|
return result;
|
||||||
|
|
||||||
|
},
|
||||||
|
_parseQString: function() {
|
||||||
|
if (!this.rawData || (this.rawData.length <= this.parseOffset)) {
|
||||||
|
throw "Expected QString";
|
||||||
|
}
|
||||||
|
// length in bytes;
|
||||||
|
var length = this._parseUInt32();
|
||||||
|
if(length == 0xFFFFFFFF) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.rawData.length - this.parseOffset < length) {
|
||||||
|
throw "Insufficient buffer length for QString parsing";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert from BE UTF16 to LE
|
||||||
|
var resultBuffer = this.rawData.slice(this.parseOffset, this.parseOffset+length);
|
||||||
|
resultBuffer.swap16();
|
||||||
|
var result = resultBuffer.toString('utf16le');
|
||||||
|
this.parseOffset += length;
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
_parseDataServerAccountInfo: function() {
|
||||||
|
return {
|
||||||
|
accessToken: this._parseOAuthAccessToken(),
|
||||||
|
username: this._parseQString(),
|
||||||
|
xmppPassword: this._parseQString(),
|
||||||
|
discourseApiKey: this._parseQString(),
|
||||||
|
walletId: this._parseUUID(),
|
||||||
|
privateKey: this._parseByteArray(),
|
||||||
|
domainId: this._parseUUID(),
|
||||||
|
tempDomainId: this._parseUUID(),
|
||||||
|
tempDomainApiKey: this._parseQString()
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_parseOAuthAccessToken: function() {
|
||||||
|
return {
|
||||||
|
token: this._parseQString(),
|
||||||
|
timestampHigh: this._parseUInt32(),
|
||||||
|
timestampLow: this._parseUInt32(),
|
||||||
|
tokenType: this._parseQString(),
|
||||||
|
refreshToken: this._parseQString()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_parseUUID: function() {
|
||||||
|
this.parseOffset += 16;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.AccountInfo = AccountInfo;
|
|
@ -6,6 +6,7 @@ const pathFinder = require('./path-finder');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const argv = require('yargs').argv;
|
const argv = require('yargs').argv;
|
||||||
const hfprocess = require('./hf-process');
|
const hfprocess = require('./hf-process');
|
||||||
|
const osHomeDir = require('os-homedir');
|
||||||
const Process = hfprocess.Process;
|
const Process = hfprocess.Process;
|
||||||
|
|
||||||
const binaryType = argv.binaryType;
|
const binaryType = argv.binaryType;
|
||||||
|
@ -69,3 +70,35 @@ exports.isInterfaceRunning = function(done) {
|
||||||
var pInterface = new Process('interface', 'interface.exe');
|
var pInterface = new Process('interface', 'interface.exe');
|
||||||
return pInterface.isRunning(done);
|
return pInterface.isRunning(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.getRootHifiDataDirectory = function(local) {
|
||||||
|
var organization = buildInfo.organization;
|
||||||
|
if (osType == 'Windows_NT') {
|
||||||
|
if (local) {
|
||||||
|
return path.resolve(osHomeDir(), 'AppData/Local', organization);
|
||||||
|
} else {
|
||||||
|
return path.resolve(osHomeDir(), 'AppData/Roaming', organization);
|
||||||
|
}
|
||||||
|
} else if (osType == 'Darwin') {
|
||||||
|
return path.resolve(osHomeDir(), 'Library/Application Support', organization);
|
||||||
|
} else {
|
||||||
|
return path.resolve(osHomeDir(), '.local/share/', organization);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getDomainServerClientResourcesDirectory = function() {
|
||||||
|
return path.join(exports.getRootHifiDataDirectory(), '/domain-server');
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getAssignmentClientResourcesDirectory = function() {
|
||||||
|
return path.join(exports.getRootHifiDataDirectory(), '/assignment-client');
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getApplicationDataDirectory = function(local) {
|
||||||
|
return path.join(exports.getRootHifiDataDirectory(local), '/Server Console');
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getInterfaceDataDirectory = function(local) {
|
||||||
|
return path.join(exports.getRootHifiDataDirectory(local), '/Interface');
|
||||||
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
const request = require('request');
|
|
||||||
const extend = require('extend');
|
|
||||||
const util = require('util');
|
|
||||||
const events = require('events');
|
|
||||||
const childProcess = require('child_process');
|
|
||||||
const fs = require('fs-extra');
|
|
||||||
const os = require('os');
|
|
||||||
const path = require('path');
|
|
|
@ -4,14 +4,18 @@ const os = require('os');
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const hfApp = require('./hf-app');
|
const hfApp = require('./hf-app');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const AccountInfo = require('./hf-acctinfo').AccountInfo;
|
||||||
|
const GetBuildInfo = hfApp.getBuildInfo;
|
||||||
|
const buildInfo = GetBuildInfo();
|
||||||
|
|
||||||
const notificationIcon = path.join(__dirname, '../../resources/console-notification.png');
|
const notificationIcon = path.join(__dirname, '../../resources/console-notification.png');
|
||||||
const NOTIFICATION_POLL_TIME_MS = 15 * 1000;
|
const NOTIFICATION_POLL_TIME_MS = 15 * 1000;
|
||||||
const METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://highfidelity.com'
|
const METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://metaverse.highfidelity.com'
|
||||||
const STORIES_URL= '/api/v1/user_stories';
|
const STORIES_URL= '/api/v1/user_stories';
|
||||||
const USERS_URL= '/api/v1/users';
|
const USERS_URL= '/api/v1/users';
|
||||||
const ECONOMIC_ACTIVITY_URL= '/api/v1/commerce/history';
|
const ECONOMIC_ACTIVITY_URL= '/api/v1/commerce/history';
|
||||||
const UPDATES_URL= '/api/v1/commerce/available_updates';
|
const UPDATES_URL= '/api/v1/commerce/available_updates';
|
||||||
|
const MAX_NOTIFICATION_ITEMS=30
|
||||||
|
|
||||||
|
|
||||||
const StartInterface=hfApp.startInterface;
|
const StartInterface=hfApp.startInterface;
|
||||||
|
@ -31,55 +35,60 @@ function HifiNotification(notificationType, notificationData) {
|
||||||
|
|
||||||
HifiNotification.prototype = {
|
HifiNotification.prototype = {
|
||||||
show: function() {
|
show: function() {
|
||||||
|
var text = "";
|
||||||
|
var message = "";
|
||||||
|
var url = null;
|
||||||
|
var app = null;
|
||||||
switch(this.type) {
|
switch(this.type) {
|
||||||
case NotificationType.GOTO:
|
case NotificationType.GOTO:
|
||||||
var text = this.data.username + " " + this.data.action_string + " in " + this.data.place_name;
|
text = this.data.username + " " + this.data.action_string + " in " + this.data.place_name;
|
||||||
notifier.notify({
|
message = "Click to go to " + this.data.place_name;
|
||||||
notificationType: this.type,
|
url = "hifi://" + this.data.place_name + this.data.path;
|
||||||
icon: notificationIcon,
|
|
||||||
title: text,
|
|
||||||
message: "Click to goto " + this.data.place_name,
|
|
||||||
wait: true,
|
|
||||||
url: "hifi://" + this.data.place_name + this.data.path
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotificationType.PEOPLE:
|
case NotificationType.PEOPLE:
|
||||||
var text = this.data.username + " has logged in.";
|
text = this.data.username + " is available in " + this.data.location.root.name + "!";
|
||||||
notifier.notify({
|
message = "Click to join them.";
|
||||||
notificationType: this.type,
|
url="hifi://" + this.data.location.root.name + this.data.location.path;
|
||||||
icon: notificationIcon,
|
|
||||||
title: text,
|
|
||||||
message: "Click to join them in " + this.data.location.root.name,
|
|
||||||
wait: true,
|
|
||||||
url: "hifi://" + this.data.location.root.name + this.data.location.path
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotificationType.WALLET:
|
case NotificationType.WALLET:
|
||||||
var text = "Economic activity.";
|
if(typeof(this.data) == "number") {
|
||||||
notifier.notify({
|
text = "You have " + this.data + " unread Wallet notifications!";
|
||||||
notificationType: this.type,
|
message = "Click to open your wallet."
|
||||||
icon: notificationIcon,
|
url = "hifiapp:hifi/commerce/wallet/Wallet.qml";
|
||||||
title: text,
|
break;
|
||||||
message: "Click to open your wallet",
|
}
|
||||||
wait: true,
|
text = "Economic activity.";
|
||||||
app: "Wallet"
|
var memo = "";
|
||||||
});
|
if(this.data.sent_certs <= 0 && this.data.received_certs <= 0) {
|
||||||
|
if(this.data.received_money > 0) {
|
||||||
|
text = this.data.sender_name + " sent you " + this.data.received_money + " HFC!";
|
||||||
|
memo = "memo: \"" + this.data.message + "\" ";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text = this.data.message.replace(/<\/?[^>]+(>|$)/g, "");
|
||||||
|
}
|
||||||
|
message = memo + "Click to open your wallet.";
|
||||||
|
url = "hifiapp:hifi/commerce/wallet/Wallet.qml";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotificationType.MARKETPLACE:
|
case NotificationType.MARKETPLACE:
|
||||||
var text = "One of your marketplace items has an update.";
|
text = "There's an update available for your version of " + this.data.base_item_title + "!";
|
||||||
notifier.notify({
|
message = "Click to open the marketplace.";
|
||||||
notificationType: this.type,
|
url = "hifiapp:hifi/commerce/purchases/Purchases.qml";
|
||||||
icon: notificationIcon,
|
|
||||||
title: text,
|
|
||||||
message: "Click to start the marketplace app",
|
|
||||||
wait: true,
|
|
||||||
app: "Marketplace"
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
notifier.notify({
|
||||||
|
notificationType: this.type,
|
||||||
|
icon: notificationIcon,
|
||||||
|
title: text,
|
||||||
|
message: message,
|
||||||
|
wait: true,
|
||||||
|
appID: buildInfo.appUserModelId,
|
||||||
|
url: url
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +98,6 @@ function HifiNotifications(config, callback) {
|
||||||
this.since = new Date(this.config.get("notifySince", "1970-01-01T00:00:00.000Z"));
|
this.since = new Date(this.config.get("notifySince", "1970-01-01T00:00:00.000Z"));
|
||||||
this.enable(this.enabled());
|
this.enable(this.enabled());
|
||||||
notifier.on('click', function(notifierObject, options) {
|
notifier.on('click', function(notifierObject, options) {
|
||||||
console.log(options);
|
|
||||||
StartInterface(options.url);
|
StartInterface(options.url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -100,16 +108,18 @@ HifiNotifications.prototype = {
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.pollTimer = setInterval(function() {
|
this.pollTimer = setInterval(function() {
|
||||||
|
var acctInfo = new AccountInfo();
|
||||||
|
var token = acctInfo.accessToken(METAVERSE_SERVER_URL);
|
||||||
var _since = _this.since;
|
var _since = _this.since;
|
||||||
_this.since = new Date();
|
_this.since = new Date();
|
||||||
IsInterfaceRunning(function(running) {
|
IsInterfaceRunning(function(running) {
|
||||||
if(running) {
|
if(running) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_this.pollForStories(_since, _this.callback);
|
_this.pollForStories(_since, token);
|
||||||
_this.pollForConnections(_since, _this.callback);
|
_this.pollForConnections(_since, token);
|
||||||
_this.pollForEconomicActivity(_since, _this.callback);
|
_this.pollForEconomicActivity(_since, token);
|
||||||
_this.pollForMarketplaceUpdates(_since, _this.callback);
|
_this.pollForMarketplaceUpdates(_since, token);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
NOTIFICATION_POLL_TIME_MS);
|
NOTIFICATION_POLL_TIME_MS);
|
||||||
|
@ -127,134 +137,128 @@ HifiNotifications.prototype = {
|
||||||
clearInterval(this.pollTimer);
|
clearInterval(this.pollTimer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pollForStories: function(since, callback) {
|
_pollCommon: function(notifyType, error, data, since) {
|
||||||
|
var maxNotificationItemCount = (since.getTime() == 0) ? MAX_NOTIFICATION_ITEMS : 1;
|
||||||
|
if (error || !data.body) {
|
||||||
|
console.log("Error: unable to get " + url);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var content = JSON.parse(data.body);
|
||||||
|
if(!content || content.status != 'success') {
|
||||||
|
console.log("Error: unable to get " + url);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
console.log(content);
|
||||||
|
if(!content.total_entries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.callback(notifyType, true);
|
||||||
|
if(content.total_entries >= maxNotificationItemCount) {
|
||||||
|
var notification = new HifiNotification(notifyType, content.total_entries);
|
||||||
|
notification.show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var notifyData = []
|
||||||
|
switch(notifyType) {
|
||||||
|
case NotificationType.GOTO:
|
||||||
|
notifyData = content.user_stories;
|
||||||
|
break;
|
||||||
|
case NotificationType.PEOPLE:
|
||||||
|
notifyData = content.data.users;
|
||||||
|
break;
|
||||||
|
case NotificationType.WALLET:
|
||||||
|
notifyData = content.data.history;
|
||||||
|
break;
|
||||||
|
case NotificationType.MARKETPLACE:
|
||||||
|
notifyData = content.data.updates;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyData.forEach(function(data) {
|
||||||
|
var notification = new HifiNotification(notifyType, data);
|
||||||
|
notification.show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pollForStories: function(since, token) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var actions = 'announcement';
|
var actions = 'announcement';
|
||||||
var options = [
|
var options = [
|
||||||
'now=' + new Date().toISOString(),
|
'now=' + new Date().toISOString(),
|
||||||
'since=' + since.toISOString(),
|
'since=' + since.getTime() / 1000,
|
||||||
'include_actions=announcement',
|
'include_actions=announcement',
|
||||||
'restriction=open,hifi',
|
'restriction=open,hifi',
|
||||||
'require_online=true'
|
'require_online=true',
|
||||||
|
'per_page='+MAX_NOTIFICATION_ITEMS
|
||||||
];
|
];
|
||||||
console.log("Polling for stories");
|
console.log("Polling for stories");
|
||||||
var url = METAVERSE_SERVER_URL + STORIES_URL + '?' + options.join('&');
|
var url = METAVERSE_SERVER_URL + STORIES_URL + '?' + options.join('&');
|
||||||
|
console.log(url);
|
||||||
request({
|
request({
|
||||||
uri: url
|
uri: url
|
||||||
}, function (error, data) {
|
}, function (error, data) {
|
||||||
if (error || !data.body) {
|
_this._pollCommon(NotificationType.GOTO, error, data, since);
|
||||||
console.log("Error: unable to get " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var content = JSON.parse(data.body);
|
|
||||||
if(!content || content.status != 'success') {
|
|
||||||
console.log("Error: unable to get " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content.user_stories.forEach(function(story) {
|
|
||||||
var updated_at = new Date(story.updated_at);
|
|
||||||
if (updated_at < since) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(NotificationType.GOTO);
|
|
||||||
var notification = new HifiNotification(NotificationType.GOTO, story);
|
|
||||||
notification.show();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
pollForConnections: function(since, callback) {
|
pollForConnections: function(since, token) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var options = [
|
var options = [
|
||||||
'filter=connections',
|
'filter=connections',
|
||||||
'since=' + since.toISOString(),
|
'since=' + since.getTime() / 1000,
|
||||||
'status=online'
|
'status=online',
|
||||||
|
'page=1',
|
||||||
|
'per_page=' + MAX_NOTIFICATION_ITEMS
|
||||||
];
|
];
|
||||||
console.log("Polling for connections");
|
console.log("Polling for connections");
|
||||||
var url = METAVERSE_SERVER_URL + USERS_URL + '?' + options.join('&');
|
var url = METAVERSE_SERVER_URL + USERS_URL + '?' + options.join('&');
|
||||||
request({
|
console.log(url);
|
||||||
uri: url
|
request.get({
|
||||||
|
uri: url,
|
||||||
|
'auth': {
|
||||||
|
'bearer': token
|
||||||
|
}
|
||||||
}, function (error, data) {
|
}, function (error, data) {
|
||||||
if (error || !data.body) {
|
_this._pollCommon(NotificationType.PEOPLE, error, data, since);
|
||||||
console.log("Error: unable to get " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var content = JSON.parse(data.body);
|
|
||||||
if(!content || content.status != 'success') {
|
|
||||||
console.log("Error: unable to get " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(content.data);
|
|
||||||
content.data.users.forEach(function(user) {
|
|
||||||
if(user.online) {
|
|
||||||
callback(NotificationType.PEOPLE);
|
|
||||||
var notification = new HifiNotification(NotificationType.PEOPLE, user);
|
|
||||||
notification.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
pollForEconomicActivity: function(since, callback) {
|
pollForEconomicActivity: function(since, token) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var options = [
|
var options = [
|
||||||
'filter=connections',
|
'since=' + since.getTime() / 1000,
|
||||||
'since=' + since.toISOString(),
|
'page=1',
|
||||||
'status=online'
|
'per_page=' + 1000 // total_entries is incorrect for wallet queries if results
|
||||||
|
// aren't all on one page, so grab them all on a single page
|
||||||
|
// for now.
|
||||||
];
|
];
|
||||||
console.log("Polling for economic activity");
|
console.log("Polling for economic activity");
|
||||||
var url = METAVERSE_SERVER_URL + ECONOMIC_ACTIVITY_URL + '?' + options.join('&');
|
var url = METAVERSE_SERVER_URL + ECONOMIC_ACTIVITY_URL + '?' + options.join('&');
|
||||||
|
console.log(url);
|
||||||
request.post({
|
request.post({
|
||||||
uri: url
|
uri: url,
|
||||||
|
'auth': {
|
||||||
|
'bearer': token
|
||||||
|
}
|
||||||
}, function (error, data) {
|
}, function (error, data) {
|
||||||
if (error || !data.body) {
|
_this._pollCommon(NotificationType.WALLET, error, data, since);
|
||||||
console.log("Error " + error + ": unable to post " + url);
|
|
||||||
console.log(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var content = JSON.parse(data.body);
|
|
||||||
if(!content || content.status != 'success') {
|
|
||||||
console.log(data.body);
|
|
||||||
console.log("Error " + content.status + ": unable to post " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(content.data);
|
|
||||||
content.data.users.forEach(function(user) {
|
|
||||||
if(user.online) {
|
|
||||||
callback(NotificationType.PEOPLE);
|
|
||||||
var notification = new HifiNotification(NotificationType.PEOPLE, user);
|
|
||||||
notification.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
pollForMarketplaceUpdates: function(since, callback) {
|
pollForMarketplaceUpdates: function(since, token) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var options = [
|
var options = [
|
||||||
'filter=connections',
|
'since=' + since.getTime() / 1000,
|
||||||
'since=' + since.toISOString(),
|
'page=1',
|
||||||
'status=online'
|
'per_page=' + MAX_NOTIFICATION_ITEMS
|
||||||
];
|
];
|
||||||
console.log("Polling for marketplace update");
|
console.log("Polling for marketplace update");
|
||||||
var url = METAVERSE_SERVER_URL + UPDATES_URL + '?' + options.join('&');
|
var url = METAVERSE_SERVER_URL + UPDATES_URL + '?' + options.join('&');
|
||||||
|
console.log(url);
|
||||||
request.put({
|
request.put({
|
||||||
uri: url
|
uri: url,
|
||||||
|
'auth': {
|
||||||
|
'bearer': token
|
||||||
|
}
|
||||||
}, function (error, data) {
|
}, function (error, data) {
|
||||||
if (error || !data.body) {
|
_this._pollCommon(NotificationType.MARKETPLACE, error, data, since);
|
||||||
console.log("Error " + error + ": unable to put " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var content = JSON.parse(data.body);
|
|
||||||
if(!content || content.status != 'success') {
|
|
||||||
console.log(data.body);
|
|
||||||
console.log("Error " + content.status + ": unable to put " + url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content.data.users.forEach(function(user) {
|
|
||||||
if(user.online) {
|
|
||||||
callback(NotificationType.PEOPLE);
|
|
||||||
var notification = new HifiNotification(NotificationType.PEOPLE, user);
|
|
||||||
notification.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue