Skip to content

Commit c35ba87

Browse files
committed
Remove PNMessageType"
1 parent 0ea2561 commit c35ba87

File tree

17 files changed

+75
-124
lines changed

17 files changed

+75
-124
lines changed

pubnub/endpoints/fetch_messages.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, pubnub):
3232
self._include_meta = None
3333
self._include_message_actions = None
3434
self._include_message_type = True
35+
self._include_type = True
3536
self._include_space_id = None
3637
self._include_uuid = None
3738

@@ -72,6 +73,11 @@ def include_message_type(self, include_message_type):
7273
self._include_message_type = include_message_type
7374
return self
7475

76+
def include_type(self, include_type):
77+
assert isinstance(include_type, bool)
78+
self._include_type = include_type
79+
return self
80+
7581
def include_uuid(self, include_uuid):
7682
assert isinstance(include_uuid, bool)
7783
self._include_uuid = include_uuid
@@ -85,7 +91,7 @@ def include_space_id(self, include_space_id):
8591
def custom_params(self):
8692
params = {
8793
'max': int(self._count),
88-
'include_type': 'true' if self._include_message_type else 'false',
94+
'include_type': 'true' if self._include_type else 'false',
8995
'include_message_type': 'true' if self._include_message_type else 'false',
9096
}
9197

@@ -165,6 +171,7 @@ def create_response(self, envelope): # pylint: disable=W0221
165171
json_input=envelope,
166172
include_message_actions=self._include_message_actions,
167173
include_message_type=self._include_message_type,
174+
include_type=self._include_type,
168175
include_space_id=self._include_space_id,
169176
start_timetoken=self._start,
170177
end_timetoken=self._end)

pubnub/endpoints/file_operations/publish_file_message.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from pubnub import utils
44
from pubnub.models.consumer.file import PNPublishFileMessageResult
55
from pubnub.endpoints.mixins import TimeTokenOverrideMixin
6-
from pubnub.models.consumer.message_type import PNMessageType
7-
from typing import Union
86

97

108
class PublishFileMessage(FileOperationEndpoint, TimeTokenOverrideMixin):
@@ -22,7 +20,7 @@ def __init__(self, pubnub):
2220
self._cipher_key = None
2321
self._replicate = None
2422
self._ptto = None
25-
self._message_type = None
23+
self._type = None
2624
self._space_id = None
2725

2826
def meta(self, meta):
@@ -53,11 +51,11 @@ def file_name(self, file_name):
5351
self._file_name = file_name
5452
return self
5553

56-
def message_type(self, message_type: Union[PNMessageType, str]):
57-
self._message_type = message_type
54+
def type(self, type: str):
55+
self._type = type
5856
return self
5957

60-
def space_id(self, space_id):
58+
def space_id(self, space_id: str):
6159
self._space_id = space_id
6260
return self
6361

@@ -99,11 +97,11 @@ def custom_params(self):
9997
"ttl": self._ttl,
10098
"store": 1 if self._should_store else 0
10199
})
102-
if self._message_type:
103-
params['type'] = str(self._message_type)
100+
if self._type:
101+
params['type'] = self._type
104102

105103
if self._space_id:
106-
params['space-id'] = str(self._space_id)
104+
params['space-id'] = self._space_id
107105

108106
return params
109107

pubnub/endpoints/file_operations/send_file.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from pubnub.endpoints.file_operations.fetch_upload_details import FetchFileUploadS3Data
77
from pubnub.request_handlers.requests_handler import RequestsRequestHandler
88
from pubnub.endpoints.mixins import TimeTokenOverrideMixin
9-
from pubnub.models.consumer.message_type import PNMessageType
10-
from typing import Union
119

1210

1311
class SendFileNative(FileOperationEndpoint, TimeTokenOverrideMixin):
@@ -24,7 +22,7 @@ def __init__(self, pubnub):
2422
self._file_object = None
2523
self._replicate = None
2624
self._ptto = None
27-
self._message_type = None
25+
self._type = None
2826
self._space_id = None
2927

3028
def file_object(self, fd):
@@ -73,8 +71,8 @@ def is_compressable(self):
7371

7472
def custom_params(self):
7573
params = {}
76-
if self._message_type:
77-
params['type'] = str(self._message_type)
74+
if self._type:
75+
params['type'] = str(self._type)
7876

7977
if self._space_id:
8078
params['space-id'] = self._space_id
@@ -120,11 +118,11 @@ def cipher_key(self, cipher_key):
120118
self._cipher_key = cipher_key
121119
return self
122120

