1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Tidy up twitter node, add status, i18n etc

This commit is contained in:
Dave Conway-Jones 2016-09-27 17:56:35 +01:00
parent b0c93e44b8
commit 4c5b75f30a
3 changed files with 37 additions and 32 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
Copyright 2013, 2015 IBM Corp. Copyright 2013, 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -186,8 +186,7 @@
$("#node-input-user").change(); $("#node-input-user").change();
}, },
oneditsave: function() { oneditsave: function() {
if ($('#node-input-tags').val() == '' && $("#node-input-user option:selected").val() != 'dm' if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() != 'dm' && $("#node-input-user option:selected").val() != 'user') {
&& $("#node-input-user option:selected").val() != 'user') {
this.inputs=1; this.inputs=1;
} }
else { else {

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013, 2015 IBM Corp. * Copyright 2013, 2016 IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -89,7 +89,8 @@ module.exports = function(RED) {
node.poll_ids = []; node.poll_ids = [];
node.since_ids = {}; node.since_ids = {};
var users = node.tags.split(","); var users = node.tags.split(",");
if (users == '') node.warn("User option selected but no users specified"); //if (users == '') node.warn("User option selected but no users specified");
if (users.length === 0) { node.warn(RED._("twitter.warn.nousers")); }
for (var i=0; i<users.length; i++) { for (var i=0; i<users.length; i++) {
var user = users[i].replace(" ",""); var user = users[i].replace(" ","");
twit.getUserTimeline({ twit.getUserTimeline({
@ -236,22 +237,23 @@ module.exports = function(RED) {
}); });
} }
} }
if (this.tags == '') if (this.tags === '') {
{ node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
this.warn("No search term(s) specified - add to node config or pass in through msg.payload"); }
else {
setupStream();
} }
else setupStream();
node.on("input", function(msg) { node.on("input", function(msg) {
if (this.tags == '') { if (this.tags === '') {
this.warn("Now searching for: " + msg.payload); if (this.stream) { this.stream.destroy(); }
if (this.stream) this.stream.destroy();
st = { track: [msg.payload] }; st = { track: [msg.payload] };
setupStream(); setupStream();
node.status({fill:"green", shape:"dot", text:msg.payload}); node.status({fill:"green", shape:"dot", text:msg.payload});
} }
//We shouldn't get into this state, but just incase, check for it //We shouldn't get into this state, but just incase, check for it
else { else {
this.warn("msg.payload passed in, but tag config is not blank, defaulting to tag config"); // node.warn("msg.payload passed in, but tag config is not blank, defaulting to tag config");
node.status({fill:"green", shape:"dot", text:node.tags});
} }
}); });
} }

View File

@ -25,9 +25,13 @@
"tweeting": "tweeting", "tweeting": "tweeting",
"failed":"failed" "failed":"failed"
}, },
"warn": {
"nousers":"User option selected but no users specified",
"waiting":"Waiting for search term"
},
"errors": { "errors": {
"ratelimit":"tweet rate limit hit", "ratelimit":"tweet rate limit hit",
"streamerror":"stream error: __error__ (__rc__)", "streamerror":"stream errosr: __error__ (__rc__)",
"unexpectedend":"stream ended unexpectedly", "unexpectedend":"stream ended unexpectedly",
"invalidtag":"invalid tag property", "invalidtag":"invalid tag property",
"missingcredentials":"missing twitter credentials", "missingcredentials":"missing twitter credentials",