@@ -323,13 +323,15 @@ var GuildScreen = (function() {
323323 for ( var i = 0 ; i < guilds . length ; i ++ ) {
324324 var guild = guilds [ i ] ;
325325 if ( ! guild || ! guild . id ) continue ;
326+ _normalizeGuild ( guild ) ;
326327 if ( ! state . guilds [ guild . id ] || state . guilds [ guild . id ] . isPlaceholder ) {
327328 state . guilds [ guild . id ] = guild ;
328329 changed = true ;
329330 }
330331 }
331332 for ( var gid in guildMap ) {
332333 if ( ! guildMap . hasOwnProperty ( gid ) ) continue ;
334+ _normalizeGuild ( guildMap [ gid ] ) ;
333335 if ( ! state . guilds [ gid ] || state . guilds [ gid ] . isPlaceholder ) {
334336 state . guilds [ gid ] = guildMap [ gid ] ;
335337 changed = true ;
@@ -366,7 +368,7 @@ var GuildScreen = (function() {
366368 if ( err || ! directory ) return ;
367369 if ( _mergeArchiveGuildDirectory ( StateEngine . getState ( ) , directory ) ) {
368370 var container = Helpers . $ ( 'screen-guild' ) ;
369- if ( container && ! container . getAttribute ( 'aria-hidden' ) ) render ( ) ;
371+ if ( _isScreenVisible ( container ) ) render ( ) ;
370372 }
371373 } ) ;
372374 }
@@ -405,7 +407,7 @@ var GuildScreen = (function() {
405407 currentState . guilds [ guildId ] = guild ;
406408 // Re-render if guild screen is active
407409 var container = Helpers . $ ( 'screen-guild' ) ;
408- if ( container && ! container . getAttribute ( 'aria-hidden' ) ) {
410+ if ( _isScreenVisible ( container ) ) {
409411 render ( ) ;
410412 }
411413 }
@@ -427,6 +429,7 @@ var GuildScreen = (function() {
427429 if ( ! state . guilds ) return list ;
428430 for ( var gid in state . guilds ) {
429431 if ( state . guilds . hasOwnProperty ( gid ) ) {
432+ _normalizeGuild ( state . guilds [ gid ] ) ;
430433 list . push ( state . guilds [ gid ] ) ;
431434 }
432435 }
@@ -438,6 +441,27 @@ var GuildScreen = (function() {
438441 return list ;
439442 }
440443
444+ function _normalizeGuild ( guild ) {
445+ if ( ! guild ) return guild ;
446+ guild . charter = guild . charter || { } ;
447+ if ( ! guild . charter . membership ) guild . charter . membership = 'open' ;
448+ if ( typeof guild . charter . tithe_pct !== 'number' ) guild . charter . tithe_pct = 1000 ;
449+ if ( typeof guild . charter . min_shares !== 'number' ) guild . charter . min_shares = 0 ;
450+ guild . members = guild . members || { } ;
451+ guild . invites = guild . invites || { } ;
452+ guild . wars = guild . wars || [ ] ;
453+ guild . quests = guild . quests || [ ] ;
454+ guild . announcements = guild . announcements || [ ] ;
455+ if ( typeof guild . totalDelegated !== 'number' ) guild . totalDelegated = 0 ;
456+ if ( typeof guild . level !== 'number' ) guild . level = 1 ;
457+ if ( typeof guild . xp !== 'number' ) guild . xp = 0 ;
458+ return guild ;
459+ }
460+
461+ function _isScreenVisible ( container ) {
462+ return ! ! ( container && container . getAttribute ( 'aria-hidden' ) !== 'true' ) ;
463+ }
464+
441465 /**
442466 * Bind guild hall events
443467 */
@@ -920,7 +944,7 @@ var GuildScreen = (function() {
920944 Helpers . EventBus . on ( events [ i ] , function ( ) {
921945 // Re-render only if guild screen is currently visible
922946 var container = Helpers . $ ( 'screen-guild' ) ;
923- if ( container && ! container . getAttribute ( 'aria-hidden' ) ) {
947+ if ( _isScreenVisible ( container ) ) {
924948 render ( ) ;
925949 }
926950 } ) ;
0 commit comments