-
Notifications
You must be signed in to change notification settings - Fork 114
Feature/additional space and message type fields #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
8c3cb75
131c173
f221647
0a49f60
1109fad
2105438
58d2215
1e95674
6d5f4e6
4b4776e
da677ba
f077ada
d047c5f
0ea2561
c35ba87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ def __init__(self, pubnub): | |
self._count = None | ||
self._include_meta = None | ||
self._include_message_actions = None | ||
self._include_message_type = None | ||
self._include_message_type = True | ||
self._include_space_id = None | ||
self._include_uuid = None | ||
|
||
def channels(self, channels): | ||
|
@@ -76,8 +77,17 @@ def include_uuid(self, include_uuid): | |
self._include_uuid = include_uuid | ||
return self | ||
|
||
def include_space_id(self, include_space_id): | ||
assert isinstance(include_space_id, bool) | ||
self._include_space_id = include_space_id | ||
seba-aln marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self | ||
|
||
def custom_params(self): | ||
params = {'max': int(self._count)} | ||
params = { | ||
'max': int(self._count), | ||
'include_type': 'true' if self._include_message_type else 'false', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'include_message_type': 'true' if self._include_message_type else 'false', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
if self._start is not None: | ||
params['start'] = str(self._start) | ||
|
@@ -88,8 +98,8 @@ def custom_params(self): | |
if self._include_meta is not None: | ||
params['include_meta'] = "true" if self._include_meta else "false" | ||
|
||
if self._include_message_type is not None: | ||
params['include_message_type'] = "true" if self._include_message_type else "false" | ||
if self._include_space_id is not None: | ||
params['include_space_id'] = "true" if self._include_space_id else "false" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space_id can be null and in this case the parameter should not be added, that's why there's |
||
|
||
if self.include_message_actions and self._include_uuid is not None: | ||
params['include_uuid'] = "true" if self._include_uuid else "false" | ||
|
@@ -154,6 +164,8 @@ def create_response(self, envelope): # pylint: disable=W0221 | |
return PNFetchMessagesResult.from_json( | ||
json_input=envelope, | ||
include_message_actions=self._include_message_actions, | ||
include_message_type=self._include_message_type, | ||
include_space_id=self._include_space_id, | ||
start_timetoken=self._start, | ||
end_timetoken=self._end) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class PNMessageType: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class look like a good example of enum class: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well Enum is a closed set of values - this is more like a wrapper around two independent message types:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every time we need to explain this I'm wondering if that's actually a good decision. Especially when you put it like that:
|
||
pn_message_type: str = None | ||
message_type: str = None | ||
_type_mapping = { | ||
'None': 'message', | ||
seba-aln marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'0': 'message', | ||
'1': 'signal', | ||
'2': 'object', | ||
'3': 'message_action', | ||
'4': 'file', | ||
} | ||
|
||
def __init__(self, message_type: str = None) -> None: | ||
self.message_type = message_type | ||
|
||
def set_pn_message_type(self, pn_message_type: str): | ||
self.pn_message_type = self._type_mapping[str(pn_message_type)] | ||
return self | ||
|
||
def from_response(message_type: str = None, pn_message_type: str = None): | ||
return PNMessageType(message_type).set_pn_message_type(pn_message_type) | ||
|
||
def __str__(self) -> str: | ||
return self.message_type if self.message_type is not None else str(self.pn_message_type) | ||
|
||
def toJSON(self) -> str: | ||
return str(self) |
Uh oh!
There was an error while loading. Please reload this page.