Browse files

something to do with the client ID registration. althogh it could mes…

…s up the server with duplicate clients
  • Loading branch information...
1 parent 86d0f70 commit 06d999ffadccebe338c6776f458f70522a4ddd15 @kylewelsby committed Oct 10, 2011
Showing with 42 additions and 29 deletions.
  1. +1 −0 CHANGES
  2. +33 −25 javascripts/background.js
  3. +1 −1 javascripts/popup.js
  4. +3 −3 javascripts/storage.js
  5. +4 −0 javascripts/txtvia.js
View
1 CHANGES
@@ -4,6 +4,7 @@ v1.2.1
* Added polling column to Devices that may require a Poll method instead of Push.
* UI updates
* Stopped the jumping into thread.
+* Fixed getting client information from server.
v1.2.0
----
View
58 javascripts/background.js
@@ -11,7 +11,7 @@ Background.init = function () {
try {
chrome.extension.onRequest.addListener(function (request, sender, callback) {
console.log("[Background.init.onRequest] Request received");
- if(callback){
+ if (callback) {
console.log("[Background.init.onRequest] with callback");
}
if (request.sync) {
@@ -33,6 +33,7 @@ Background.init = function () {
Background.notify.icon();
Background.onAuthenticated();
};
+Background.failed = false;
Background.waitForAuth = function () {
if (Background.authenticated()) {
console.log("[Background.waitForAuth] Authenticated after waiting");
@@ -186,14 +187,15 @@ Background.Process.Post.messages = function () {
}
};
Background.Process.Post.client = function (callback) {
-
+ var unique_id = TxtVia.GenerateUniqueID();
if (Background.Process.lock === false && Background.authenticated()) {
$.ajax({
url: TxtVia.url + "/devices.json",
type: "POST",
- data: "unique_id=" + localStorage.UNIQUE_ID + "&type=client&name=" + encodeURIComponent(TxtVia.appName) + "&auth_token=" + localStorage.authToken,
+ data: "unique_id=" + unique_id + "&type=client&name=" + encodeURIComponent(TxtVia.appName) + "&auth_token=" + localStorage.authToken,
beforeSent: function () {
Background.Process.lock = true;
+ localStorage.UNIQUE_ID = unique_id;
},
success: function (data) {
localStorage.clientId = data.id;
@@ -312,25 +314,27 @@ Background.Process.Poll.messages = function () {
}
};
Background.Process.Get.device = function () {
- $.ajax({
- url: TxtVia.url + "/devices/" + localStorage.UNIQUE_ID + ".json",
- type: "GET",
- success: function (data) {
- console.log(data);
- if(data){
- localStorage.clientId = data.id;
- Background.notify.client.restored(data);
- chrome.extension.sendRequest({
- device: data
- }, function () {
- console.log("[Background.Process.Get.device] sent to display");
- });
+ if (Background.authenticated()) {
+ $.ajax({
+ url: TxtVia.url + "/devices/" + localStorage.UNIQUE_ID + ".json?auth_token=" + localStorage.authToken + "&type=client",
+ type: "GET",
+ success: function (data) {
+ console.log(data);
+ if (data) {
+ localStorage.clientId = data.id;
+ Background.notify.client.restored(data);
+ chrome.extension.sendRequest({
+ device: data
+ }, function () {
+ console.log("[Background.Process.Get.device] sent to display");
+ });
+ }
+ },
+ error: function (e) {
+ console.log("[Background.Process.Get.device] failed : " + e.responseText);
}
- },
- error: function (e) {
- console.log("[Background.Process.Get.device] failed : " + e.responseText);
- }
- });
+ });
+ }
};
Background.Process.fullDownload = function (callback) {
Background.Process.completed = 0;
@@ -344,7 +348,7 @@ Background.Process.onDevices = function (callback) {
var silence = false;
if (r.rows.length > 0) {
console.log(r.rows.length);
- if(r.rows.length === 1 && r.rows.item(0).device_type === "client"){
+ if (r.rows.length === 1 && r.rows.item(0).device_type === "client") {
silence = true;
}
if (!callback && !silence) {
@@ -464,9 +468,10 @@ Background.notify.client.failed = function (status) {
break;
default:
action = function () {
- Background.Process.Post.client();
+ // Background.Process.Post.client();
+ window.location.reload();
};
- message = "Failed to successfully setup client with TxtVia.\n\r Click here to try again.";
+ message = "Failed to successfully setup client with TxtVia.\n\r Click here to reload TxtVia.";
break;
}
notification = webkitNotifications.createNotification(chrome.extension.getURL('/images/failed.png'), "Awe damn", message);
@@ -475,7 +480,10 @@ Background.notify.client.failed = function (status) {
notification.cancel();
};
console.log(notification);
- notification.show();
+ if (Background.failed === false) {
+ Background.failed = true;
+ notification.show();
+ }
};
Background.notify.message = {};
Background.notify.message.sent = function (message) {
View
2 javascripts/popup.js
@@ -243,7 +243,7 @@ var PopUp = (function () {
thread: function (conversation, callback) {
console.log(conversation);
PopUp.currentThread = conversation.recipient;
- var header, avatar, currentThread;
+ var header, avatar, currentThread, img;
header = $("<h3>", {
text: conversation.name ? conversation.name : conversation.recipient
});
View
6 javascripts/storage.js
@@ -70,7 +70,7 @@ TxtVia.WebDB.insertInto.messages = function (message, callback) {
TxtVia.WebDB.insertInto.devices = function (device, callback) {
TxtVia.WebDB.db.transaction(function (tx) {
tx.executeSql('INSERT INTO devices(name, device_id, device_type, carrier, unique_id) VALUES (?,?,?,?,?)', [device.name, device.id, device.device_type, device.carrier, device.unique_id], callback, TxtVia.WebDB.onError);
- if(device.device_type === "hashblue"){
+ if (device.device_type === "hashblue") {
localStorage.pollForMessages = true;
}
});
@@ -176,7 +176,7 @@ TxtVia.Storage = function () {
}
}
if (!localStorage.UNIQUE_ID) {
- localStorage.UNIQUE_ID = $.sha256(TxtVia.appType + ":" + TxtVia.appID + ":" + today.getDate() + "-" + today.getMonth() + "-" + today.getYear() + "_" + today.getTime());
+ localStorage.UNIQUE_ID = TxtVia.GenerateUniqueID();
}
if (!localStorage.unReadMessages) {
localStorage.unReadMessages = 0;
@@ -211,7 +211,7 @@ TxtVia.Storage = function () {
if (!localStorage.enableSounds) {
localStorage.enableSounds = true;
}
- if (!localStorage.pollForMessages){
+ if (!localStorage.pollForMessages) {
localStorage.pollForMessages = false;
}
if (!localStorage.newMessageSound) {
View
4 javascripts/txtvia.js
@@ -69,6 +69,10 @@ TxtVia.uriParams = function (name) {
return null;
}
};
+TxtVia.GenerateUniqueID = function () {
+ var today = new Date();
+ return $.sha256(TxtVia.appType + ":" + TxtVia.appID + ":" + today.getDate() + "-" + today.getMonth() + "-" + today.getYear() + "_" + today.getTime());
+};
TxtVia.TextUtil = {};
TxtVia.TextUtil.mobileNumber = function (number) {
try {

0 comments on commit 06d999f

Please sign in to comment.