Don't append channel to non-root posts

Problem: When publishing a root post, other clients give you the option
of adding a `channel` property, which is basically just a hashtag. We
show this at the end of the message, but since replies often copy the
`channel` property then it gets appended to every reply.

Solution: Only append the channel as a hashtag for root posts.
This commit is contained in:
Christian Bundy 2020-03-24 08:11:13 -07:00
parent 42e051fc6a
commit 1adbd15afd
2 changed files with 12 additions and 14 deletions

View File

@ -469,10 +469,17 @@ module.exports = ({ cooler, isPublic }) => {
} }
} }
const isPost =
lodash.get(msg, "value.content.type") === "post" &&
lodash.get(msg, "value.content.text", false) !== false;
const hasRoot = lodash.get(msg, "value.content.root", false) !== false;
const hasFork = lodash.get(msg, "value.content.fork", false) !== false;
const channel = lodash.get(msg, "value.content.channel"); const channel = lodash.get(msg, "value.content.channel");
const hasChannel = typeof channel === "string" && channel.length > 2; const hasChannel = typeof channel === "string" && channel.length > 2;
const isRoot = hasRoot === false;
if (hasChannel) { if (hasChannel && isRoot) {
msg.value.content.text += `\n\n#${channel}`; msg.value.content.text += `\n\n#${channel}`;
} }
@ -506,12 +513,6 @@ module.exports = ({ cooler, isPublic }) => {
url: avatarUrl, url: avatarUrl,
}); });
const isPost =
lodash.get(msg, "value.content.type") === "post" &&
lodash.get(msg, "value.content.text") != null;
const hasRoot = lodash.get(msg, "value.content.root") != null;
const hasFork = lodash.get(msg, "value.content.fork") != null;
if (isPost && hasRoot === false && hasFork === false) { if (isPost && hasRoot === false && hasFork === false) {
lodash.set(msg, "value.meta.postType", "post"); lodash.set(msg, "value.meta.postType", "post");
} else if (isPost && hasRoot && hasFork === false) { } else if (isPost && hasRoot && hasFork === false) {

View File

@ -77,7 +77,7 @@ const createConnection = (config) => {
lodash.get(ssbConfig, "friends.hops", 0) lodash.get(ssbConfig, "friends.hops", 0)
); );
const add = address => { const add = (address) => {
inProgress[address] = true; inProgress[address] = true;
return () => { return () => {
inProgress[address] = false; inProgress[address] = false;
@ -88,10 +88,10 @@ const createConnection = (config) => {
rawConnect() rawConnect()
.then((ssb) => { .then((ssb) => {
log("Retrying connection to own server"); log("Retrying connection to own server");
ssb.friends.hops().then(hops => { ssb.friends.hops().then((hops) => {
pull( pull(
ssb.conn.stagedPeers(), ssb.conn.stagedPeers(),
pull.drain(x => { pull.drain((x) => {
x.filter(([address, data]) => { x.filter(([address, data]) => {
const notInProgress = inProgress[address] !== true; const notInProgress = inProgress[address] !== true;
@ -110,10 +110,7 @@ const createConnection = (config) => {
hops[data.key] hops[data.key]
}/${maxHops} hops: ${address}` }/${maxHops} hops: ${address}`
); );
ssb.conn ssb.conn.connect(address, data).then(done).catch(done);
.connect(address, data)
.then(done)
.catch(done);
}); });
}) })
); );