123-
def message_type(self, message_type: Union[PNMessageType, str]):
124-
self._message_type = message_type
121+
def type(self, type: str):
122+
self._type = type
125123
return self
126124

127-
def space_id(self, space_id):
125+
def space_id(self, space_id: str):
128126
self._space_id = space_id
129127
return self
130128

@@ -158,7 +156,7 @@ def sync(self):
158156
replicate(self._replicate).\
159157
ptto(self._ptto).\
160158
cipher_key(self._cipher_key).\
161-
message_type(self._message_type).\
159+
type(self._type).\
162160
space_id(self._space_id).sync()
163161

164162
response_envelope.result.timestamp = publish_file_response.result.timestamp

pubnub/endpoints/pubsub/publish.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from pubnub.models.consumer.pubsub import PNPublishResult
66
from pubnub.enums import HttpMethod, PNOperationType
77
from pubnub.endpoints.mixins import TimeTokenOverrideMixin
8-
from pubnub.models.consumer.message_type import PNMessageType
9-
from typing import Union
108

119

1210
class Publish(Endpoint, TimeTokenOverrideMixin):
@@ -31,15 +29,15 @@ def channel(self, channel):
3129
self._channel = str(channel)
3230
return self
3331

34-
def space_id(self, space_id):
32+
def space_id(self, space_id: str):
3533
self._space_id = str(space_id)
3634
return self
3735

3836
def message(self, message):
3937
self._message = message
4038
return self
4139

42-
def message_type(self, message_type: Union[PNMessageType, str]):
40+
def message_type(self, message_type: str):
4341
self._message_type = message_type
4442
return self
4543

@@ -104,10 +102,10 @@ def custom_params(self):
104102
params["auth"] = utils.url_encode(self.pubnub.config.auth_key)
105103

106104
if self._message_type is not None:
107-
params['type'] = str(self._message_type)
105+
params['type'] = self._message_type
108106

109107
if self._space_id is not None:
110-
params['space-id'] = str(self._space_id)
108+
params['space-id'] = self._space_id
111109

112110
return params
113111

pubnub/endpoints/signal.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from pubnub.endpoints.endpoint import Endpoint
33
from pubnub.enums import HttpMethod, PNOperationType
44
from pubnub.models.consumer.signal import PNSignalResult
5-
from pubnub.models.consumer.message_type import PNMessageType
6-
from typing import Union
75

86

97
class Signal(Endpoint):
@@ -13,7 +11,7 @@ def __init__(self, pubnub):
1311
Endpoint.__init__(self, pubnub)
1412
self._channel = None
1513
self._message = None
16-
self._space = None
14+
self._space_id = None
1715
self._message_type = None
1816

1917
def channel(self, channel):
@@ -24,11 +22,11 @@ def message(self, message):
2422
self._message = message
2523
return self
2624

27-
def space_id(self, space):
28-
self._space = str(space)
25+
def space_id(self, space_id: str):
26+
self._space_id = str(space_id)
2927
return self
3028

31-
def message_type(self, message_type: Union[PNMessageType, str]):
29+
def message_type(self, message_type: str):
3230
self._message_type = message_type
3331
return self
3432

@@ -44,10 +42,10 @@ def custom_params(self):
4442
params = {}
4543

4644
if self._message_type is not None:
47-
params['type'] = str(self._message_type)
45+
params['type'] = self._message_type
4846

49-
if self._space is not None:
50-
params['space-id'] = str(self._space)
47+
if self._space_id is not None:
48+
params['space-id'] = self._space_id
5149

5250
return params
5351

pubnub/models/consumer/history.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from pubnub.models.consumer.message_type import PNMessageType
2-
3-
41
class PNHistoryResult(object):
52
def __init__(self, messages, start_timetoken, end_timetoken):
63
self.messages = messages
@@ -66,14 +63,15 @@ def __str__(self):
6663
return "Fetch messages result for range %d..%d" % (self.start_timetoken, self.end_timetoken)
6764

6865
@classmethod
69-
def from_json(cls, json_input, include_message_actions=False, include_message_type=False, include_space_id=False,
70-
start_timetoken=None, end_timetoken=None):
66+
def from_json(cls, json_input, include_message_actions=False, include_message_type=False, include_type=False,
67+
include_space_id=False, start_timetoken=None, end_timetoken=None):
7168
channels = {}
7269

7370
for key, entry in json_input['channels'].items():
7471
channels[key] = []
7572
for item in entry:
76-
message = PNFetchMessageItem(item, include_message_actions, include_message_type, include_space_id)
73+
message = PNFetchMessageItem(item, include_message_actions, include_message_type, include_type,
74+
include_space_id)
7775
channels[key].append(message)
7876

