From cdca52b7e28f0fdd140131e47f94cf4ecf623b72 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Wed, 29 Jul 2020 21:48:42 -0700 Subject: [PATCH] Rename followed to following (#170) * Rename followed field to following in profile * Rename shared field to sharing in profile * Revert changes to icons.js * Rename following squeaks to followed squeaks * Fix frontend for renamed get followed request --- .../src/pages/profile/Profile.js | 30 +++++++++---------- .../src/pages/profiles/Profiles.js | 13 ++++---- .../src/pages/timeline/Timeline.js | 4 +-- init.sql | 4 +-- itests/tests/test_squeak_node.py | 24 +++++++-------- proto/squeak_admin.proto | 20 ++++++------- .../admin/squeak_admin_server_handler.py | 10 +++---- .../admin/squeak_admin_server_servicer.py | 16 +++++----- squeakserver/node/squeak_node.py | 12 ++++---- squeakserver/server/postgres_db.py | 22 +++++++------- squeakserver/server/squeak_profile.py | 2 +- 11 files changed, 78 insertions(+), 79 deletions(-) diff --git a/frontend/squeak-node-frontend/src/pages/profile/Profile.js b/frontend/squeak-node-frontend/src/pages/profile/Profile.js index 394e5f8e..da31e9d5 100644 --- a/frontend/squeak-node-frontend/src/pages/profile/Profile.js +++ b/frontend/squeak-node-frontend/src/pages/profile/Profile.js @@ -19,7 +19,7 @@ import Widget from "../../components/Widget"; import { GetSqueakProfileRequest, - SetSqueakProfileFollowedRequest, + SetSqueakProfileFollowingRequest, } from "../../proto/squeak_admin_pb" import { SqueakAdminClient } from "../../proto/squeak_admin_grpc_web_pb" @@ -45,13 +45,13 @@ export default function ProfilePage() { setSqueakProfile(response.getSqueakProfile()) }); }; - const setFollowed = (id, followed) => { - console.log("called setFollowed with profileId: " + id + ", followed: " + followed); - var setSqueakProfileFollowedRequest = new SetSqueakProfileFollowedRequest() - setSqueakProfileFollowedRequest.setProfileId(id); - setSqueakProfileFollowedRequest.setFollowed(followed); - console.log(setSqueakProfileFollowedRequest); - client.setSqueakProfileFollowed(setSqueakProfileFollowedRequest, {}, (err, response) => { + const setFollowing = (id, following) => { + console.log("called setFollowing with profileId: " + id + ", following: " + following); + var setSqueakProfileFollowingRequest = new SetSqueakProfileFollowingRequest() + setSqueakProfileFollowingRequest.setProfileId(id); + setSqueakProfileFollowingRequest.setFollowing(following); + console.log(setSqueakProfileFollowingRequest); + client.setSqueakProfileFollowing(setSqueakProfileFollowingRequest, {}, (err, response) => { console.log(response); getSqueakProfile(id); }); @@ -62,10 +62,10 @@ export default function ProfilePage() { getSqueakProfile(id) },[id]); - const handleSettingsFollowedChange = (event) => { + const handleSettingsFollowingChange = (event) => { console.log("Settings changed for profile id: " + id); - console.log("Followed changed to: " + event.target.checked); - setFollowed(id, event.target.checked); + console.log("Following changed to: " + event.target.checked); + setFollowing(id, event.target.checked); }; const handleSettingsChange = (event) => { @@ -98,12 +98,12 @@ export default function ProfilePage() { Profile settings } - label="Followed" + control={} + label="Following" /> } - label="Shared" + control={} + label="Sharing" /> } diff --git a/frontend/squeak-node-frontend/src/pages/profiles/Profiles.js b/frontend/squeak-node-frontend/src/pages/profiles/Profiles.js index 48e8d785..bfdc8476 100644 --- a/frontend/squeak-node-frontend/src/pages/profiles/Profiles.js +++ b/frontend/squeak-node-frontend/src/pages/profiles/Profiles.js @@ -26,7 +26,6 @@ import mock from "../dashboard/mock"; import {GetInfoRequest} from "../../proto/lnd_pb" import { HelloRequest, - GetFollowedSqueakDisplaysRequest, GetSigningProfilesRequest, GetContactProfilesRequest, } from "../../proto/squeak_admin_pb" @@ -261,11 +260,11 @@ export default function Profiles() { [ p.getProfileName(), p.getAddress(), - p.getFollowed().toString(), - p.getShared().toString(), + p.getFollowing().toString(), + p.getSharing().toString(), ] )} - columns={["Name", "Address", "Followed", "Shared"]} + columns={["Name", "Address", "Following", "Sharing"]} options={{ filter: false, print: false, @@ -294,11 +293,11 @@ export default function Profiles() { [ p.getProfileName(), p.getAddress(), - p.getFollowed().toString(), - p.getShared().toString(), + p.getFollowing().toString(), + p.getSharing().toString(), ] )} - columns={["Name", "Address", "Followed", "Shared"]} + columns={["Name", "Address", "Following", "Sharing"]} options={{ filter: false, print: false, diff --git a/frontend/squeak-node-frontend/src/pages/timeline/Timeline.js b/frontend/squeak-node-frontend/src/pages/timeline/Timeline.js index 13026516..4c36bd41 100644 --- a/frontend/squeak-node-frontend/src/pages/timeline/Timeline.js +++ b/frontend/squeak-node-frontend/src/pages/timeline/Timeline.js @@ -48,8 +48,8 @@ export default function TimelinePage() { const getSqueaks = () => { console.log("called getSqueaks"); - var getSqueaksRequest = new GetFollowedSqueakDisplaysRequest() - client.getFollowedSqueakDisplays(getSqueaksRequest, {}, (err, response) => { + var getFollowedSqueakDisplaysRequest = new GetFollowedSqueakDisplaysRequest() + client.getFollowedSqueakDisplays(getFollowedSqueakDisplaysRequest, {}, (err, response) => { console.log(response); setSqueaks(response.getSqueakDisplayEntriesList()) }); diff --git a/init.sql b/init.sql index 22898206..f5287cca 100644 --- a/init.sql +++ b/init.sql @@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS profile ( profile_name VARCHAR(64) NOT NULL, private_key bytea, address VARCHAR(35) UNIQUE NOT NULL, -- Maximum length of a bitcoin address is 35. - shared BOOLEAN NOT NULL, - followed BOOLEAN NOT NULL, + sharing BOOLEAN NOT NULL, + following BOOLEAN NOT NULL, whitelisted BOOLEAN NOT NULL ); diff --git a/itests/tests/test_squeak_node.py b/itests/tests/test_squeak_node.py index 474b5cca..363bad64 100644 --- a/itests/tests/test_squeak_node.py +++ b/itests/tests/test_squeak_node.py @@ -335,18 +335,18 @@ def test_set_profile_whitelisted(server_stub, admin_stub, contact_profile_id): ) assert get_squeak_profile_response.squeak_profile.whitelisted == True -def test_set_profile_followed(server_stub, admin_stub, contact_profile_id): +def test_set_profile_following(server_stub, admin_stub, contact_profile_id): # Get the existing profile get_squeak_profile_response = admin_stub.GetSqueakProfile( squeak_admin_pb2.GetSqueakProfileRequest(profile_id=contact_profile_id,) ) - assert get_squeak_profile_response.squeak_profile.followed == False + assert get_squeak_profile_response.squeak_profile.following == False - # Set the profile to be followed - admin_stub.SetSqueakProfileFollowed( - squeak_admin_pb2.SetSqueakProfileFollowedRequest( + # Set the profile to be following + admin_stub.SetSqueakProfileFollowing( + squeak_admin_pb2.SetSqueakProfileFollowingRequest( profile_id=contact_profile_id, - followed=True, + following=True, ) ) @@ -354,14 +354,14 @@ def test_set_profile_followed(server_stub, admin_stub, contact_profile_id): get_squeak_profile_response = admin_stub.GetSqueakProfile( squeak_admin_pb2.GetSqueakProfileRequest(profile_id=contact_profile_id,) ) - assert get_squeak_profile_response.squeak_profile.followed == True + assert get_squeak_profile_response.squeak_profile.following == True -def test_get_followed_squeaks(server_stub, admin_stub, saved_squeak_hash, signing_profile_id): - # Set the profile to be followed - admin_stub.SetSqueakProfileFollowed( - squeak_admin_pb2.SetSqueakProfileFollowedRequest( +def test_get_following_squeaks(server_stub, admin_stub, saved_squeak_hash, signing_profile_id): + # Set the profile to be following + admin_stub.SetSqueakProfileFollowing( + squeak_admin_pb2.SetSqueakProfileFollowingRequest( profile_id=signing_profile_id, - followed=True, + following=True, ) ) diff --git a/proto/squeak_admin.proto b/proto/squeak_admin.proto index 2eda23a8..f91e166f 100644 --- a/proto/squeak_admin.proto +++ b/proto/squeak_admin.proto @@ -50,9 +50,9 @@ service SqueakAdmin { */ rpc SetSqueakProfileWhitelisted (SetSqueakProfileWhitelistedRequest) returns (SetSqueakProfileWhitelistedReply) {} - /** sqkadmin: `setsqueakprofilefollowed` + /** sqkadmin: `setsqueakprofilefollowing` */ - rpc SetSqueakProfileFollowed (SetSqueakProfileFollowedRequest) returns (SetSqueakProfileFollowedReply) {} + rpc SetSqueakProfileFollowing (SetSqueakProfileFollowingRequest) returns (SetSqueakProfileFollowingReply) {} /** sqkadmin: `makesqueak` */ @@ -154,15 +154,15 @@ message SetSqueakProfileWhitelistedRequest { message SetSqueakProfileWhitelistedReply { } -message SetSqueakProfileFollowedRequest { +message SetSqueakProfileFollowingRequest { /// The profile id int32 profile_id = 1; - /// Followed - bool followed = 2; + /// Following + bool following = 2; } -message SetSqueakProfileFollowedReply { +message SetSqueakProfileFollowingReply { } message SqueakProfile { @@ -178,11 +178,11 @@ message SqueakProfile { /// The address string address = 4; - /// Shared - bool shared = 5; + /// Sharing + bool sharing = 5; - /// Followed - bool followed = 6; + /// Following + bool following = 6; /// Whitelisted bool whitelisted = 7; diff --git a/squeakserver/admin/squeak_admin_server_handler.py b/squeakserver/admin/squeak_admin_server_handler.py index d6c6db0e..0d02468b 100644 --- a/squeakserver/admin/squeak_admin_server_handler.py +++ b/squeakserver/admin/squeak_admin_server_handler.py @@ -66,12 +66,12 @@ class SqueakAdminServerHandler(object): )) self.squeak_node.set_squeak_profile_whitelisted(profile_id, whitelisted) - def handle_set_squeak_profile_followed(self, profile_id, followed): - logger.info("Handle set squeak profile followed with profile id: {}, followed: {}".format( + def handle_set_squeak_profile_following(self, profile_id, following): + logger.info("Handle set squeak profile following with profile id: {}, following: {}".format( profile_id, - followed, + following, )) - self.squeak_node.set_squeak_profile_followed(profile_id, followed) + self.squeak_node.set_squeak_profile_following(profile_id, following) def handle_make_squeak(self, profile_id, content_str, replyto_hash): logger.info("Handle make squeak profile with id: {}".format(profile_id)) @@ -96,7 +96,7 @@ class SqueakAdminServerHandler(object): logger.info("Handle get followed squeak display entries.") squeak_entries_with_profile = self.squeak_node.get_followed_squeak_entries_with_profile() logger.info( - "Got number of squeak entries: {}".format( + "Got number of followed squeak entries: {}".format( len(squeak_entries_with_profile) ) ) diff --git a/squeakserver/admin/squeak_admin_server_servicer.py b/squeakserver/admin/squeak_admin_server_servicer.py index 93cfe2c9..86cd37af 100644 --- a/squeakserver/admin/squeak_admin_server_servicer.py +++ b/squeakserver/admin/squeak_admin_server_servicer.py @@ -87,11 +87,11 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer): self.handler.handle_set_squeak_profile_whitelisted(profile_id, whitelisted) return squeak_admin_pb2.SetSqueakProfileWhitelistedReply() - def SetSqueakProfileFollowed(self, request, context): + def SetSqueakProfileFollowing(self, request, context): profile_id = request.profile_id - followed = request.followed - self.handler.handle_set_squeak_profile_followed(profile_id, followed) - return squeak_admin_pb2.SetSqueakProfileFollowedReply() + following = request.following + self.handler.handle_set_squeak_profile_following(profile_id, following) + return squeak_admin_pb2.SetSqueakProfileFollowingReply() def MakeSqueak(self, request, context): profile_id = request.profile_id @@ -140,7 +140,7 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer): for entry in squeak_entries_with_profile ] - return squeak_admin_pb2.GetFollowedSqueakDisplaysReply( + return squeak_admin_pb2.GetAddressSqueakDisplaysReply( squeak_display_entries=squeak_display_msgs ) @@ -154,7 +154,7 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer): for entry in squeak_entries_with_profile ] - return squeak_admin_pb2.GetFollowedSqueakDisplaysReply( + return squeak_admin_pb2.GetAncestorSqueakDisplaysReply( squeak_display_entries=squeak_display_msgs ) @@ -194,8 +194,8 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer): profile_name=squeak_profile.profile_name, has_private_key=has_private_key, address=squeak_profile.address, - shared=squeak_profile.shared, - followed=squeak_profile.followed, + sharing=squeak_profile.sharing, + following=squeak_profile.following, whitelisted=squeak_profile.whitelisted, ) diff --git a/squeakserver/node/squeak_node.py b/squeakserver/node/squeak_node.py index 7db361e7..15592f77 100644 --- a/squeakserver/node/squeak_node.py +++ b/squeakserver/node/squeak_node.py @@ -133,8 +133,8 @@ class SqueakNode: profile_name=profile_name, private_key=signing_key_bytes, address=str(address), - shared=False, - followed=False, + sharing=False, + following=False, whitelisted=False, ) return self.postgres_db.insert_profile(squeak_profile) @@ -148,8 +148,8 @@ class SqueakNode: profile_name=profile_name, private_key=None, address=squeak_address, - shared=False, - followed=False, + sharing=False, + following=False, whitelisted=False, ) return self.postgres_db.insert_profile(squeak_profile) @@ -170,8 +170,8 @@ class SqueakNode: self.postgres_db.set_profile_whitelisted(profile_id, whitelisted) self.squeak_whitelist.refresh() - def set_squeak_profile_followed(self, profile_id, followed): - self.postgres_db.set_profile_followed(profile_id, followed) + def set_squeak_profile_following(self, profile_id, following): + self.postgres_db.set_profile_following(profile_id, following) def make_squeak(self, profile_id, content_str, replyto_hash): squeak_profile = self.postgres_db.get_profile(profile_id) diff --git a/squeakserver/server/postgres_db.py b/squeakserver/server/postgres_db.py index 29e86ef4..66be1af4 100644 --- a/squeakserver/server/postgres_db.py +++ b/squeakserver/server/postgres_db.py @@ -110,13 +110,13 @@ class PostgresDb: return self._parse_squeak_entry_with_profile(row) def get_followed_squeak_entries_with_profile(self): - """ Get a squeak. """ + """ Get all followed squeaks. """ sql = """ SELECT * FROM squeak JOIN profile ON squeak.author_address=profile.address WHERE squeak.block_header IS NOT NULL - AND profile.followed + AND profile.following ORDER BY n_block_height DESC, n_time DESC; """ with self.get_cursor() as curs: @@ -189,7 +189,7 @@ class PostgresDb: def insert_profile(self, squeak_profile): """ Insert a new squeak profile. """ sql = """ - INSERT INTO profile(profile_name, private_key, address, shared, followed, whitelisted) + INSERT INTO profile(profile_name, private_key, address, sharing, following, whitelisted) VALUES(%s, %s, %s, %s, %s, %s) RETURNING profile_id; """ @@ -201,8 +201,8 @@ class PostgresDb: squeak_profile.profile_name, squeak_profile.private_key, squeak_profile.address, - squeak_profile.shared, - squeak_profile.followed, + squeak_profile.sharing, + squeak_profile.following, squeak_profile.whitelisted, ), ) @@ -277,15 +277,15 @@ class PostgresDb: with self.get_cursor() as curs: curs.execute(sql, (whitelisted, profile_id,)) - def set_profile_followed(self, profile_id, followed): - """ Set a profile is followed. """ + def set_profile_following(self, profile_id, following): + """ Set a profile is following. """ sql = """ UPDATE profile - SET followed=%s + SET following=%s WHERE profile_id=%s; """ with self.get_cursor() as curs: - curs.execute(sql, (followed, profile_id,)) + curs.execute(sql, (following, profile_id,)) def get_unverified_block_squeaks(self): """ Get all squeaks without block header. """ @@ -356,8 +356,8 @@ class PostgresDb: profile_name=row["profile_name"], private_key=private_key, address=row["address"], - shared=row["shared"], - followed=row["followed"], + sharing=row["sharing"], + following=row["following"], whitelisted=row["whitelisted"], ) diff --git a/squeakserver/server/squeak_profile.py b/squeakserver/server/squeak_profile.py index dbeb30d4..ed9b597b 100644 --- a/squeakserver/server/squeak_profile.py +++ b/squeakserver/server/squeak_profile.py @@ -2,5 +2,5 @@ from collections import namedtuple SqueakProfile = namedtuple( "SqueakProfile", - "profile_id, profile_name, private_key, address, shared, followed, whitelisted", + "profile_id, profile_name, private_key, address, sharing, following, whitelisted", )