Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,20 @@ describe('AttachmentListComponent', () => {
} as any as Attachment<DefaultStreamChatGenerics>;
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,17 @@ describe('ChannelService - threads', () => {
{} as any as SendMessageAPIResponse<DefaultStreamChatGenerics>
);
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,
});
});

Expand Down
26 changes: 13 additions & 13 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>) {
async sendAction(
messageId: string,
formData: Record<string, string>,
parentMessageId?: string
) {
const channel = this.activeChannelSubject.getValue()!;
const response = await channel.sendAction(messageId, formData);
if (response?.message) {
Expand All @@ -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]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@
#defaultAttachments
let-messageId="messageId"
let-attachments="attachments"
let-parentMessageId="parentMessageId"
>
<stream-attachment-list
[messageId]="messageId"
[attachments]="attachments"
[parentMessageId]="parentMessageId"
></stream-attachment-list>
</ng-template>
<ng-container
Expand Down Expand Up @@ -382,14 +384,31 @@
[user]="message?.quoted_message?.user || undefined"
></stream-avatar-placeholder>
<div class="quoted-message-inner">
<stream-attachment-list
<ng-container
*ngIf="
message?.quoted_message?.attachments &&
message?.quoted_message?.attachments?.length
"
[attachments]="quotedMessageAttachments"
[messageId]="message?.quoted_message?.id"
></stream-attachment-list>
>
<ng-template
#defaultAttachments
let-messageId="messageId"
let-attachments="attachments"
let-parentMessageId="parentMessageId"
>
<stream-attachment-list
[messageId]="messageId"
[attachments]="attachments"
[parentMessageId]="parentMessageId"
></stream-attachment-list>
</ng-template>
<ng-container
*ngTemplateOutlet="
attachmentListTemplate || defaultAttachments;
context: getQuotedMessageAttachmentListContext()
"
></ng-container>
</ng-container>
<div
data-testid="quoted-message-text"
[innerHTML]="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ describe('MessageComponent', () => {
...message,
...{ attachments },
};
component.message.parent_id = 'parent-id';
fixture.detectChanges();
const attachmentComponent = queryAttachmentComponent();

Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
return {
messageId: this.message?.id || '',
attachments: this.message?.attachments || [],
parentMessageId: this.message?.parent_id,
};
}

getQuotedMessageAttachmentListContext(): AttachmentListContext {
return {
messageId: this.message?.quoted_message?.id || '',
attachments: this.quotedMessageAttachments,
parentMessageId: this?.message?.quoted_message?.parent_id,
};
}

Expand Down
1 change: 1 addition & 0 deletions projects/stream-chat-angular/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type ChannelActionsContext<
export type AttachmentListContext = {
messageId: string;
attachments: Attachment<DefaultStreamChatGenerics>[];
parentMessageId?: string;
};

export type AvatarType = 'channel' | 'user';
Expand Down