Skip to content

Commit

Permalink
Create required components
Browse files Browse the repository at this point in the history
  • Loading branch information
hv0905 committed Nov 2, 2024
1 parent 0152b14 commit ab0990a
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/message-protocol-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"type": "image",
"content": {
"file": "/path/to/probe/file",
"alt": "Image alt text (optional)"
"alt": "Image alt text (optional)",
"width": 100,
"height": 100
}
},
{
Expand Down
11 changes: 11 additions & 0 deletions src/app/Controllers/MessageSegments/mseg-file.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, input } from "@angular/core";
import { MessageSegmentFile } from "../../Models/Messages/MessageSegments";

@Component({
selector: 'app-mseg-text',
templateUrl: '../../Views/MessageSegments/mseg-file.html',
// styleUrls: ['../../Styles/MessageSegments/message-segment-text.scss']
})
export class MessageSegmentFileComponent {
context = input.required<MessageSegmentFile>();
}
11 changes: 11 additions & 0 deletions src/app/Controllers/MessageSegments/mseg-img.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, input } from "@angular/core";
import { MessageSegmentImage } from "../../Models/Messages/MessageSegments";

@Component({
selector: 'app-mseg-img',
templateUrl: '../../Views/MessageSegments/mseg-img.html',
// styleUrls: ['../../Styles/MessageSegments/message-segment-text.scss']
})
export class MessageSegmentImgComponent {
context = input.required<MessageSegmentImage>();
}
11 changes: 11 additions & 0 deletions src/app/Controllers/MessageSegments/mseg-text.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, input } from "@angular/core";
import { MessageSegmentText } from "../../Models/Messages/MessageSegments";

@Component({
selector: 'app-mseg-text',
templateUrl: '../../Views/MessageSegments/mseg-text.html',
// styleUrls: ['../../Styles/MessageSegments/message-segment-text.scss']
})
export class MessageSegmentTextComponent {
context = input.required<MessageSegmentText>();
}
11 changes: 11 additions & 0 deletions src/app/Controllers/MessageSegments/mseg-video.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, input } from "@angular/core";
import { MessageSegmentVideo } from "../../Models/Messages/MessageSegments";

@Component({
selector: 'app-mseg-video',
templateUrl: '../../Views/MessageSegments/mseg-video.html',
// styleUrls: ['../../Styles/MessageSegments/message-segment-text.scss']
})
export class MessageSegmentVideoComponent {
context = input.required<MessageSegmentVideo>();
}
11 changes: 11 additions & 0 deletions src/app/Controllers/MessageSegments/mseg-voice.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, input } from "@angular/core";
import { MessageSegmentVoice } from "../../Models/Messages/MessageSegments";

