@@ -49,8 +49,14 @@ function FlamebaseDatabase(database, path) {
4949 */
5050 this . syncFromDatabase = function ( ) {
5151 try {
52- console . log ( "####################### data path: " + path ) ;
52+ if ( this . debugVal ) {
53+ logger . debug ( "####################### data path: " + path ) ;
54+ }
5355 object . ref = object . db . getData ( path ) ;
56+ this . lastStringReference = JSON . stringify ( object . ref ) ;
57+ if ( this . debugVal ) {
58+ logger . debug ( "####################### ref: " + JSON . stringify ( object . ref ) ) ;
59+ }
5460 object . syncNotifications ( ) ;
5561 } catch ( e ) {
5662 console . log ( "####################### not found, generating {} " ) ;
@@ -179,6 +185,8 @@ function FlamebaseDatabase(database, path) {
179185 sen . notification = notification ;
180186 this . sendPushMessage ( sen ) ;
181187 }
188+ } else if ( this . debugVal ) {
189+ logger . debug ( "no differences located" ) ;
182190 }
183191 }
184192
@@ -211,6 +219,8 @@ function FlamebaseDatabase(database, path) {
211219 s . notification = notification ;
212220 this . sendPushMessage ( s ) ;
213221 }
222+ } else if ( this . debugVal ) {
223+ logger . debug ( "no differences located" ) ;
214224 }
215225 }
216226 } ;
@@ -250,20 +260,36 @@ function FlamebaseDatabase(database, path) {
250260 var notificationLength = JSON . stringify ( notification ) . length ;
251261
252262 var differences = JSON . stringify ( diff ( JSON . parse ( this . lastStringReference ) , this . ref ) ) ;
253- differences = this . string2Hex ( differences ) ;
254263 var partsToSend = [ ] ;
255- var limit = os . indexOf ( this . OS . IOS ) !== - 1 ? this . lengthLimit . IOS - notificationLength : this . lengthLimit . ANDROID - notificationLength ;
256- if ( differences . length > limit ) {
257- var index = - 1 ;
258- var pendingChars = differences . length ;
259- while ( pendingChars > 0 ) {
260- index ++ ;
261- var part = differences . slice ( index * limit , ( pendingChars < limit ? index * limit + pendingChars : ( index + 1 ) * limit ) ) ;
262- pendingChars = pendingChars - part . length ;
263- partsToSend . push ( part ) ;
264+
265+ if ( this . debugVal ) {
266+ logger . debug ( "diff: " + differences ) ;
267+ }
268+
269+ if ( differences === "false" ) {
270+ var currentStringRef = JSON . stringify ( this . ref ) ;
271+ if ( this . lastStringReference . length != currentStringRef . length ) {
272+ logger . error ( "something went wrong; chars diff: " + ( this . lastStringReference . length - currentStringRef . length ) ) ;
273+ }
274+ if ( this . debugVal ) {
275+ logger . debug ( "no differences" ) ;
264276 }
265277 } else {
266- partsToSend . push ( differences ) ;
278+ differences = this . string2Hex ( differences ) ;
279+
280+ var limit = os . indexOf ( this . OS . IOS ) !== - 1 ? this . lengthLimit . IOS - notificationLength : this . lengthLimit . ANDROID - notificationLength ;
281+ if ( differences . length > limit ) {
282+ var index = - 1 ;
283+ var pendingChars = differences . length ;
284+ while ( pendingChars > 0 ) {
285+ index ++ ;
286+ var part = differences . slice ( index * limit , ( pendingChars < limit ? index * limit + pendingChars : ( index + 1 ) * limit ) ) ;
287+ pendingChars = pendingChars - part . length ;
288+ partsToSend . push ( part ) ;
289+ }
290+ } else {
291+ partsToSend . push ( differences ) ;
292+ }
267293 }
268294
269295 var result = { } ;
0 commit comments