Skip to content

Commit f81a848

Browse files
authored
Merge pull request #347 from GetStream/fix-gif-delete-in-threads
Fix gif delete in threads
2 parents 88b8f30 + 4d09992 commit f81a848

File tree

9 files changed

+81
-27
lines changed

9 files changed

+81
-27
lines changed

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,20 @@ describe('AttachmentListComponent', () => {
356356
} as any as Attachment<DefaultStreamChatGenerics>;
357357
component.messageId = 'message-id';
358358
component.attachments = [attachment];
359+
component.parentMessageId = 'parent-id';
359360
component.ngOnChanges();
360361
fixture.detectChanges();
361362

362363
const actions = queryActions();
363364
actions[1].click();
364365

365-
expect(sendAction).toHaveBeenCalledWith('message-id', {
366-
image_action: 'shuffle',
367-
});
366+
expect(sendAction).toHaveBeenCalledWith(
367+
'message-id',
368+
{
369+
image_action: 'shuffle',
370+
},
371+
'parent-id'
372+
);
368373
});
369374

370375
describe('should display image attachment', () => {

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class AttachmentListComponent implements OnChanges {
2626
* The id of the message the attachments belong to
2727
*/
2828
@Input() messageId: string | undefined;
29+
/**
30+
* The parent id of the message the attachments belong to
31+
*/
32+
@Input() parentMessageId: string | undefined;
2933
/**
3034
* The attachments to display
3135
*/
@@ -119,9 +123,13 @@ export class AttachmentListComponent implements OnChanges {
119123
}
120124

121125
sendAction(action: Action) {
122-
void this.channelService.sendAction(this.messageId!, {
123-
[action.name!]: action.value!,
124-
});
126+
void this.channelService.sendAction(
127+
this.messageId!,
128+
{
129+
[action.name!]: action.value!,
130+
},
131+
this.parentMessageId
132+
);
125133
}
126134

127135
trackByActionValue(_: number, item: Action) {

projects/stream-chat-angular/src/lib/channel.service.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,10 @@ describe('ChannelService', () => {
983983
spyOn(channel.state, 'removeMessage');
984984
await service.sendAction('1', { image_action: 'send' });
985985

986-
expect(channel.state.removeMessage).toHaveBeenCalledWith({ id: '1' });
986+
expect(channel.state.removeMessage).toHaveBeenCalledWith({
987+
id: '1',
988+
parent_id: undefined,
989+
});
987990
});
988991

989992
it('should update message', () => {

projects/stream-chat-angular/src/lib/channel.service.thread.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,17 @@ describe('ChannelService - threads', () => {
529529
{} as any as SendMessageAPIResponse<DefaultStreamChatGenerics>
530530
);
531531
spyOn(channel.state, 'removeMessage');
532-
await service.sendAction(replies[replies.length - 1].id, {
533-
image_action: 'send',
534-
});
532+
await service.sendAction(
533+
replies[replies.length - 1].id,
534+
{
535+
image_action: 'send',
536+
},
537+
parentMessage.id
538+
);
535539

536540
expect(channel.state.removeMessage).toHaveBeenCalledWith({
537541
id: replies[replies.length - 1].id,
542+
parent_id: parentMessage.id,
538543
});
539544
});
540545

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,13 @@ export class ChannelService<
695695
* [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).
696696
* @param messageId
697697
* @param formData
698+
* @param parentMessageId
698699
*/
699-
async sendAction(messageId: string, formData: Record<string, string>) {
700+
async sendAction(
701+
messageId: string,
702+
formData: Record<string, string>,
703+
parentMessageId?: string
704+
) {
700705
const channel = this.activeChannelSubject.getValue()!;
701706
const response = await channel.sendAction(messageId, formData);
702707
if (response?.message) {
@@ -711,21 +716,16 @@ export class ChannelService<
711716
])
712717
: this.activeChannelMessagesSubject.next([...channel.state.messages]);
713718
} else {
714-
channel.state.removeMessage({ id: messageId });
715-
if (
716-
this.activeChannelMessagesSubject
717-
.getValue()
718-
.find((m) => m.id === messageId)
719-
) {
720-
this.activeChannelMessagesSubject.next([...channel.state.messages]);
721-
} else if (
722-
this.activeThreadMessagesSubject
723-
.getValue()
724-
.find((m) => m.id === messageId)
725-
) {
719+
channel.state.removeMessage({
720+
id: messageId,
721+
parent_id: parentMessageId,
722+
});
723+
if (parentMessageId) {
726724
this.activeThreadMessagesSubject.next(
727725
channel.state.threads[this.activeParentMessageIdSubject.getValue()!]
728726
);
727+
} else {
728+
this.activeChannelMessagesSubject.next([...channel.state.messages]);
729729
}
730730
}
731731
}

projects/stream-chat-angular/src/lib/message/message.component.html

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@
160160
#defaultAttachments
161161
let-messageId="messageId"
162162
let-attachments="attachments"
163+
let-parentMessageId="parentMessageId"
163164
>
164165
<stream-attachment-list
165166
[messageId]="messageId"
166167
[attachments]="attachments"
168+
[parentMessageId]="parentMessageId"
167169
></stream-attachment-list>
168170
</ng-template>
169171
<ng-container
@@ -385,14 +387,31 @@
385387
[user]="message?.quoted_message?.user || undefined"
386388
></stream-avatar-placeholder>
387389
<div class="quoted-message-inner">
388-
<stream-attachment-list
390+
<ng-container
389391
*ngIf="
390392
message?.quoted_message?.attachments &&
391393
message?.quoted_message?.attachments?.length
392394
"
393-
[attachments]="quotedMessageAttachments"
394-
[messageId]="message?.quoted_message?.id"
395-
></stream-attachment-list>
395+
>
396+
<ng-template
397+
#defaultAttachments
398+
let-messageId="messageId"
399+
let-attachments="attachments"
400+
let-parentMessageId="parentMessageId"
401+
>
402+
<stream-attachment-list
403+
[messageId]="messageId"
404+
[attachments]="attachments"
405+
[parentMessageId]="parentMessageId"
406+
></stream-attachment-list>
407+
</ng-template>
408+
<ng-container
409+
*ngTemplateOutlet="
410+
attachmentListTemplate || defaultAttachments;
411+
context: getQuotedMessageAttachmentListContext()
412+
"
413+
></ng-container>
414+
</ng-container>
396415
<div
397416
data-testid="quoted-message-text"
398417
[innerHTML]="

projects/stream-chat-angular/src/lib/message/message.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ describe('MessageComponent', () => {
563563
...message,
564564
...{ attachments },
565565
};
566+
component.message.parent_id = 'parent-id';
566567
fixture.detectChanges();
567568
const attachmentComponent = queryAttachmentComponent();
568569

@@ -579,6 +580,9 @@ describe('MessageComponent', () => {
579580
expect(attachmentComponent).not.toBeUndefined();
580581
expect(attachmentComponent.attachments).toBe(attachments);
581582
expect(attachmentComponent.messageId).toBe(component.message.id);
583+
expect(attachmentComponent.parentMessageId).toBe(
584+
component.message.parent_id
585+
);
582586
});
583587

584588
it('should display reactions icon, if user can react to message', () => {

projects/stream-chat-angular/src/lib/message/message.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
209209
return {
210210
messageId: this.message?.id || '',
211211
attachments: this.message?.attachments || [],
212+
parentMessageId: this.message?.parent_id,
213+
};
214+
}
215+
216+
getQuotedMessageAttachmentListContext(): AttachmentListContext {
217+
return {
218+
messageId: this.message?.quoted_message?.id || '',
219+
attachments: this.quotedMessageAttachments,
220+
parentMessageId: this?.message?.quoted_message?.parent_id,
212221
};
213222
}
214223

projects/stream-chat-angular/src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type ChannelActionsContext<
156156
export type AttachmentListContext = {
157157
messageId: string;
158158
attachments: Attachment<DefaultStreamChatGenerics>[];
159+
parentMessageId?: string;
159160
};
160161

161162
export type AvatarType = 'channel' | 'user';

0 commit comments

Comments
 (0)