@Component({
selector: 'app-mseg-voice',
templateUrl: '../../Views/MessageSegments/mseg-voice.html',
// styleUrls: ['../../Styles/MessageSegments/message-segment-text.scss']
})
export class MessageSegmentVoiceComponent {
context = input.required<MessageSegmentVoice>();
}
1 change: 0 additions & 1 deletion src/app/Controllers/advanced-setting.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class AdvancedSettingComponent implements OnInit {
.subscribe(
() => {
this.updatingSetting = null;
this.cacheService.cachedData.me = Object.assign({}, this.me);
this.cacheService.cachedData.options = Object.assign({}, this.options);
this.cacheService.saveCache();
},
Expand Down
14 changes: 14 additions & 0 deletions src/app/Controllers/message.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, input } from '@angular/core';
import { Message } from '../Models/Message';

@Component({
selector: 'app-message',
templateUrl: '../Views/message.html',
})
export class MessageComponent {
message = input.required<Message>();
isByMe = input<boolean>(false);
groupWithPrevious = input<boolean>(false);
isSending = input<boolean>(false);
isFailed = input<boolean>(false);
}
6 changes: 6 additions & 0 deletions src/app/Models/Messages/MessageContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { MessageSegmentBase } from "./MessageSegments";

export interface MessageContent {
preview?: string;
segments: MessageSegmentBase[];
}
63 changes: 63 additions & 0 deletions src/app/Models/Messages/MessageSegments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export type MessageSegmentTypes = (
| MessageSegmentText
| MessageSegmentImage
| MessageSegmentVideo
| MessageSegmentVoice
| MessageSegmentFile
| MessageSegmentContact
| MessageSegmentThreadInvitation
| MessageSegmentThreadJoinRequest
)['type'];

export interface MessageSegmentBase {
type: MessageSegmentTypes;
}

export interface MessageSegmentText extends MessageSegmentBase {
type: 'text';
content: string;
}

interface MessageSegmentFileLike<TName extends MessageSegmentTypes> extends MessageSegmentBase {
type: TName;
url: string;
}

export interface MessageSegmentImage extends MessageSegmentFileLike<'image'> {
width: number;
height: number;
alt?: string;
}

export type MessageSegmentVideo = MessageSegmentFileLike<'video'>;

export interface MessageSegmentVoice extends MessageSegmentFileLike<'voice'> {
duration: number;
}

export interface MessageSegmentFile extends MessageSegmentFileLike<'file'> {
fileName: string;
size: number;
}

export interface MessageSegmentContact extends MessageSegmentBase {
type: 'contact';
id: string;
nickname: string;
avatarUrl: string;
bio: string;
}

export interface MessageSegmentThreadInvitation extends MessageSegmentBase {
type: 'thread-invitation';
id: string;
token: string;
validTo: Date;
}

export interface MessageSegmentThreadJoinRequest extends MessageSegmentBase {
type: 'thread-join-request';
id: string;
token: string;
validTo: Date;
}
8 changes: 4 additions & 4 deletions src/app/Utils/Typing.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Example input: <{a: string, b: boolean, c: number, d: boolean}, boolean>
* Example output: {b: boolean, d: boolean}
* Example input: `<{a: string, b: boolean, c: number, d: boolean}, boolean>`
* Example output: `{b: boolean, d: boolean}`
*/
export type PropertiesWithType<T, P> = {
[K in keyof T as T[K] extends P ? K : never]: T[K];
};

/**
* Example input: <{a: string, b: boolean, c: number, d: boolean}, boolean>
* Example output: 'b' | 'd'
* Example input: `<{a: string, b: boolean, c: number, d: boolean}, boolean>`
* Example output: `'b' | 'd'`
*/
export type PropertryNamesWithType<T, P> = keyof PropertiesWithType<T, P>;
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added src/app/Views/message.html
Empty file.
14 changes: 13 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ import { ToggleMenuItemComponent } from './Controllers/toggle-menu-item.componen
import { NewThreadComponent } from './Controllers/new-thread.component';
import { IconForFilePipe } from './Pipes/icon-for-file.pipe';
import { ThreadAvatarComponent } from './Controllers/thread-avatar.component';
import { MessageSegmentTextComponent } from './Controllers/MessageSegments/mseg-text.component';
import { MessageSegmentImgComponent } from './Controllers/MessageSegments/mseg-img.component';
import { MessageSegmentVideoComponent } from './Controllers/MessageSegments/mseg-video.component';
import { MessageSegmentVoiceComponent } from './Controllers/MessageSegments/mseg-voice.component';
import { MessageSegmentFileComponent } from './Controllers/MessageSegments/mseg-file.component';
import { MessageComponent } from './Controllers/message.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -107,7 +113,13 @@ import { ThreadAvatarComponent } from './Controllers/thread-avatar.component';
ThreadOptionsComponent,
ToggleMenuItemComponent,
NewThreadComponent,
ThreadAvatarComponent
ThreadAvatarComponent,
MessageComponent,
MessageSegmentTextComponent,
MessageSegmentImgComponent,
MessageSegmentVideoComponent,
MessageSegmentVoiceComponent,
MessageSegmentFileComponent,
],
providers: [
ApiService,
Expand Down

0 comments on commit ab0990a

Please sign in to comment.