Fixed Twitter notifications

New: Twitter notifications now require a Twitter (see settings for details)

Closes #1049
This commit is contained in:
Mark McDowall 2016-01-06 22:32:12 -08:00
parent 7ca67fe57a
commit a96718f7b3
8 changed files with 65 additions and 32 deletions

View file

@ -2,5 +2,6 @@
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="file://$PROJECT_DIR$/System/Logs/Files/LogFileModel.js" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

3
src/UI/.idea/misc.xml generated
View file

@ -4,5 +4,4 @@
<option name="state" value="git@github.com:NzbDrone/NzbDrone.git" />
</component>
<component name="ProjectRootManager" version="2" />
</project>
</project>

View file

@ -1,3 +1,4 @@
var _ = require('underscore');
var vent = require('vent');
var Marionette = require('marionette');
var DeleteView = require('../Delete/NotificationDeleteView');
@ -86,10 +87,20 @@ var view = Marionette.ItemView.extend({
},
_onAuthorizeNotification : function() {
this.ui.indicator.show();
var self = this;
var callbackUrl = window.location.origin + '/oauth.html';
this.ui.indicator.show();
var promise = this.model.connectData(this.ui.authorizedNotificationButton.data('value') + '?callbackUrl=' + callbackUrl);
var fields = this.model.get('fields');
var consumerKeyObj = _.findWhere(fields, { name: 'ConsumerKey' });
var consumerSecretObj = _.findWhere(fields, { name: 'ConsumerSecret' });
var queryParams = {
callbackUrl: callbackUrl,
consumerKey: (consumerKeyObj ? consumerKeyObj.value : ''),
consumerSecret: (consumerSecretObj ? consumerSecretObj.value : '')
};
var promise = this.model.connectData(this.ui.authorizedNotificationButton.data('value'), queryParams);
promise.always(function() {
self.ui.indicator.hide();

View file

@ -4,14 +4,19 @@ var DeepModel = require('backbone.deepmodel');
var Messenger = require('../Shared/Messenger');
module.exports = DeepModel.extend({
connectData : function(action, initialQueryString) {
connectData : function(action, initialQueryParams) {
var self = this;
this.trigger('connect:sync');
var promise = $.Deferred();
var callAction = function(action) {
var callAction = function(action, queryParams) {
if (queryParams) {
action = action + '?' + $.param(queryParams, true);
}
var params = {
url : self.collection.url + '/connectData/' + action,
contentType : 'application/json',
@ -30,11 +35,20 @@ module.exports = DeepModel.extend({
{
window.open(response.url);
var selfWindow = window;
selfWindow.onCompleteOauth = function(query, callback) {
delete selfWindow.onCompleteOauth;
if (response.nextStep) {
callAction(response.nextStep + query);
var queryParams = {};
var splitQuery = query.substring(1).split('&');
_.each(splitQuery, function (param) {
var paramSplit = param.split('=');
queryParams[paramSplit[0]] = paramSplit[1];
});
callAction(response.nextStep, _.extend(initialQueryParams, queryParams));
}
else {
promise.resolve(response);
@ -59,7 +73,7 @@ module.exports = DeepModel.extend({
}
}
if (response.nextStep) {
callAction(response.nextStep);
callAction(response.nextStep, initialQueryParams);
}
else {
promise.resolve(response);
@ -67,7 +81,7 @@ module.exports = DeepModel.extend({
});
};
callAction(action, initialQueryString);
callAction(action, initialQueryParams);
Messenger.monitor({
promise : promise,

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>oauth landing page</title>
<script><!--
<script><!--
window.opener.onCompleteOauth(window.location.search, function() { window.close(); });
--></script>
</head>