Skip to content

Commit 5679026

Browse files
committed
rename drafty form response content type to text/x-drafy-fr
1 parent a84a5a6 commit 5679026

File tree

14 files changed

+85
-83
lines changed

14 files changed

+85
-83
lines changed

package-lock.json

Lines changed: 52 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"react": "^18.3.0",
7676
"react-dom": "^18.3.0",
7777
"react-intl": "^7.0.0",
78-
"tinode-sdk": "^0.24.3",
78+
"tinode-sdk": "^0.24.4",
7979
"webm-duration-fix": "^1.0.4"
8080
},
8181
"devDependencies": {

src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,6 @@ export const SELF_AVATAR_URI = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS
148148

149149
// Toast display duration, milliseconds.
150150
export const TOAST_DURATION = 3_000;
151+
152+
// MIME type for the legacy Drafty form-response data.
153+
export const DRAFTY_FR_MIME_TYPE_LEGACY = 'application/json'; // Remove in 2026.

src/lib/formatters.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import InlineVideo from '../widgets/inline-video.jsx';
1010
import LazyImage from '../widgets/lazy-image.jsx'
1111
import UploadingImage from '../widgets/uploading-image.jsx'
1212

13-
import { BROKEN_IMAGE_SIZE, CLICKABLE_URL_SCHEMES, IMAGE_THUMBNAIL_DIM, NO_DIMENSIONS_VIDEO, REM_SIZE,
14-
VIDEO_THUMBNAIL_WIDTH } from '../config.js';
13+
import { BROKEN_IMAGE_SIZE, CLICKABLE_URL_SCHEMES, IMAGE_THUMBNAIL_DIM, NO_DIMENSIONS_VIDEO,
14+
REM_SIZE, VIDEO_THUMBNAIL_WIDTH } from '../config.js';
1515
import { base64ToBlob, blobToBase64, fitImageSize, imageScaled } from './blob-helpers.js';
1616
import { idToColorClass, secondsToTime, shortenFileName } from './strformat.js';
1717
import { cancelablePromise, sanitizeUrl, sanitizeUrlForMime } from './utils.js';
@@ -44,9 +44,6 @@ const messages = defineMessages({
4444
}
4545
});
4646

