From b859c6f6b414105f95a472b6bf5fdc8915461536 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Tue, 12 Jul 2022 09:55:02 +0200 Subject: [PATCH 1/2] fix: Gifs not removed from threads #319 --- .../attachment-list.component.spec.ts | 11 +++++--- .../attachment-list.component.ts | 14 +++++++--- .../src/lib/channel.service.spec.ts | 5 +++- .../src/lib/channel.service.thread.spec.ts | 11 +++++--- .../src/lib/channel.service.ts | 26 +++++++++---------- .../src/lib/message/message.component.html | 3 +++ .../src/lib/message/message.component.spec.ts | 4 +++ .../src/lib/message/message.component.ts | 1 + projects/stream-chat-angular/src/lib/types.ts | 1 + 9 files changed, 53 insertions(+), 23 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts b/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts index 0bdc8288..f2596256 100644 --- a/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts +++ b/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts @@ -356,15 +356,20 @@ describe('AttachmentListComponent', () => { } as any as Attachment; component.messageId = 'message-id'; component.attachments = [attachment]; + component.parentMessageId = 'parent-id'; component.ngOnChanges(); fixture.detectChanges(); const actions = queryActions(); actions[1].click(); - expect(sendAction).toHaveBeenCalledWith('message-id', { - image_action: 'shuffle', - }); + expect(sendAction).toHaveBeenCalledWith( + 'message-id', + { + image_action: 'shuffle', + }, + 'parent-id' + ); }); describe('should display image attachment', () => { diff --git a/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts b/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts index 9f5e301b..6ae2d827 100644 --- a/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts +++ b/projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts @@ -26,6 +26,10 @@ export class AttachmentListComponent implements OnChanges { * The id of the message the attachments belong to */ @Input() messageId: string | undefined; + /** + * The parent id of the message the attachments belong to + */ + @Input() parentMessageId: string | undefined; /** * The attachments to display */ @@ -119,9 +123,13 @@ export class AttachmentListComponent implements OnChanges { } sendAction(action: Action) { - void this.channelService.sendAction(this.messageId!, { - [action.name!]: action.value!, - }); + void this.channelService.sendAction( + this.messageId!, + { + [action.name!]: action.value!, + }, + this.parentMessageId + ); } trackByActionValue(_: number, item: Action) { diff --git a/projects/stream-chat-angular/src/lib/channel.service.spec.ts b/projects/stream-chat-angular/src/lib/channel.service.spec.ts index e0440e1e..ef5c57a3 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.spec.ts @@ -983,7 +983,10 @@ describe('ChannelService', () => { spyOn(channel.state, 'removeMessage'); await service.sendAction('1', { image_action: 'send' }); - expect(channel.state.removeMessage).toHaveBeenCalledWith({ id: '1' }); + expect(channel.state.removeMessage).toHaveBeenCalledWith({ + id: '1', + parent_id: undefined, + }); }); it('should update message', () => { diff --git a/projects/stream-chat-angular/src/lib/channel.service.thread.spec.ts b/projects/stream-chat-angular/src/lib/channel.service.thread.spec.ts index 00eabf47..c6a7ca92 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.thread.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.thread.spec.ts @@ -529,12 +529,17 @@ describe('ChannelService - threads', () => { {} as any as SendMessageAPIResponse ); spyOn(channel.state, 'removeMessage'); - await service.sendAction(replies[replies.length - 1].id, { - image_action: 'send', - }); + await service.sendAction( + replies[replies.length - 1].id, + { + image_action: 'send', + }, + parentMessage.id + ); expect(channel.state.removeMessage).toHaveBeenCalledWith({ id: replies[replies.length - 1].id, + parent_id: parentMessage.id, }); }); diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts index 2c1d8fb4..40e572d2 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.ts @@ -695,8 +695,13 @@ export class ChannelService< * [Runs a message action](https://getstream.io/chat/docs/rest/#messages-runmessageaction) in the current channel. Updates the message list based on the action result (if no message is returned, the message will be removed from the message list). * @param messageId * @param formData + * @param parentMessageId */ - async sendAction(messageId: string, formData: Record) { + async sendAction( + messageId: string, + formData: Record, + parentMessageId?: string + ) { const channel = this.activeChannelSubject.getValue()!; const response = await channel.sendAction(messageId, formData); if (response?.message) { @@ -711,21 +716,16 @@ export class ChannelService< ]) : this.activeChannelMessagesSubject.next([...channel.state.messages]); } else { - channel.state.removeMessage({ id: messageId }); - if ( - this.activeChannelMessagesSubject - .getValue() - .find((m) => m.id === messageId) - ) { - this.activeChannelMessagesSubject.next([...channel.state.messages]); - } else if ( - this.activeThreadMessagesSubject - .getValue() - .find((m) => m.id === messageId) - ) { + channel.state.removeMessage({ + id: messageId, + parent_id: parentMessageId, + }); + if (parentMessageId) { this.activeThreadMessagesSubject.next( channel.state.threads[this.activeParentMessageIdSubject.getValue()!] ); + } else { + this.activeChannelMessagesSubject.next([...channel.state.messages]); } } } diff --git a/projects/stream-chat-angular/src/lib/message/message.component.html b/projects/stream-chat-angular/src/lib/message/message.component.html index 60b9201a..469bb3bc 100644 --- a/projects/stream-chat-angular/src/lib/message/message.component.html +++ b/projects/stream-chat-angular/src/lib/message/message.component.html @@ -160,10 +160,12 @@ #defaultAttachments let-messageId="messageId" let-attachments="attachments" + let-parentMessageId="parentMessageId" >
{ ...message, ...{ attachments }, }; + component.message!.parent_id = 'parent-id'; fixture.detectChanges(); const attachmentComponent = queryAttachmentComponent(); @@ -579,6 +580,9 @@ describe('MessageComponent', () => { expect(attachmentComponent).not.toBeUndefined(); expect(attachmentComponent.attachments).toBe(attachments); expect(attachmentComponent.messageId).toBe(component.message.id); + expect(attachmentComponent.parentMessageId).toBe( + component.message.parent_id + ); }); it('should display reactions icon, if user can react to message', () => { diff --git a/projects/stream-chat-angular/src/lib/message/message.component.ts b/projects/stream-chat-angular/src/lib/message/message.component.ts index 3c80ddba..6b96d33c 100644 --- a/projects/stream-chat-angular/src/lib/message/message.component.ts +++ b/projects/stream-chat-angular/src/lib/message/message.component.ts @@ -209,6 +209,7 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy { return { messageId: this.message?.id || '', attachments: this.message?.attachments || [], + parentMessageId: this.message?.parent_id, }; } diff --git a/projects/stream-chat-angular/src/lib/types.ts b/projects/stream-chat-angular/src/lib/types.ts index 587fbde4..f1ffc4ab 100644 --- a/projects/stream-chat-angular/src/lib/types.ts +++ b/projects/stream-chat-angular/src/lib/types.ts @@ -156,6 +156,7 @@ export type ChannelActionsContext< export type AttachmentListContext = { messageId: string; attachments: Attachment[]; + parentMessageId?: string; }; export type AvatarType = 'channel' | 'user'; From 4d0999291df3a7b736296f1d065a5c5762267fbf Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Tue, 12 Jul 2022 10:04:34 +0200 Subject: [PATCH 2/2] fix: Custom attachment list ignored inside quoted message --- .../src/lib/message/message.component.html | 26 +++++++++++++++---- .../src/lib/message/message.component.spec.ts | 2 +- .../src/lib/message/message.component.ts | 8 ++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/message/message.component.html b/projects/stream-chat-angular/src/lib/message/message.component.html index 469bb3bc..17c65e31 100644 --- a/projects/stream-chat-angular/src/lib/message/message.component.html +++ b/projects/stream-chat-angular/src/lib/message/message.component.html @@ -384,15 +384,31 @@ [user]="message?.quoted_message?.user || undefined" >
- + > + + + + +