fix talk frontend display of posts and comments

urbit/talk@da2a800
This commit is contained in:
Anton Dyudin 2017-01-09 13:43:02 -08:00
parent c5e7c7cc33
commit 36eacf4a30

View File

@ -201,13 +201,6 @@ Persistence = _persistence({
type: "station-listen"
};
}),
createStation: function(station) {
Dispatcher.handleViewAction({
station: station,
type: "station-create"
});
return Persistence.createStation(station);
},
listen: function() {
return Persistence.listen();
},
@ -224,8 +217,12 @@ Persistence = _persistence({
'cabal': 'cabal'
});
},
createStation: function(name) {
return Persistence.createStation(name);
createStation: function(station) {
Dispatcher.handleViewAction({
station: station,
type: "station-create"
});
return Persistence.createStation(station);
},
setSources: function(station, sources) {
return Persistence.setSources(station, window.urb.ship, sources);
@ -305,7 +302,7 @@ module.exports = recl({
},{}],5:[function(require,module,exports){
var Member, a, clas, div, h2, h3, label, pre, recl, ref, util,
var Member, a, clas, div, h2, h3, label, pre, recl, ref, rele, util,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
util = require('../util.coffee');
@ -314,6 +311,8 @@ clas = require('classnames');
recl = React.createClass;
rele = React.createElement;
ref = React.DOM, div = ref.div, pre = ref.pre, a = ref.a, label = ref.label, h2 = ref.h2, h3 = ref.h3;
Member = require('./MemberComponent.coffee');
@ -356,9 +355,16 @@ module.exports = recl({
}
return this.props._handlePm(user);
},
abbreviate: function(s) {
if (s.length <= 80) {
return s;
} else {
return (s.slice(0, 77)) + "...";
}
},
renderSpeech: function(arg) {
var app, com, exp, fat, lin, mor, tax, url, x;
lin = arg.lin, app = arg.app, exp = arg.exp, tax = arg.tax, url = arg.url, mor = arg.mor, fat = arg.fat, com = arg.com;
var app, comment, exp, fat, lin, mor, post, tax, url, x;
lin = arg.lin, app = arg.app, exp = arg.exp, tax = arg.tax, url = arg.url, mor = arg.mor, fat = arg.fat, comment = arg.comment, post = arg.post;
switch (false) {
case !(lin || app || exp || tax):
return (lin || app || exp || tax).txt;
@ -368,11 +374,14 @@ module.exports = recl({
target: "_blank",
key: "speech"
}, url.txt);
case !com:
return div({}, com.txt, div({}, a({
className: "btn",
href: com.url
}, "Go to thread")));
case !comment:
return div({}, a({
href: comment.url
}, this.abbreviate(comment.txt)));
case !post:
return div({}, a({
href: post.url
}, post.title));
case !mor:
return mor.map(this.renderSpeech);
case !fat:
@ -432,13 +441,13 @@ module.exports = recl({
}
},
render: function() {
var aude, audi, bouquet, className, comment, delivery, k, mainStation, name, path, ref1, speech, style, thought, txt, type, url, v;
var aude, audi, bouquet, className, comment, delivery, glyph, k, mainStation, name, path, post, ref1, ref2, speech, style, thought, title, txt, type, url, v;
thought = this.props.thought;
delivery = _.uniq(_.pluck(thought.audience, "delivery"));
speech = thought.statement.speech;
bouquet = thought.statement.bouquet;
if (speech == null) {
return;
return null;
}
name = this.props.name ? this.props.name : "";
aude = _.keys(thought.audience);
@ -466,21 +475,47 @@ module.exports = recl({
href: url
}, path);
speech = {
com: {
comment: {
txt: txt,
url: url
}
};
}
className = clas('gram', (this.props.sameAs ? "same" : "first"), (delivery.indexOf("received") !== -1 ? "received" : "pending"), {
if (_.filter(bouquet, ["fora-post"]).length > 0) {
post = true;
ref2 = speech.mor;
for (k in ref2) {
v = ref2[k];
if (v.fat) {
url = v.fat.taf.url.txt;
txt = v.fat.tor.text;
}
if (v.app) {
title = v.app.txt.replace("forum post: ", "");
}
}
audi = a({
href: url
}, title);
speech = {
post: {
txt: txt,
url: url,
title: title
}
};
}
className = clas('gram', (this.props.sameAs ? "same" : "first"), ((indexOf.call(delivery, "received") >= 0) ? "received" : "pending"), {
'new': this.props.unseen
}, {
comment: comment
comment: comment,
post: post
}, this.classesInSpeech(speech));
style = {
height: this.props.height,
marginTop: this.props.marginTop
};
glyph = this.props.glyph || "*";
return div({
className: className,
'data-index': this.props.index,
@ -491,12 +526,12 @@ module.exports = recl({
key: "meta"
}, label({
className: "type " + type,
"data-glyph": this.props.glyph || "*"
"data-glyph": glyph
}), h2({
className: 'author planet',
onClick: this._handlePm,
key: "member"
}, React.createElement(Member, {
}, rele(Member, {
ship: this.props.ship,
glyph: this.props.glyph,
key: "member"
@ -613,12 +648,10 @@ module.exports = recl({
sortedMessages: function(messages) {
var station;
station = this.state.station;
return _.sortBy(messages, (function(_this) {
return function(message) {
message.pending = message.thought.audience[station];
return message.key;
};
})(this));
return _.sortBy(messages, function(message) {
message.pending = message.thought.audience[station];
return message.key;
});
},
componentWillMount: function() {
return Infinite = window.Infinite;
@ -718,16 +751,20 @@ module.exports = recl({
sameAs = _.isEqual(lastSaid, nowSaid);
lastSaid = nowSaid;
lineNums = 1;
speechArr = [];
context.font = FONT_SIZE + 'px bau';
if (message.thought.statement.speech.lin != null) {
speechArr = message.thought.statement.speech.lin.txt.split(/(\s|-)/);
} else if (message.thought.statement.speech.url != null) {
speechArr = message.thought.statement.speech.url.txt.split(/(\s|-)/);
} else if (message.thought.statement.speech.fat != null) {
context.font = (FONT_SIZE * 0.9) + 'px scp';
speechArr = message.thought.statement.speech.fat.taf.exp.txt.split(/(\s|-)/);
}
speech = message.thought.statement.speech;
context.font = speech.fat == null ? (FONT_SIZE * 0.9) + 'px scp' : FONT_SIZE + 'px bau';
speechArr = (function() {
switch (false) {
case speech.lin == null:
return speechArr = speech.lin.txt.split(/(\s|-)/);
case speech.url == null:
return speechArr = speech.url.txt.split(/(\s|-)/);
case speech.fat == null:
return speech.fat.taf.exp.txt.split(/(\s|-)/);
default:
return [];
}
})();
_.reduce(_.tail(speechArr), function(base, word) {
if (context.measureText(base + word).width > speechLength) {
lineNums += 1;
@ -754,7 +791,6 @@ module.exports = recl({
height = null;
marginTop = null;
}
speech = message.thought.statement.speech;
audience = (_.keys(message.thought.audience)).join(" ");
mez = rele(Message, _.extend({}, message, {
station: station,
@ -856,7 +892,7 @@ module.exports = recl({
return this.setState(this.stateFromStore());
},
componentWillReceiveProps: function(nextProps) {
if (this.props.open === true && nextProps.open === false) {
if (this.props.open && nextProps.open === false) {
return this.setState({
open: null
});
@ -1064,7 +1100,7 @@ Audience = recl({
}
},
_autoCompleteAudience: function() {
var aud, g, i, j, len, len1, ref1, ref2, s, stations, txt;
var aud, g, i, j, len, len1, modulo, ref1, ref2, s, stations, txt;
txt = $('#audience .input').text().trim();
if (this.tabAudList == null) {
this.tabAudList = [];
@ -1097,7 +1133,10 @@ Audience = recl({
} else {
this.tabAudIndex++;
}
this.tabAudIndex = (this.tabAudIndex % this.tabAudList.length + this.tabAudList.length) % this.tabAudList.length;
modulo = function(a, b) {
return ((a % b) + a) % b;
};
this.tabAudIndex = modulo(this.tabAudIndex, this.tabAudList.length);
} else {
this.tabAudIndex = 0;
}
@ -1251,7 +1290,7 @@ module.exports = recl({
return this.set();
},
_autoComplete: function() {
var i, msg, name, obj, ptxt, ref1, ref2, tindex, txt;
var i, modulo, msg, name, obj, ptxt, ref1, ref2, tindex, txt;
txt = this.$message.text();
tindex = txt.lastIndexOf('~');
if (tindex === -1) {
@ -1281,7 +1320,10 @@ module.exports = recl({
} else {
this.tabIndex++;
}
this.tabIndex = (this.tabIndex % this.tabList.length + this.tabList.length) % this.tabList.length;
modulo = function(a, b) {
return ((a % b) + a) % b;
};
this.tabIndex = modulo(this.tabIndex, this.tabList.length);
} else {
this.tabIndex = 0;
}
@ -1785,13 +1827,14 @@ MessageStore = _.merge(new EventEmitter, {
}
},
convertDate: function(time) {
var d;
var date, t;
time = time.substr(1).split(".");
time[1] = this.leadingZero(time[1]);
time[2] = this.leadingZero(time[2]);
d = new moment(time[0] + "-" + time[1] + "-" + time[2] + "T" + time[4] + ":" + time[5] + ":" + time[6] + "Z");
d.tz("Europe/London");
return d;
t = time;
date = new moment(t[0] + "-" + t[1] + "-" + t[2] + "T" + t[4] + ":" + t[5] + ":" + t[6] + "Z");
date.tz("Europe/London");
return date;
},
getListening: function() {
return _listening;
@ -1804,8 +1847,10 @@ MessageStore = _.merge(new EventEmitter, {
if (_.keys(_messages).length === 0) {
return [];
}
messages = _.sortBy(_messages, function(_message) {
return _message.thought.statement.time;
messages = _.sortBy(_messages, function(arg) {
var time;
time = arg.thought.statement.time;
return time;
});
return _.keys(messages[messages.length - 1].thought.audience);
},
@ -2125,7 +2170,7 @@ module.exports = util = {
var station;
if (document.location.search) {
station = document.location.search.replace(/^\?/, '');
if (station.indexOf('dbg.nopack') !== -1) {
if (station.indexOf('dbg.') !== -1) {
return station = util.mainStation();
}
} else {