47-
const JSON_MIME_TYPE = 'application/json+drafty';
48-
const JSON_MIME_TYPE_LEGACY = 'application/json'; // Remove in 2026.
49-
5047
// The main Drafty formatter: converts Drafty elements into React classes. 'this' is set by the caller.
5148
// 'this' must contain:
5249
// viewportWidth:
@@ -307,7 +304,7 @@ export function previewFormatter(style, data, values, key) {
307304
break;
308305
case 'EX':
309306
if (data) {
310-
if (data.mime == JSON_MIME_TYPE || data.mime == JSON_MIME_TYPE_LEGACY) {
307+
if (Drafty.isFormResponseType(data.mime)) {
311308
// Ignore JSON attachments: they are form response payloads.
312309
return null;
313310
}
@@ -429,7 +426,7 @@ function quoteFormatter(style, data, values, key) {
429426
case 'EX':
430427
let fname;
431428
if (data) {
432-
if (data.mime == JSON_MIME_TYPE || data.mime == JSON_MIME_TYPE_LEGACY) {
429+
if (Drafty.isFormResponseType(data.mime)) {
433430
// Ignore JSON attachments: they are form response payloads.
434431
return null;
435432
}

src/views/messages-view.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import SendMessage from '../widgets/send-message.jsx';
2222
import VideoPreview from '../widgets/video-preview.jsx';
2323

2424
import { DEFAULT_P2P_ACCESS_MODE, EDIT_PREVIEW_LENGTH, IMAGE_PREVIEW_DIM, IMMEDIATE_P2P_SUBSCRIPTION,
25-
KEYPRESS_DELAY, MESSAGES_PAGE, MAX_EXTERN_ATTACHMENT_SIZE, MAX_IMAGE_DIM, MAX_INBAND_ATTACHMENT_SIZE,
26-
READ_DELAY, QUOTED_REPLY_LENGTH, VIDEO_PREVIEW_DIM } from '../config.js';
25+
DRAFTY_FR_MIME_TYPE_LEGACY, KEYPRESS_DELAY, MESSAGES_PAGE, MAX_EXTERN_ATTACHMENT_SIZE, MAX_IMAGE_DIM,
26+
MAX_INBAND_ATTACHMENT_SIZE, READ_DELAY, QUOTED_REPLY_LENGTH, VIDEO_PREVIEW_DIM } from '../config.js';
2727
import { CALL_STATE_OUTGOING_INITATED, CALL_STATE_IN_PROGRESS } from '../constants.js';
2828
import { blobToBase64, fileToBase64, imageScaled, makeImageUrl } from '../lib/blob-helpers.js';
2929
import HashNavigation from '../lib/navigation.js';
@@ -1025,7 +1025,7 @@ class MessagesView extends React.Component {
10251025
// If the attachment is a JSON file, then use 'application/octet-stream' instead of 'application/json'.
10261026
// This is a temporary workaround for the collision with the 'application/json' MIME type of form responses.
10271027
// Remove this code in 2026 or so.
1028-
const jsonMimeConverter = (fileType) => fileType == 'application/json' ? 'application/octet-stream' : fileType;
1028+
const jsonMimeConverter = (fileType) => fileType === DRAFTY_FR_MIME_TYPE_LEGACY ? 'application/octet-stream' : fileType;
10291029

10301030
if (file.size > maxInbandAttachmentSize) {
10311031
// Too large to send inband - uploading out of band and sending as a link.

src/widgets/chat-message.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ class BaseChatMessage extends React.PureComponent {
162162
const attachments = [];
163163
if (this.props.mimeType == Drafty.getContentType() && Drafty.isValid(content)) {
164164
Drafty.attachments(content, (att, i) => {
165-
if (att.mime == 'application/json+drafty' ||
166-
att.mime == 'application/json') {
165+
if (Drafty.isFormResponseType(att.mime)) {
167166
// Don't show json drafty form response objects as attachments.
168167
// They are not meant for users.
169168
return;

umd/index.dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7230,6 +7230,7 @@ __webpack_require__.r(__webpack_exports__);
72307230
/* harmony export */ CLICKABLE_URL_SCHEMES: function() { return /* binding */ CLICKABLE_URL_SCHEMES; },
72317231
/* harmony export */ DEFAULT_HOST: function() { return /* binding */ DEFAULT_HOST; },
72327232
/* harmony export */ DEFAULT_P2P_ACCESS_MODE: function() { return /* binding */ DEFAULT_P2P_ACCESS_MODE; },
7233+
/* harmony export */ DRAFTY_FR_MIME_TYPE_LEGACY: function() { return /* binding */ DRAFTY_FR_MIME_TYPE_LEGACY; },
72337234
/* harmony export */ EDIT_PREVIEW_LENGTH: function() { return /* binding */ EDIT_PREVIEW_LENGTH; },
72347235
/* harmony export */ FORWARDED_PREVIEW_LENGTH: function() { return /* binding */ FORWARDED_PREVIEW_LENGTH; },
72357236
/* harmony export */ IMAGE_PREVIEW_DIM: function() { return /* binding */ IMAGE_PREVIEW_DIM; },
@@ -7326,6 +7327,7 @@ const WAKE_UP_TICK = 1000;
73267327
const MIN_SWIPE_DISTANCE = REM_SIZE * 3;
73277328
const SELF_AVATAR_URI = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZpZXdCb3g9IjAgMCAxNyAxNyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMy41NjIgMXYxNS40NTlsNC42ODYtMy4yNyA0Ljc1MiAzLjI2di0xNS40NDloLTkuNDM4ek0xMiAxNC41NTFsLTMuNzU2LTIuNTc4LTMuNjgxIDIuNTY4di0xMi41NDFoNy40Mzd2MTIuNTUxeiIgZmlsbD0iIzU1NTU1NSIgLz48L3N2Zz4=';
73287329
const TOAST_DURATION = 3_000;
7330+
const DRAFTY_FR_MIME_TYPE_LEGACY = 'application/json';
73297331

73307332
/***/ }),
73317333

@@ -7712,8 +7714,6 @@ const messages = (0,react_intl__WEBPACK_IMPORTED_MODULE_1__.defineMessages)({
77127714
}]
77137715
}
77147716
});
7715-
const JSON_MIME_TYPE = 'application/json+drafty';
7716-
const JSON_MIME_TYPE_LEGACY = 'application/json';
77177717
function fullFormatter(style, data, values, key, stack) {
77187718
if (stack.includes('QQ')) {
77197719
return quoteFormatter.call(this, style, data, values, key);
@@ -7939,7 +7939,7 @@ function previewFormatter(style, data, values, key) {
79397939
break;
79407940
case 'EX':
79417941
if (data) {
7942-
if (data.mime == JSON_MIME_TYPE || data.mime == JSON_MIME_TYPE_LEGACY) {
7942+
if (tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.isFormResponseType(data.mime)) {
79437943
return null;
79447944
}
79457945
delete data.val;
@@ -8058,7 +8058,7 @@ function quoteFormatter(style, data, values, key) {
80588058
case 'EX':
80598059
let fname;
80608060
if (data) {
8061-
if (data.mime == JSON_MIME_TYPE || data.mime == JSON_MIME_TYPE_LEGACY) {
8061+
if (tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.isFormResponseType(data.mime)) {
80628062
return null;
80638063
}
80648064
fname = data.name;
@@ -11156,7 +11156,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
1115611156
}
1115711157
sendFileAttachment(file) {
1115811158
const maxInbandAttachmentSize = this.props.tinode.getServerParam('maxMessageSize', _config_js__WEBPACK_IMPORTED_MODULE_18__.MAX_INBAND_ATTACHMENT_SIZE) * 0.75 - 1024 | 0;
11159-
const jsonMimeConverter = fileType => fileType == 'application/json' ? 'application/octet-stream' : fileType;
11159+
const jsonMimeConverter = fileType => fileType === _config_js__WEBPACK_IMPORTED_MODULE_18__.DRAFTY_FR_MIME_TYPE_LEGACY ? 'application/octet-stream' : fileType;
1116011160
if (file.size > maxInbandAttachmentSize) {
1116111161
const uploader = this.props.tinode.getLargeFileHelper();
1116211162
if (!uploader) {
@@ -16517,7 +16517,7 @@ class BaseChatMessage extends (react__WEBPACK_IMPORTED_MODULE_0___default().Pure
1651716517
const attachments = [];
1651816518
if (this.props.mimeType == tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.getContentType() && tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.isValid(content)) {
1651916519
tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.attachments(content, (att, i) => {
16520-
if (att.mime == 'application/json+drafty' || att.mime == 'application/json') {
16520+
if (tinode_sdk__WEBPACK_IMPORTED_MODULE_2__.Drafty.isFormResponseType(att.mime)) {
1652116521
return;
1652216522
}
1652316523
attachments.push(react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_attachment_jsx__WEBPACK_IMPORTED_MODULE_3__["default"], {

umd/index.dev.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

umd/index.prod.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

umd/index.prod.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)