Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

orientorf188708b20f4
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index 12225ae613a..f84c4292470 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -10,6 +10,12 @@ below features are supported.
## 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**
* `PATCH /settings/display`: Replaced the `night_mode` boolean with
diff --git a/zerver/models.py b/zerver/models.py
index ec4e8bf056b..d42e531c21e 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -2114,10 +2114,10 @@ class Attachment(AbstractAttachment):
'size': self.size,
# convert to JavaScript-style UNIX timestamp so we can take
# advantage of client timezones.
- 'create_time': time.mktime(self.create_time.timetuple()) * 1000,
+ 'create_time': int(time.mktime(self.create_time.timetuple()) * 1000),
'messages': [{
'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()],
}
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 45f187cdca3..038401c7fa6 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -386,11 +386,13 @@ paths:
description: |
Size of the file in bytes.
create_time:
- # TODO: Make this value always return integers.
- type: number
+ type: integer
description: |
Time when the attachment was uploaded as a UNIX timestamp
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:
type: array
description: |
@@ -402,13 +404,15 @@ paths:
items:
type: object
properties:
- name:
- type: number
+ date_sent:
+ type: integer
description: |
Time when the message was sent as a UNIX timestamp
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:
type: integer
description: |
@@ -429,15 +433,15 @@ paths:
"name": "166050.jpg",
"path_id": "2/ce/DfOkzwdg_IwlrN3myw3KGtiJ/166050.jpg",
"size": 571946,
- "create_time": 1588145417000.0,
+ "create_time": 1588145417000,
"messages": [
{
"id": 102,
- "name": 1588145424000.0
+ "date_sent": 1588145424000
},
{
"id": 103,
- "name": 1588145448000.0
+ "date_sent": 1588145448000
}
]
}
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 5976d43c012..96ee69806e9 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -2737,10 +2737,10 @@ class EventsRegisterTest(ZulipTestCase):
('name', check_string),
('size', check_int),
('path_id', check_string),
- ('create_time', check_float),
+ ('create_time', check_int),
('messages', check_list(check_dict_only([
('id', check_int),
- ('name', check_float),
+ ('date_sent', check_int),
]))),
])),
('upload_space_used', equals(6)),
@@ -2779,10 +2779,10 @@ class EventsRegisterTest(ZulipTestCase):
('name', check_string),
('size', check_int),
('path_id', check_string),
- ('create_time', check_float),
+ ('create_time', check_int),
('messages', check_list(check_dict_only([
('id', check_int),
- ('name', check_float),
+ ('date_sent', check_int),
]))),
])),
('upload_space_used', equals(6)),