Skip to content

Commit 7b73cac

Browse files
authored
fix: remove pinned_at from the updateMessage api (#1484)
## CLA - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested ## Description of the changes, What, Why and How? Whenever using the `updateMessage` API, we rely on updating the entire message object with most of its values left unchanged and only some of them mutating. This generally works fine as the backend does updates in a smart way (i.e it won't update a field if its value hasn't changed). However, since natively Javascript dates go down to milliseconds and server-side they are stored until microseconds, there is a discrepancy between these 2 values and the `pinned_at` value is considered different; hence causing things to malfunction. For example, if a user does not have pinning permissions in a specific channel and someone else pins a message, they won't be able to update it due to the fact that it will be considered as an update to the `pinned_at` date as well - throwing an error. Similarly to how we handle other dates (`created_at`, `updated_at` etc), we disregard this value for the time being. For a more long-term solution, it would be prudent if we: - Store dates as strings and only convert them to dates whenever needed (this still has some odd edge cases that we'd need to take into account) - Possibly rely on `partialUpdateMessage` rather than `updateMessage` for features like message editing in order to avoid broken behaviour (however, using the vanilla API would still not work) So, for the time being we ignore `pinned_at` from the API. More information in [this Slack thread](https://getstream.slack.com/archives/C04SDJ3BC6Q/p1739524298745469). ## Changelog -
1 parent ffcf1d5 commit 7b73cac

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
27052705
'type',
27062706
'updated_at',
27072707
'user',
2708+
'pinned_at',
27082709
'__html',
27092710
];
27102711

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,7 @@ export type ReservedMessageFields =
28962896
| 'reply_count'
28972897
| 'type'
28982898
| 'updated_at'
2899+
| 'pinned_at'
28992900
| 'user'
29002901
| '__html';
29012902

test/unit/client.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,14 @@ describe('Client deleteUsers', () => {
388388
});
389389
});
390390

391-
describe('updateMessage should ensure sanity of `mentioned_users`', () => {
391+
describe('updateMessage should maintain data integrity', () => {
392+
let client;
393+
394+
beforeEach(async () => {
395+
client = await getClientWithUser();
396+
});
397+
392398
it('should convert mentioned_users from array of user objects to array of userIds', async () => {
393-
const client = await getClientWithUser();
394399
client.post = (url, config) => {
395400
expect(typeof config.message.mentioned_users[0]).to.be.equal('string');
396401
expect(config.message.mentioned_users[0]).to.be.equal('uthred');
@@ -414,7 +419,6 @@ describe('updateMessage should ensure sanity of `mentioned_users`', () => {
414419
});
415420

416421
it('should allow empty mentioned_users', async () => {
417-
const client = await getClientWithUser();
418422
client.post = (url, config) => {
419423
expect(config.message.mentioned_users[0]).to.be.equal(undefined);
420424
};
@@ -436,6 +440,29 @@ describe('updateMessage should ensure sanity of `mentioned_users`', () => {
436440
}),
437441
);
438442
});
443+
444+
it('should remove reserved and volatile fields before running the update', async () => {
445+
const postSpy = sinon.stub(client, 'post');
446+
const updatedMessage = generateMsg({
447+
text: 'test message',
448+
pinned_at: new Date().toISOString(),
449+
mentioned_users: undefined,
450+
});
451+
452+
await client.updateMessage(updatedMessage);
453+
454+
const messageInQuery = {
455+
attachments: updatedMessage.attachments,
456+
mentioned_users: updatedMessage.mentioned_users,
457+
reaction_counts: updatedMessage.reaction_counts,
458+
reaction_scores: updatedMessage.reaction_scores,
459+
silent: updatedMessage.silent,
460+
status: updatedMessage.status,
461+
text: updatedMessage.text,
462+
};
463+
464+
expect(postSpy.args[0][1].message).to.deep.equal(messageInQuery);
465+
});
439466
});
440467

441468
describe('Client search', async () => {

0 commit comments

Comments
 (0)