attachments: Change data type and make variable names more accurate.

Change variable `name` to `date_sent` as `name` actually stores
the date sent. Also change the data types of `name` and `create_time`
to integer. As they actually have empty decimal value.
This commit is contained in:
orientor 2020-06-24 13:58:00 +05:30 committed by Tim Abbott
parent 4a88e2a732
commit f188708b20
4 changed files with 24 additions and 14 deletions

View File

@ -10,6 +10,12 @@ below features are supported.
## Changes in Zulip 3.0 ## Changes in Zulip 3.0
**Feature level 22**
* 'GET /attachments': Rename `name` to `date_sent` for clearer meaning
and change the data types of the new `date_sent` and `create_time`
to integer (previously the implementation could send floats).
**Feature level 21** **Feature level 21**
* `PATCH /settings/display`: Replaced the `night_mode` boolean with * `PATCH /settings/display`: Replaced the `night_mode` boolean with

View File

@ -2114,10 +2114,10 @@ class Attachment(AbstractAttachment):
'size': self.size, 'size': self.size,
# convert to JavaScript-style UNIX timestamp so we can take # convert to JavaScript-style UNIX timestamp so we can take
# advantage of client timezones. # advantage of client timezones.
'create_time': time.mktime(self.create_time.timetuple()) * 1000, 'create_time': int(time.mktime(self.create_time.timetuple()) * 1000),
'messages': [{ 'messages': [{
'id': m.id, 'id': m.id,
'name': time.mktime(m.date_sent.timetuple()) * 1000, 'date_sent': int(time.mktime(m.date_sent.timetuple()) * 1000),
} for m in self.messages.all()], } for m in self.messages.all()],
} }

View File

@ -386,11 +386,13 @@ paths:
description: | description: |
Size of the file in bytes. Size of the file in bytes.
create_time: create_time:
# TODO: Make this value always return integers. type: integer
type: number
description: | description: |
Time when the attachment was uploaded as a UNIX timestamp Time when the attachment was uploaded as a UNIX timestamp
multiplied by 1000 (matching the format of getTime() in JavaScript). multiplied by 1000 (matching the format of getTime() in JavaScript).
**Changes**: Changed in Zulip 2.2 (feature level 22). This field was
previously a floating point number.
messages: messages:
type: array type: array
description: | description: |
@ -402,13 +404,15 @@ paths:
items: items:
type: object type: object
properties: properties:
name: date_sent:
type: number type: integer
description: | description: |
Time when the message was sent as a UNIX timestamp Time when the message was sent as a UNIX timestamp
multiplied by 1000 (matching the format of getTime() in JavaScript). multiplied by 1000 (matching the format of getTime() in JavaScript).
**Deprecated**: We plan to rename this field. **Changes**: Changed in Zulip 2.2 (feature level 22). This
field was previously strangely called `name` and was a floating
point number.
id: id:
type: integer type: integer
description: | description: |
@ -429,15 +433,15 @@ paths:
"name": "166050.jpg", "name": "166050.jpg",
"path_id": "2/ce/DfOkzwdg_IwlrN3myw3KGtiJ/166050.jpg", "path_id": "2/ce/DfOkzwdg_IwlrN3myw3KGtiJ/166050.jpg",
"size": 571946, "size": 571946,
"create_time": 1588145417000.0, "create_time": 1588145417000,
"messages": [ "messages": [
{ {
"id": 102, "id": 102,
"name": 1588145424000.0 "date_sent": 1588145424000
}, },
{ {
"id": 103, "id": 103,
"name": 1588145448000.0 "date_sent": 1588145448000
} }
] ]
} }

View File

@ -2737,10 +2737,10 @@ class EventsRegisterTest(ZulipTestCase):
('name', check_string), ('name', check_string),
('size', check_int), ('size', check_int),
('path_id', check_string), ('path_id', check_string),
('create_time', check_float), ('create_time', check_int),
('messages', check_list(check_dict_only([ ('messages', check_list(check_dict_only([
('id', check_int), ('id', check_int),
('name', check_float), ('date_sent', check_int),
]))), ]))),
])), ])),
('upload_space_used', equals(6)), ('upload_space_used', equals(6)),
@ -2779,10 +2779,10 @@ class EventsRegisterTest(ZulipTestCase):
('name', check_string), ('name', check_string),
('size', check_int), ('size', check_int),
('path_id', check_string), ('path_id', check_string),
('create_time', check_float), ('create_time', check_int),
('messages', check_list(check_dict_only([ ('messages', check_list(check_dict_only([
('id', check_int), ('id', check_int),
('name', check_float), ('date_sent', check_int),
]))), ]))),
])), ])),
('upload_space_used', equals(6)), ('upload_space_used', equals(6)),