@@ -112,7 +112,7 @@ var ChronicleScreen = (function() {
112112 feed . innerHTML = '<p class="empty-state">' + Helpers . t ( 'loading' ) + '</p>' ;
113113
114114 var state = StateEngine . getState ( ) ;
115- var entries = _collectStateEntries ( state ) ;
115+ var entries = _collectPostEntries ( state ) ;
116116 var accounts = _getFeedAccounts ( state ) ;
117117
118118 if ( ! accounts . length || typeof VoiceProtocol === 'undefined' || ! VoiceProtocol . loadChronicle ) {
@@ -207,18 +207,18 @@ var ChronicleScreen = (function() {
207207 } ;
208208 }
209209
210- function _collectStateEntries ( state ) {
210+ function _collectPostEntries ( state ) {
211211 var entries = [ ] ;
212212
213213 if ( state . recentActions ) {
214214 for ( var i = state . recentActions . length - 1 ; i >= 0 && entries . length < 50 ; i -- ) {
215215 var action = state . recentActions [ i ] ;
216- var narrative = _actionToNarrative ( action ) ;
217- if ( narrative && _entryMatchesRequiredTag ( action . type , narrative ) ) {
216+ var postText = _actionToPostText ( action ) ;
217+ if ( postText && _entryMatchesRequiredTag ( action . type , postText ) ) {
218218 entries . push ( {
219219 type : 'action' ,
220220 account : action . sender ,
221- text : narrative ,
221+ text : postText ,
222222 actionType : action . type ,
223223 timestamp : action . timestamp ,
224224 blockNum : action . blockNum
@@ -227,23 +227,6 @@ var ChronicleScreen = (function() {
227227 }
228228 }
229229
230- if ( state . duels && state . duels . history ) {
231- for ( var j = state . duels . history . length - 1 ; j >= 0 && entries . length < 50 ; j -- ) {
232- var duel = state . duels . history [ j ] ;
233- var duelNarrative = _duelToNarrative ( duel , state ) ;
234- if ( duelNarrative ) {
235- entries . push ( {
236- type : 'duel' ,
237- account : duel . winner || duel . challenger ,
238- text : duelNarrative ,
239- actionType : 'duel_completed' ,
240- timestamp : null ,
241- blockNum : duel . completedBlock
242- } ) ;
243- }
244- }
245- }
246-
247230 return entries ;
248231 }
249232
@@ -362,67 +345,9 @@ var ChronicleScreen = (function() {
362345 return true ;
363346 }
364347
365- function _actionToNarrative ( action ) {
366- var t = Helpers . t ;
367- var charInfo = StateEngine . getCharacter ( action . sender ) ;
368- var name = ( charInfo && charInfo . name ) || action . sender || '???' ;
369-
370- switch ( action . type ) {
371- case 'chronicle_post' :
372- return action . text || ( action . message && action . message . text ) || '' ;
373- case 'hunt' :
374- return t ( 'chronicle_narrative_hunt' , { name : name } ) ;
375- case 'hunt_victory' :
376- case 'hunt_defeat' :
377- if ( action . events && action . events [ 0 ] ) {
378- var creature = action . events [ 0 ] . creature || '' ;
379- if ( action . type === 'hunt_victory' ) {
380- return t ( 'chronicle_narrative_hunt_win' , { name : name , creature : creature } ) ;
381- } else {
382- return t ( 'chronicle_narrative_hunt_lose' , { name : name , creature : creature } ) ;
383- }
384- }
385- return t ( 'chronicle_narrative_hunt' , { name : name } ) ;
386- case 'character_created' :
387- return t ( 'chronicle_narrative_awaken' , { name : name } ) ;
388- case 'rest_complete' :
389- return t ( 'chronicle_narrative_rest' , { name : name } ) ;
390- case 'blessing_sent' :
391- if ( ! _isBlessAction ( action ) ) return null ;
392- return t ( 'chronicle_narrative_bless' , { name : name , target : action . receiver || '' } ) ;
393- default :
394- return null ;
395- }
396- }
397-
398- function _isBlessAction ( action ) {
399- if ( ! action ) return false ;
400- return action . type === 'blessing_sent' && action . memo && String ( action . memo ) . indexOf ( BLESS_MEMO_PREFIX ) === 0 ;
401- }
402-
403- function _duelToNarrative ( duel , state ) {
404- var t = Helpers . t ;
405- var charA = state . characters [ duel . challenger ] || { } ;
406- var charB = state . characters [ duel . target ] || { } ;
407- var nameA = charA . name || duel . challenger ;
408- var nameB = charB . name || duel . target ;
409-
410- if ( duel . forfeited ) {
411- return t ( 'chronicle_narrative_duel_forfeit' , { winner : duel . winner === duel . challenger ? nameA : nameB } ) ;
412- }
413-
414- if ( duel . winner ) {
415- var winnerName = duel . winner === duel . challenger ? nameA : nameB ;
416- var loserName = duel . winner === duel . challenger ? nameB : nameA ;
417- return t ( 'chronicle_narrative_duel_win' , {
418- winner : winnerName ,
419- loser : loserName ,
420- winsA : duel . winsA || 0 ,
421- winsB : duel . winsB || 0
422- } ) ;
423- }
424-
425- return t ( 'chronicle_narrative_duel_draw' , { nameA : nameA , nameB : nameB } ) ;
348+ function _actionToPostText ( action ) {
349+ if ( ! action || action . type !== 'chronicle_post' ) return null ;
350+ return action . text || ( action . message && action . message . text ) || '' ;
426351 }
427352
428353 function _filterByTab ( entries , state ) {
0 commit comments