Skip to content

Commit

Permalink
removed unused social code
Browse files Browse the repository at this point in the history
  • Loading branch information
ballPointPenguin committed Nov 27, 2024
1 parent 59c72ae commit 604ae7c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 192 deletions.
115 changes: 5 additions & 110 deletions server/src/comment.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import _ from "underscore";
import fs from "fs";
import Translate from "@google-cloud/translate";

import pg from "./db/pg-query";
import SQL from "./db/sql";
import { MPromise } from "./utils/metered";
import Utils from "./utils/common";
import logger from "./utils/logger";

import Config from "./config";
import Conversation from "./conversation";
import User from "./user";
import { CommentType } from "./d";

// TODO should this be a number instead?
Expand All @@ -29,22 +26,6 @@ type Docs = {
rows: Row[];
};

type InfoToReturn = {
uid?: string | number;
followers_count?: any;
fb_user_id?: any;
fb_verified?: any;
fb_public_profile?: string;
fb_picture?: any;
tw_verified?: any;
tw_followers_count?: any;
verified?: any;
};

type UidToSocialInfo = {
[key: string]: any;
};

const useTranslateApi: boolean = Config.shouldUseTranslationAPI;
const translateClient = useTranslateApi ? Translate() : null;

Expand All @@ -71,11 +52,9 @@ function getComments(o: CommentType) {
? _getCommentsForModerationList(o)
: _getCommentsList(o);
let convPromise = Conversation.getConversationInfo(o.zid);
let conv: { is_anon: any } | null = null;
return Promise.all([convPromise, commentListPromise])
.then(function (a) {
let rows = a[1];
conv = a[0];
let cols = [
"txt",
"tid",
Expand Down Expand Up @@ -108,87 +87,6 @@ function getComments(o: CommentType) {
});
return rows;
})
.then(function (comments) {
let include_social = !conv?.is_anon && o.include_social;

if (include_social) {
let nonAnonComments = comments.filter(function (c: {
anon: any;
is_seed: any;
}) {
return !c.anon && !c.is_seed;
});
let uids = _.pluck(nonAnonComments, "uid");
return User.getSocialInfoForUsers(uids, o.zid).then(function (
socialInfos: any[]
) {
let uidToSocialInfo: UidToSocialInfo = {};
socialInfos.forEach(function (info: {
verified: any;
followers_count: any;
fb_public_profile: string;
uid: string | number;
}) {
// whitelist properties to send
let infoToReturn: InfoToReturn = _.pick(info, [
// fb
"fb_name",
"fb_link",
"fb_user_id",
// twitter
"name",
"screen_name",
"twitter_user_id",
"profile_image_url_https",
"followers_count",
// xInfo
"x_profile_image_url",
"x_name",
]);
infoToReturn.tw_verified = !!info.verified;
infoToReturn.tw_followers_count = info.followers_count;

// extract props from fb_public_profile
if (info.fb_public_profile) {
try {
let temp = JSON.parse(info.fb_public_profile);
infoToReturn.fb_verified = temp.verified;
} catch (err) {
logger.error(
"error parsing JSON of fb_public_profile for uid: " +
info.uid,
err
);
}
}

if (!_.isUndefined(infoToReturn.fb_user_id)) {
let width = 40;
let height = 40;
infoToReturn.fb_picture = `https://graph.facebook.com/v2.2/${infoToReturn.fb_user_id}/picture?width=${width}&height=${height}`;
}

uidToSocialInfo[info.uid] = infoToReturn;
});
return comments.map(function (c: {
uid: string | number;
anon: any;
social: any;
}) {
let s = uidToSocialInfo[c.uid];
if (s) {
if (!c.anon) {
// s should be undefined in this case, but adding a double-check here in case.
c.social = s;
}
}
return c;
});
});
} else {
return comments;
}
})
.then(function (comments) {
comments.forEach(function (c: { uid: any; anon: any }) {
delete c.uid;
Expand All @@ -214,7 +112,7 @@ function _getCommentsForModerationList(o: {
.queryP("select strict_moderation from conversations where zid = ($1);", [
o.zid,
])
.then((c: any) => {
.then(() => {
return o.strict_moderation;
});
}
Expand Down Expand Up @@ -341,14 +239,11 @@ function _getCommentsList(o: {
if (!_.isUndefined(o.withoutTids)) {
q = q.and(SQL.sql_comments.tid.notIn(o.withoutTids));
}
if (o.moderation) {
q = q.and(SQL.sql_comments.active.equals(true));
if (conv.strict_moderation) {
q = q.and(SQL.sql_comments.mod.equals(Utils.polisTypes.mod.ok));
} else {
q = q.and(SQL.sql_comments.active.equals(true));
if (conv.strict_moderation) {
q = q.and(SQL.sql_comments.mod.equals(Utils.polisTypes.mod.ok));
} else {
q = q.and(SQL.sql_comments.mod.notEquals(Utils.polisTypes.mod.ban));
}
q = q.and(SQL.sql_comments.mod.notEquals(Utils.polisTypes.mod.ban));
}

q = q.and(SQL.sql_comments.velocity.gt(0)); // filter muted comments
Expand Down
51 changes: 1 addition & 50 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,36 +659,10 @@ function initializePolisHelpers() {
if (!rows || !rows.length) {
throw "polis_err_unknown_conversation";
}
let conv = rows[0];
const conv = rows[0];
if (!conv.is_active) {
throw "polis_err_conversation_is_closed";
}
// if (conv.auth_needed_to_vote) {
// return isModerator(zid, uid).then((is_mod: any) => {
// if (is_mod) {
// return conv;
// }
// return Promise.all([
// pgQueryP(
// "select * from xids where owner = ($1) and uid = ($2);",
// [conv.owner, uid]
// ),
// getSocialInfoForUsers([uid], zid),
// // Binding elements 'xids' and 'info' implicitly have an 'any' type.ts(7031)
// // @ts-ignore
// ]).then(([xids, info]) => {
// var socialAccountIsLinked = info.length > 0;
// // Object is of type 'unknown'.ts(2571)
// // @ts-ignore
// var hasXid = xids.length > 0;
// if (socialAccountIsLinked || hasXid) {
// return conv;
// } else {
// throw "polis_err_post_votes_social_needed";
// }
// });
// });
// }
if (conv.use_xid_whitelist) {
return isXidWhitelisted(conv.owner, xid).then(
(is_whitelisted: boolean) => {
Expand Down Expand Up @@ -10840,29 +10814,6 @@ Thanks for using Polis!
});
}

// function getFacebookFriendsInConversation(zid, uid) {
// if (!uid) {
// return Promise.resolve([]);
// }
// let p = pgQueryP_readOnly(
// "select * from " +
// "(select * from " +
// "(select * from " +
// "(select friend as uid from facebook_friends where uid = ($2) union select uid from facebook_friends where friend = ($2) union select uid from facebook_users where uid = ($2)) as friends) " +
// // ^ as friends
// "as fb natural left join facebook_users) as fb2 " +
// "inner join (select * from participants where zid = ($1) and (vote_count > 0 OR uid = ($2))) as p on fb2.uid = p.uid;", [zid, uid]);
// //"select * from (select * from (select friend as uid from facebook_friends where uid = ($2) union select uid from facebook_friends where friend = ($2)) as friends where uid in (select uid from participants where zid = ($1))) as fb natural left join facebook_users;", [zid, uid]);
// return p;
// }

// function getFacebookUsersInConversation(zid) {
// let p = pgQueryP_readOnly("select * from facebook_users inner join (select * from participants where zid = ($1) and vote_count > 0) as p on facebook_users.uid = p.uid;", [zid]);
// return p;
// }

const getSocialInfoForUsers = User.getSocialInfoForUsers;

function updateVoteCount(zid: any, pid: any) {
// return pgQueryP("update participants set vote_count = vote_count + 1 where zid = ($1) and pid = ($2);",[zid, pid]);
return pgQueryP(
Expand Down
32 changes: 0 additions & 32 deletions server/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import LruCache from "lru-cache";
import pg from "./db/pg-query";
import { MPromise } from "./utils/metered";

import Config from "./config";
import Conversation from "./conversation";
import LRUCache from "lru-cache";
import logger from "./utils/logger";
Expand Down Expand Up @@ -271,35 +270,6 @@ function getPidForParticipant(
};
}

function getSocialInfoForUsers(uids: any[], zid: any) {
uids = _.uniq(uids);
uids.forEach(function (uid: string) {
if (!_.isNumber(uid)) {
throw "polis_err_123123_invalid_uid got:" + uid;
}
});
if (!uids.length) {
return Promise.resolve([]);
}
let uidString = uids.join(",");
return pg.queryP_metered_readOnly(
"getSocialInfoForUsers",
"with " +
"x as (select * from xids where uid in (" +
uidString +
") and owner in (select org_id from conversations where zid = ($1))), " +
"fb as (select * from facebook_users where uid in (" +
uidString +
")), " +
"tw as (select * from twitter_users where uid in (" +
uidString +
")), " +
"foo as (select *, coalesce(fb.uid, tw.uid) as foouid from fb full outer join tw on tw.uid = fb.uid) " +
"select *, coalesce(foo.foouid, x.uid) as uid from foo full outer join x on x.uid = foo.foouid;",
[zid]
);
}

function getXidRecordByXidOwnerId(
xid: any,
owner: any,
Expand Down Expand Up @@ -402,7 +372,6 @@ export {
getPid,
getPidPromise,
getPidForParticipant,
getSocialInfoForUsers,
};

export default {
Expand All @@ -416,5 +385,4 @@ export default {
getPid,
getPidPromise,
getPidForParticipant,
getSocialInfoForUsers,
};

0 comments on commit 604ae7c

Please sign in to comment.