Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…s up the server with duplicate clients
  • Loading branch information...
commit 06d999ffadccebe338c6776f458f70522a4ddd15 1 parent 86d0f70
Kyle Welsby authored
1  CHANGES
@@ -4,6 +4,7 @@ v1.2.1
4 4 * Added polling column to Devices that may require a Poll method instead of Push.
5 5 * UI updates
6 6 * Stopped the jumping into thread.
  7 +* Fixed getting client information from server.
7 8
8 9 v1.2.0
9 10 ----
58 javascripts/background.js
@@ -11,7 +11,7 @@ Background.init = function () {
11 11 try {
12 12 chrome.extension.onRequest.addListener(function (request, sender, callback) {
13 13 console.log("[Background.init.onRequest] Request received");
14   - if(callback){
  14 + if (callback) {
15 15 console.log("[Background.init.onRequest] with callback");
16 16 }
17 17 if (request.sync) {
@@ -33,6 +33,7 @@ Background.init = function () {
33 33 Background.notify.icon();
34 34 Background.onAuthenticated();
35 35 };
  36 +Background.failed = false;
36 37 Background.waitForAuth = function () {
37 38 if (Background.authenticated()) {
38 39 console.log("[Background.waitForAuth] Authenticated after waiting");
@@ -186,14 +187,15 @@ Background.Process.Post.messages = function () {
186 187 }
187 188 };
188 189 Background.Process.Post.client = function (callback) {
189   -
  190 + var unique_id = TxtVia.GenerateUniqueID();
190 191 if (Background.Process.lock === false && Background.authenticated()) {
191 192 $.ajax({
192 193 url: TxtVia.url + "/devices.json",
193 194 type: "POST",
194   - data: "unique_id=" + localStorage.UNIQUE_ID + "&type=client&name=" + encodeURIComponent(TxtVia.appName) + "&auth_token=" + localStorage.authToken,
  195 + data: "unique_id=" + unique_id + "&type=client&name=" + encodeURIComponent(TxtVia.appName) + "&auth_token=" + localStorage.authToken,
195 196 beforeSent: function () {
196 197 Background.Process.lock = true;
  198 + localStorage.UNIQUE_ID = unique_id;
197 199 },
198 200 success: function (data) {
199 201 localStorage.clientId = data.id;
@@ -312,25 +314,27 @@ Background.Process.Poll.messages = function () {
312 314 }
313 315 };
314 316 Background.Process.Get.device = function () {
315   - $.ajax({
316   - url: TxtVia.url + "/devices/" + localStorage.UNIQUE_ID + ".json",
317   - type: "GET",
318   - success: function (data) {
319   - console.log(data);
320   - if(data){
321   - localStorage.clientId = data.id;
322   - Background.notify.client.restored(data);
323   - chrome.extension.sendRequest({
324   - device: data
325   - }, function () {
326   - console.log("[Background.Process.Get.device] sent to display");
327   - });
  317 + if (Background.authenticated()) {
  318 + $.ajax({
  319 + url: TxtVia.url + "/devices/" + localStorage.UNIQUE_ID + ".json?auth_token=" + localStorage.authToken + "&type=client",
  320 + type: "GET",
  321 + success: function (data) {
  322 + console.log(data);
  323 + if (data) {
  324 + localStorage.clientId = data.id;
  325 + Background.notify.client.restored(data);
  326 + chrome.extension.sendRequest({
  327 + device: data
  328 + }, function () {
  329 + console.log("[Background.Process.Get.device] sent to display");
  330 + });
  331 + }
  332 + },
  333 + error: function (e) {
  334 + console.log("[Background.Process.Get.device] failed : " + e.responseText);
328 335 }
329   - },
330   - error: function (e) {
331   - console.log("[Background.Process.Get.device] failed : " + e.responseText);
332   - }
333   - });
  336 + });
  337 + }
334 338 };
335 339 Background.Process.fullDownload = function (callback) {
336 340 Background.Process.completed = 0;
@@ -344,7 +348,7 @@ Background.Process.onDevices = function (callback) {
344 348 var silence = false;
345 349 if (r.rows.length > 0) {
346 350 console.log(r.rows.length);
347   - if(r.rows.length === 1 && r.rows.item(0).device_type === "client"){
  351 + if (r.rows.length === 1 && r.rows.item(0).device_type === "client") {
348 352 silence = true;
349 353 }
350 354 if (!callback && !silence) {
@@ -464,9 +468,10 @@ Background.notify.client.failed = function (status) {
464 468 break;
465 469 default:
466 470 action = function () {
467   - Background.Process.Post.client();
  471 + // Background.Process.Post.client();
  472 + window.location.reload();
468 473 };
469   - message = "Failed to successfully setup client with TxtVia.\n\r Click here to try again.";
  474 + message = "Failed to successfully setup client with TxtVia.\n\r Click here to reload TxtVia.";
470 475 break;
471 476 }
472 477 notification = webkitNotifications.createNotification(chrome.extension.getURL('/images/failed.png'), "Awe damn", message);
@@ -475,7 +480,10 @@ Background.notify.client.failed = function (status) {
475 480 notification.cancel();
476 481 };
477 482 console.log(notification);
478   - notification.show();
  483 + if (Background.failed === false) {
  484 + Background.failed = true;
  485 + notification.show();
  486 + }
479 487 };
480 488 Background.notify.message = {};
481 489 Background.notify.message.sent = function (message) {
2  javascripts/popup.js
@@ -243,7 +243,7 @@ var PopUp = (function () {
243 243 thread: function (conversation, callback) {
244 244 console.log(conversation);
245 245 PopUp.currentThread = conversation.recipient;
246   - var header, avatar, currentThread;
  246 + var header, avatar, currentThread, img;
247 247 header = $("<h3>", {
248 248 text: conversation.name ? conversation.name : conversation.recipient
249 249 });
6 javascripts/storage.js
@@ -70,7 +70,7 @@ TxtVia.WebDB.insertInto.messages = function (message, callback) {
70 70 TxtVia.WebDB.insertInto.devices = function (device, callback) {
71 71 TxtVia.WebDB.db.transaction(function (tx) {
72 72 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);
73   - if(device.device_type === "hashblue"){
  73 + if (device.device_type === "hashblue") {
74 74 localStorage.pollForMessages = true;
75 75 }
76 76 });
@@ -176,7 +176,7 @@ TxtVia.Storage = function () {
176 176 }
177 177 }
178 178 if (!localStorage.UNIQUE_ID) {
179   - localStorage.UNIQUE_ID = $.sha256(TxtVia.appType + ":" + TxtVia.appID + ":" + today.getDate() + "-" + today.getMonth() + "-" + today.getYear() + "_" + today.getTime());
  179 + localStorage.UNIQUE_ID = TxtVia.GenerateUniqueID();
180 180 }
181 181 if (!localStorage.unReadMessages) {
182 182 localStorage.unReadMessages = 0;
@@ -211,7 +211,7 @@ TxtVia.Storage = function () {
211 211 if (!localStorage.enableSounds) {
212 212 localStorage.enableSounds = true;
213 213 }
214   - if (!localStorage.pollForMessages){
  214 + if (!localStorage.pollForMessages) {
215 215 localStorage.pollForMessages = false;
216 216 }
217 217 if (!localStorage.newMessageSound) {
4 javascripts/txtvia.js
@@ -69,6 +69,10 @@ TxtVia.uriParams = function (name) {
69 69 return null;
70 70 }
71 71 };
  72 +TxtVia.GenerateUniqueID = function () {
  73 + var today = new Date();
  74 + return $.sha256(TxtVia.appType + ":" + TxtVia.appID + ":" + today.getDate() + "-" + today.getMonth() + "-" + today.getYear() + "_" + today.getTime());
  75 +};
72 76 TxtVia.TextUtil = {};
73 77 TxtVia.TextUtil.mobileNumber = function (number) {
74 78 try {

0 comments on commit 06d999f

Please sign in to comment.
Something went wrong with that request. Please try again.