diff --git a/squeaknode/admin/messages.py b/squeaknode/admin/messages.py index 4613cf67..b00425fb 100644 --- a/squeaknode/admin/messages.py +++ b/squeaknode/admin/messages.py @@ -208,20 +208,24 @@ def message_to_peer_address(peer_address: squeak_admin_pb2.PeerAddress) -> PeerA ) -def message_to_squeak_entry(squeak_entry: squeak_admin_pb2.SqueakDisplayEntry) -> SqueakEntry: +def message_to_squeak_entry(squeak_entry_msg: squeak_admin_pb2.SqueakDisplayEntry) -> SqueakEntry: + like_time_ms = squeak_entry_msg.liked_time_ms if squeak_entry_msg.liked_time_ms > 0 else None + reply_to_hash = bytes.fromhex( + squeak_entry_msg.reply_to) if squeak_entry_msg.reply_to else None + content_str = squeak_entry_msg.content_str if len( + squeak_entry_msg.content_str) > 0 else None return SqueakEntry( - squeak_hash=bytes.fromhex(squeak_entry.squeak_hash), - address=squeak_entry.author_address, - block_height=squeak_entry.block_height, - block_hash=bytes.fromhex(squeak_entry.block_hash), - block_time=squeak_entry.block_time, - squeak_time=squeak_entry.squeak_time, - reply_to=bytes.fromhex( - squeak_entry.reply_to) if squeak_entry.reply_to else None, - is_unlocked=squeak_entry.is_unlocked, + squeak_hash=bytes.fromhex(squeak_entry_msg.squeak_hash), + address=squeak_entry_msg.author_address, + block_height=squeak_entry_msg.block_height, + block_hash=bytes.fromhex(squeak_entry_msg.block_hash), + block_time=squeak_entry_msg.block_time, + squeak_time=squeak_entry_msg.squeak_time, + reply_to=reply_to_hash, + is_unlocked=squeak_entry_msg.is_unlocked, squeak_profile=None, # TODO: message to squeak profile - liked_time_ms=squeak_entry.liked_time_ms, - content=squeak_entry.content_str, + liked_time_ms=like_time_ms, + content=content_str, ) diff --git a/tests/admin/test_messages.py b/tests/admin/test_messages.py index 419f0abd..b49b5a62 100644 --- a/tests/admin/test_messages.py +++ b/tests/admin/test_messages.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from squeaknode.admin.messages import message_to_peer_address +from squeaknode.admin.messages import message_to_squeak_entry from squeaknode.admin.messages import peer_address_to_message from squeaknode.admin.messages import received_offer_to_message from squeaknode.admin.messages import received_payment_to_message @@ -49,6 +50,14 @@ def test_squeak_entry_to_message(squeak_entry_locked, squeak_entry_msg_locked): assert msg == squeak_entry_msg_locked +def test_message_to_squeak_entry(squeak_entry_locked, squeak_entry_msg_locked): + entry = message_to_squeak_entry(squeak_entry_msg_locked) + + # TODO: remove this line after implementing "message_to_squeak_profile" + entry_with_null_profile = squeak_entry_locked._replace(squeak_profile=None) + assert entry == entry_with_null_profile + + def test_profile_to_message(signing_profile, signing_profile_msg): msg = squeak_profile_to_message(signing_profile)