Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check post body and post username when checking profanity filter
seperate post parsing into a new model type
- Loading branch information
1 parent
6560229
commit ce185d1
Showing
3 changed files
with
43 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from .. import utils | ||
from .. import session_pb2 as protobuf | ||
|
||
|
||
class Post: | ||
"""Class representing a post made in an open group""" | ||
|
||
_proto = None | ||
|
||
def __init__(self, raw=None, *, user=None, text=None): | ||
if isinstance(raw, bytes) or isinstance(raw, memoryview): | ||
msg = protobuf.Content() | ||
msg.ParseFromString(utils.remove_session_message_padding(raw)) | ||
self._proto = msg.dataMessage | ||
if self._proto is None: | ||
# TODO: implement other kinds of construction methods for Posts | ||
raise ValueError('must provide raw message bytes') | ||
|
||
@property | ||
def text(self): | ||
""" accessor for the post body """ | ||
return self._proto.body | ||
|
||
@property | ||
def username(self): | ||
""" accessor for the username of the post's author """ | ||
if self.profile is None: | ||
return | ||
return self.profile.displayName | ||
|
||
@property | ||
def profile(self): | ||
""" accessor for the user profile data containing things like username etc """ | ||
return self._proto.profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters