Ported MessagesView to V3
This commit is contained in:
@@ -13,24 +13,24 @@
|
|||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
@if (serviceManager.currentSession != null) {
|
@if (serviceManager.currentSession != null) {
|
||||||
@for (message of messages(); track message.msgid; let i = $index) {
|
@for (message of messages(); track message.messageId; let i = $index) {
|
||||||
<div
|
<div
|
||||||
class="message"
|
class="message"
|
||||||
[class.author]="
|
[class.author]="
|
||||||
messageAsDm(message).author == serviceManager.currentSession()!.userData.userid ||
|
messageAsDm(message).author.userId == sessionManager.userData()?.userId ||
|
||||||
messageAsNetwork(message).author.userid == serviceManager.currentSession()!.userData.userid
|
messageAsNetwork(message).author.userId == sessionManager.userData()?.userId
|
||||||
"
|
"
|
||||||
[class.chained_start]="isMessageStartOfChain(i)"
|
[class.chained_start]="isMessageStartOfChain(i)"
|
||||||
[class.chained_middle]="isMessageMiddleInChain(i)"
|
[class.chained_middle]="isMessageMiddleInChain(i)"
|
||||||
[class.chained_end]="isMessageEndOfChain(i)"
|
[class.chained_end]="isMessageEndOfChain(i)"
|
||||||
>
|
>
|
||||||
<div class="above">
|
<div class="above">
|
||||||
<span>{{ message.sent_at.T * 1000 | date: 'HH:mm' }}</span>
|
<span>{{ message.sentAt | date: 'HH:mm' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bubble" tuiDropdownContext [tuiDropdown]="messageContextMenu">
|
<div class="bubble" tuiDropdownContext [tuiDropdown]="messageContextMenu">
|
||||||
<span class="message-text">{{ message.message }}</span>
|
<span class="message-text">{{ message.content }}</span>
|
||||||
<masonry style="max-height: 300px">
|
<!-- <masonry style="max-height: 300px">
|
||||||
@for (file of filterExpressedMedia(message.files); track file) {
|
@for (file of filterExpressedMedia(message.attachments); track file) {
|
||||||
<div style="position:relative;">
|
<div style="position:relative;">
|
||||||
@if (file.extraMetaData && Object.keys(file.extraMetaData).length > 0) {
|
@if (file.extraMetaData && Object.keys(file.extraMetaData).length > 0) {
|
||||||
@if (file.extraMetaData['progressShown']) {
|
@if (file.extraMetaData['progressShown']) {
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
<span>{{ file.fileName }}</span>
|
<span>{{ file.fileName }}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>-->
|
||||||
</div>
|
</div>
|
||||||
<div class="below"></div>
|
<div class="below"></div>
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
tuiOption
|
tuiOption
|
||||||
type="button"
|
type="button"
|
||||||
iconEnd="@tui.pencil"
|
iconEnd="@tui.pencil"
|
||||||
(click)="messageBoxViewModel().editingMessage.set({message: message.message, messageId: message.msgid}); messageBoxViewModel().message.set(message.message);"
|
(click)="messageBoxViewModel().editingMessage.set({content: message.content, messageId: message.messageId}); messageBoxViewModel().message.set(message.content??'');"
|
||||||
>
|
>
|
||||||
{{ "chat.elements.messages.contextMenu.edit" | translate }}
|
{{ "chat.elements.messages.contextMenu.edit" | translate }}
|
||||||
</button>
|
</button>
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
tuiOption
|
tuiOption
|
||||||
type="button"
|
type="button"
|
||||||
iconEnd="@tui.trash"
|
iconEnd="@tui.trash"
|
||||||
(click)="onDelete.emit(message.msgid)"
|
(click)="onDelete.emit(message.messageId)"
|
||||||
>
|
>
|
||||||
{{ "chat.elements.messages.contextMenu.delete" | translate }}
|
{{ "chat.elements.messages.contextMenu.delete" | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import {Component, EventEmitter, inject, input, Output} from '@angular/core';
|
import { Component, EventEmitter, inject, input, Output } from '@angular/core';
|
||||||
import {Message} from '@chatenium/chatenium-sdk/domain/dmService.schema';
|
import { Message, ThreadMessage, Attachment, ThreadMessageAttachment } from 'chatenium-sdk-preview';
|
||||||
import {Message as NetworkMessage} from '@chatenium/chatenium-sdk/domain/textChannelService.schema'
|
import { ServiceManager } from '../../../service-manager';
|
||||||
import {ServiceManager} from '../../../service-manager';
|
import { DatePipe } from '@angular/common';
|
||||||
import {DatePipe} from '@angular/common';
|
import { Masonry } from '../masonry/masonry';
|
||||||
import {Masonry} from '../masonry/masonry';
|
import { VideoPlayer } from '../video-player/video-player';
|
||||||
import {VideoPlayer} from '../video-player/video-player';
|
|
||||||
import {
|
import {
|
||||||
TuiButton,
|
TuiButton,
|
||||||
TuiDataListComponent,
|
TuiDataListComponent,
|
||||||
@@ -12,13 +11,12 @@ import {
|
|||||||
TuiDropdownContext,
|
TuiDropdownContext,
|
||||||
TuiGroup,
|
TuiGroup,
|
||||||
TuiIcon,
|
TuiIcon,
|
||||||
TuiOption
|
TuiOption,
|
||||||
} from '@taiga-ui/core';
|
} from '@taiga-ui/core';
|
||||||
import {TranslatePipe} from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import {MessageBoxViewModel} from '../message-box/message-box-viewmodel';
|
import { MessageBoxViewModel } from '../message-box/message-box-viewmodel';
|
||||||
import {FileDataWithPreview} from '../message-box/message-box';
|
import { TuiProgressCircle, TuiSkeleton } from '@taiga-ui/kit';
|
||||||
import {Attachment} from '@chatenium/chatenium-sdk/domain/common.schema';
|
import { SessionManager } from '../../../session-manager';
|
||||||
import {TuiProgressCircle, TuiSkeleton} from '@taiga-ui/kit';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'messages',
|
selector: 'messages',
|
||||||
@@ -35,27 +33,28 @@ import {TuiProgressCircle, TuiSkeleton} from '@taiga-ui/kit';
|
|||||||
TuiGroup,
|
TuiGroup,
|
||||||
TuiIcon,
|
TuiIcon,
|
||||||
TuiProgressCircle,
|
TuiProgressCircle,
|
||||||
TuiSkeleton
|
TuiSkeleton,
|
||||||
],
|
],
|
||||||
templateUrl: './messages.html',
|
templateUrl: './messages.html',
|
||||||
styleUrl: './messages.scss',
|
styleUrl: './messages.scss',
|
||||||
})
|
})
|
||||||
export class Messages {
|
export class Messages {
|
||||||
serviceManager = inject(ServiceManager)
|
serviceManager = inject(ServiceManager);
|
||||||
|
sessionManager = inject(SessionManager);
|
||||||
|
|
||||||
messages = input.required<Message[] | NetworkMessage[]>()
|
messages = input.required<Message[] | ThreadMessage[]>();
|
||||||
messageBoxViewModel = input.required<MessageBoxViewModel>()
|
messageBoxViewModel = input.required<MessageBoxViewModel>();
|
||||||
loading = input(false)
|
loading = input(false);
|
||||||
|
|
||||||
@Output() onDelete = new EventEmitter<string>()
|
@Output() onDelete = new EventEmitter<string>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps code readability by specifying what type of messages are being processed.
|
* Helps code readability by specifying what type of messages are being processed.
|
||||||
* Example: messageAsDm(message).author == userid -- We are specifying that we are handling dm messages
|
* Example: messageAsDm(message).author == userid -- We are specifying that we are handling dm messages
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
messageAsDm(message: Message | NetworkMessage) {
|
messageAsDm(message: Message | ThreadMessage) {
|
||||||
return message == undefined ? <Message>{author: "no"} : message as Message
|
return message as Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,8 +62,8 @@ export class Messages {
|
|||||||
Example: messageAsNetwork(message).author.userid == userid -- We are specifying that we are handling network messages
|
Example: messageAsNetwork(message).author.userid == userid -- We are specifying that we are handling network messages
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
messageAsNetwork(message: Message | NetworkMessage) {
|
messageAsNetwork(message: Message | ThreadMessage) {
|
||||||
return message == undefined ? <NetworkMessage>{author: {userid: "no"}} : message as NetworkMessage
|
return message as ThreadMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMessageStartOfChain(i: number) {
|
isMessageStartOfChain(i: number) {
|
||||||
@@ -76,16 +75,17 @@ export class Messages {
|
|||||||
// is author == last msg's author
|
// is author == last msg's author
|
||||||
if (prev) {
|
if (prev) {
|
||||||
if (
|
if (
|
||||||
(typeof message.author === 'string' && this.messageAsDm(prev).author !== this.messageAsDm(message).author) &&
|
typeof message.author === 'string' &&
|
||||||
this.messageAsNetwork(prev).author.userid !== this.messageAsNetwork(message).author.userid
|
this.messageAsDm(prev).author.userId !== this.messageAsDm(message).author.userId &&
|
||||||
|
this.messageAsNetwork(prev).author.userId !== this.messageAsNetwork(message).author.userId
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// same author but time gap between this and prev msg
|
// same author but time gap between this and prev msg
|
||||||
if (
|
const currMsgDate = new Date(message.sentAt);
|
||||||
Math.abs(message.sent_at.T - prev.sent_at.T) >= 60
|
const prevMsgDate = new Date(prev.sentAt);
|
||||||
) {
|
if (Math.abs(currMsgDate.getDate() - prevMsgDate.getDate()) >= 60_000) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,12 +100,14 @@ export class Messages {
|
|||||||
const prev = this.messages()[i - 1];
|
const prev = this.messages()[i - 1];
|
||||||
|
|
||||||
// message must be from the same author and have little time gap between
|
// message must be from the same author and have little time gap between
|
||||||
|
const currMsgDate = new Date(message.sentAt);
|
||||||
|
const prevMsgDate = new Date(prev.sentAt);
|
||||||
return (
|
return (
|
||||||
(
|
((typeof message.author === 'string' &&
|
||||||
(typeof message.author === 'string' && this.messageAsDm(prev).author == this.messageAsDm(message).author) ||
|
this.messageAsDm(prev).author == this.messageAsDm(message).author) ||
|
||||||
this.messageAsNetwork(prev).author.userid == this.messageAsNetwork(message).author.userid
|
this.messageAsNetwork(prev).author.userId ==
|
||||||
) &&
|
this.messageAsNetwork(message).author.userId) &&
|
||||||
Math.abs(message.sent_at.T - prev.sent_at.T) <= 60
|
Math.abs(currMsgDate.getDate() - prevMsgDate.getDate()) <= 60_000
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,19 +120,20 @@ export class Messages {
|
|||||||
|
|
||||||
const next = this.messages()[i + 1];
|
const next = this.messages()[i + 1];
|
||||||
|
|
||||||
|
const currMsgDate = new Date(message.sentAt);
|
||||||
|
const nextMsgDate = new Date(next.sentAt);
|
||||||
// First condition: next author is different
|
// First condition: next author is different
|
||||||
if (next) {
|
if (next) {
|
||||||
if (
|
if (
|
||||||
(typeof message.author === 'string' && this.messageAsDm(next).author != this.messageAsDm(message).author) ||
|
(typeof message.author === 'string' &&
|
||||||
this.messageAsNetwork(next).author.userid != this.messageAsNetwork(message).author.userid
|
this.messageAsDm(next).author != this.messageAsDm(message).author) ||
|
||||||
|
this.messageAsNetwork(next).author.userId != this.messageAsNetwork(message).author.userId
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// same author but time gap between this and next msg
|
// same author but time gap between this and next msg
|
||||||
if (
|
if (Math.abs(currMsgDate.getDate() - nextMsgDate.getDate()) >= 60) {
|
||||||
Math.abs(message.sent_at.T - next.sent_at.T) >= 60
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,12 +142,16 @@ export class Messages {
|
|||||||
return i + 1 === this.messages().length;
|
return i + 1 === this.messages().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
filterExpressedMedia(files: Attachment[]) {
|
filterExpressedMedia(files: Attachment[] | ThreadMessageAttachment[] | undefined) {
|
||||||
return files.filter(f => f.type == "image" || f.type == "video")
|
return files
|
||||||
|
? files.filter((f) => f.mimeType.startsWith('image') || f.mimeType.startsWith('video'))
|
||||||
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
filterNonExpressedMedia(files: Attachment[]) {
|
filterNonExpressedMedia(files: Attachment[] | ThreadMessageAttachment[] | undefined) {
|
||||||
return files.filter(f => f.type != "image" && f.type != "video")
|
return files
|
||||||
|
? files.filter((f) => f.mimeType.startsWith('image') || f.mimeType.startsWith('video'))
|
||||||
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly Object = Object;
|
protected readonly Object = Object;
|
||||||
|
|||||||
Reference in New Issue
Block a user