7977
return PNFetchMessagesResult(
@@ -89,7 +87,7 @@ class PNFetchMessageItem(object):
8987
timetoken = None
9088
actions = None
9189

92-
def __init__(self, item, include_message_actions, include_message_type, include_space_id):
90+
def __init__(self, item, include_message_actions, include_message_type, include_type, include_space_id):
9391
self.message = item['message']
9492
self.timetoken = item['timetoken']
9593

@@ -106,9 +104,13 @@ def __init__(self, item, include_message_actions, include_message_type, include_
106104
self.actions = {}
107105

108106
if include_message_type:
109-
self.message_type = PNMessageType.from_response(
110-
message_type=item['type'] if 'type' in item.keys() else None,
111-
pn_message_type=item['message_type'])
107+
if 'message_type' in item:
108+
self.message_type = str(item['message_type']) if item['message_type'] is not None else '0'
109+
else:
110+
self.message_type = None
111+
112+
if include_type:
113+
self.type = item['type'] if 'type' in item.keys() else None
112114

113115
if include_space_id:
114116
self.space_id = item['space_id']

pubnub/models/consumer/message_type.py

-27
This file was deleted.

pubnub/models/consumer/pubsub.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class PNMessageResult(object):
55
def __init__(self, message, subscription, channel, timetoken, user_metadata=None, publisher=None, message_type=None,
6-
space_id=None):
6+
type=None, space_id=None):
77
if subscription is not None:
88
assert isinstance(subscription, str)
99

@@ -29,7 +29,8 @@ def __init__(self, message, subscription, channel, timetoken, user_metadata=None
2929
self.timetoken = timetoken
3030
self.user_metadata = user_metadata
3131
self.publisher = publisher
32-
self.type = message_type
32+
self.message_type = message_type
33+
self.type = type
3334
self.space_id = space_id
3435

3536

pubnub/models/server/subscribe.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from pubnub.models.consumer.message_type import PNMessageType
2-
3-
41
class SubscribeEnvelope:
52
def __init__(self, messages=None, metadata=None):
63
assert isinstance(messages, (list, None))
@@ -58,11 +55,13 @@ def from_json(cls, json_input):
5855
if 'si' in json_input:
5956
message.space_id = json_input['si']
6057

58+
# customers message type set during publish
6159
if 'mt' in json_input:
62-
if 'e' in json_input:
63-
message.message_type = PNMessageType.from_response(json_input['mt'], json_input['e'])
64-
else:
65-
message.message_type = PNMessageType(json_input['mt'])
60+
message.type = json_input['mt']
61+
62+
# internal message type (None|0 = message, 1 = file, etc)
63+
if 'e' in json_input:
64+
message.message_type = json_input['mt']
6665

6766
return message
6867

pubnub/workers.py

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def _process_incoming_payload(self, message):
174174
timetoken=publish_meta_data.publish_timetoken,
175175
publisher=publisher,
176176
message_type=message.message_type,
177+
type=message.type,
177178
space_id=message.space_id
178179
)
179180
self._listener_manager.announce_message(pn_message_result)

tests/acceptance/files/steps/steps.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def step_impl(context):
1313
context.peer = pubnub_instance
1414

1515

16-
@when(u'I send a file with \'{space_id}\' space id and \'{message_type}\' message type')
17-
def step_impl(context, space_id, message_type):
16+
@when(u'I send a file with \'{space_id}\' space id and \'{type}\' type')
17+
def step_impl(context, space_id, type):
1818
try:
1919
with open('tests/acceptance/files/test.txt', 'rb') as file_object:
2020
envelope = context.peer.send_file().channel('test').message('test').should_store(True).ttl(200). \
21-
file_name('test.txt').file_object(file_object).space_id(space_id).message_type(message_type).sync()
21+
file_name('test.txt').file_object(file_object).space_id(space_id).type(type).sync()
2222
context.status = envelope.status
2323
context.result = envelope.result
2424
except PubNubException as error:

tests/acceptance/history/steps/then_steps.py

+10
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ def step_impl(context):
3131
@then('history response contains messages with space ids')
3232
def step_impl(context):
3333
assert all('space_id' in item.__dict__.keys() for item in context.messages)
34+
35+
36+
@then("history response contains messages with '{type1}' and '{type2}' types")
37+
def step_impl(context, type1, type2):
38+
assert all(str(item.type) in [type1, type2] for item in context.messages)
39+
40+
41+
@then('history response contains messages without types')
42+
def step_impl(context):
43+
assert all('type' not in item.__dict__.keys() for item in context.messages)

0 commit comments

Comments
 (0)