From 3101e612273744573c719ff6b2c202a91416aabc Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Mon, 2 Nov 2015 12:42:58 -0800 Subject: [PATCH] front end PM glyph display --- .../js/components/MessagesComponent.coffee | 6 ++-- pub/talk/src/js/main.js | 28 +++++++++++++++---- pub/talk/src/js/util.coffee | 20 +++++++++---- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/pub/talk/src/js/components/MessagesComponent.coffee b/pub/talk/src/js/components/MessagesComponent.coffee index a976ba4048..f775649ce4 100644 --- a/pub/talk/src/js/components/MessagesComponent.coffee +++ b/pub/talk/src/js/components/MessagesComponent.coffee @@ -94,7 +94,7 @@ module.exports = recl stations:StationStore.getStations() configs:StationStore.getConfigs() typing:MessageStore.getTyping() - glyph:StationStore.getGlyphMap() + glyphs:StationStore.getGlyphMap() } getInitialState: -> @stateFromStore() @@ -198,10 +198,10 @@ module.exports = recl div {id: "messages"}, _messages.map (_message,k) => nowSaid = [_message.ship,_message.thought.audience] + glyph = window.util.getGlyph @state.glyphs, _.keys _message.thought.audience {station} = @state mess = { - station, @_handlePm, @_handleAudi, - glyph: @state.glyph[(_.keys _message.thought.audience).join " "] + glyph, station, @_handlePm, @_handleAudi, unseen: lastIndex and lastIndex is k sameAs: _.isEqual lastSaid, nowSaid } diff --git a/pub/talk/src/js/main.js b/pub/talk/src/js/main.js index 9d933b93d1..943d99c975 100644 --- a/pub/talk/src/js/main.js +++ b/pub/talk/src/js/main.js @@ -385,7 +385,7 @@ module.exports = recl({ stations: StationStore.getStations(), configs: StationStore.getConfigs(), typing: MessageStore.getTyping(), - glyph: StationStore.getGlyphMap() + glyphs: StationStore.getGlyphMap() }; }, getInitialState: function() { @@ -508,14 +508,15 @@ module.exports = recl({ id: "messages" }, _messages.map((function(_this) { return function(_message, k) { - var mess, nowSaid, ref4; + var glyph, mess, nowSaid, ref4; nowSaid = [_message.ship, _message.thought.audience]; + glyph = window.util.getGlyph(_this.state.glyphs, _.keys(_message.thought.audience)); station = _this.state.station; mess = { + glyph: glyph, station: station, _handlePm: _this._handlePm, _handleAudi: _this._handleAudi, - glyph: _this.state.glyph[(_.keys(_message.thought.audience)).join(" ")], unseen: lastIndex && lastIndex === k, sameAs: _.isEqual(lastSaid, nowSaid) }; @@ -6293,10 +6294,13 @@ if (!window.util) { _.merge(window.util, { mainStations: ["court", "floor", "porch"], mainStationPath: function(user) { + if (user == null) { + user = window.urb.user; + } return "~" + user + "/" + (window.util.mainStation(user)); }, mainStation: function(user) { - if (!user) { + if (user == null) { user = window.urb.user; } switch (user.length) { @@ -6308,10 +6312,22 @@ _.merge(window.util, { return "porch"; } }, + getGlyph: function(glyphs, audi) { + return glyphs[audi.join(" ")] || (function() { + switch (false) { + case !!_.contains(audi, window.util.mainStationPath()): + return "*"; + case audi.length !== 1: + return ":"; + default: + return ";"; + } + })(); + }, clipAudi: function(audi) { var ms, regx; audi = audi.join(" "); - ms = window.util.mainStationPath(window.urb.user); + ms = window.util.mainStationPath(); regx = new RegExp("/" + ms, "g"); audi = audi.replace(regx, ""); return audi.split(" "); @@ -6319,7 +6335,7 @@ _.merge(window.util, { expandAudi: function(audi) { var ms; audi = audi.join(" "); - ms = window.util.mainStationPath(window.urb.user); + ms = window.util.mainStationPath(); if (audi.indexOf(ms) === -1) { if (audi.length > 0) { audi += " "; diff --git a/pub/talk/src/js/util.coffee b/pub/talk/src/js/util.coffee index 23929aa24f..7841ab2fdf 100644 --- a/pub/talk/src/js/util.coffee +++ b/pub/talk/src/js/util.coffee @@ -2,10 +2,10 @@ if not window.util then window.util = {} _.merge window.util, mainStations: ["court","floor","porch"] - mainStationPath: (user) -> "~#{user}/#{window.util.mainStation(user)}" + mainStationPath: (user = window.urb.user) -> + "~#{user}/#{window.util.mainStation(user)}" - mainStation: (user) -> - if not user then user = window.urb.user + mainStation: (user = window.urb.user) -> switch user.length when 3 return "court" @@ -14,16 +14,24 @@ _.merge window.util, when 13 return "porch" + getGlyph: (glyphs, audi)-> + glyphs[audi.join " "] or switch + when not _.contains audi, window.util.mainStationPath() + "*" + when audi.length is 1 + ":" + else ";" + clipAudi: (audi) -> audi = audi.join " " - ms = window.util.mainStationPath window.urb.user + ms = window.util.mainStationPath() regx = new RegExp "/#{ms}","g" audi = audi.replace regx,"" audi.split " " expandAudi: (audi) -> audi = audi.join " " - ms = window.util.mainStationPath window.urb.user + ms = window.util.mainStationPath() if audi.indexOf(ms) is -1 if audi.length > 0 audi += " " @@ -82,4 +90,4 @@ _.merge window.util, if window.util.isScrolling() $('body').addClass 'scrolling' else - $('body').removeClass 'scrolling' \ No newline at end of file + $('body').removeClass 'scrolling'