Skip to content

Commit

Permalink
feat(type): define chat type
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 29, 2022
1 parent 13d0178 commit 174fb02
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions services/comment/src/lib/type.ts → core/type/src/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AlwatrDocumentObject} from '@alwatr/type';
import type {AlwatrDocumentObject} from './storage.js';

type CommonMessage = AlwatrDocumentObject & {
user: unknown;
from: unknown;
replyId?: string;
};

Expand Down
1 change: 1 addition & 0 deletions core/type/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './storage.js';
export * from './service.js';
export * from './alwatr.js';
export * from './math.js';
export * from './chat.js';

// FIXME:
export type MaybePromise<T> = T | Promise<T>
Expand Down
4 changes: 3 additions & 1 deletion services/comment/src/lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {AlwatrStorageClient} from '@alwatr/storage-client';

import {config} from '../config.js';
import {Message} from './type.js';

import type {Message} from '@alwatr/type';


export const storageClient = new AlwatrStorageClient<Message>(config.storage);
3 changes: 1 addition & 2 deletions services/comment/src/route/patch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {config, logger} from '../config.js';
import {nanoServer} from '../lib/nano-server.js';
import {storageClient} from '../lib/storage.js';
import {Message} from '../lib/type.js';

import type {AlwatrConnection} from '@alwatr/nano-server';
import type {AlwatrServiceResponse} from '@alwatr/type';
import type {Message, AlwatrServiceResponse} from '@alwatr/type';

nanoServer.route('PATCH', '/', setComment);

Expand Down
1 change: 0 additions & 1 deletion ui/demo-pwa/src/director/comment-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {AlwatrDocumentStorage} from '@alwatr/type';

export const commentDocumentStorageSignal = new SignalInterface('comment-document-storage');


async function requestCommentStorage(cacheStrategy: CacheStrategy): Promise<void> {
// logger.logMethod('jobListProvider');
console.log('jobListProvider');
Expand Down
12 changes: 4 additions & 8 deletions ui/demo-pwa/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/type';
import {TextMessage} from '@alwatr/type';

import type {AlwatrDocumentStorage} from '@alwatr/type';

declare global {
interface AlwatrSignals {
'comment-document-storage': AlwatrDocumentStorage<ChatMessage>;
}
}

export type ChatTextMessage = {
export type ChatMessage = TextMessage & {
from: string;
type: 'text';
text: string;
};

export type _ChatMessage = ChatTextMessage; // TODO: ChatPhotoMessage

export type ChatMessage = AlwatrDocumentObject & _ChatMessage;
5 changes: 2 additions & 3 deletions ui/ui-kit/src/chat/chat-list.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {AlwatrDummyElement, css, customElement, html, nothing, property} from '@alwatr/element';
import './chat-message.js';

import type {ChatMessage as _ChatMessage} from './chat-message.js';
import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/type';
import type {ChatMessage} from './chat-message.js';
import type {AlwatrDocumentStorage} from '@alwatr/type';

declare global {
interface HTMLElementTagNameMap {
'alwatr-chat-list': AlwatrChatList;
}
}

export type ChatMessage = AlwatrDocumentObject & _ChatMessage;
export type ChatStorage = AlwatrDocumentStorage<ChatMessage>;

export function* map<T>(
Expand Down
11 changes: 5 additions & 6 deletions ui/ui-kit/src/chat/chat-message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {AlwatrDummyElement, css, customElement, html, nothing, property} from '@alwatr/element';

import type {TextMessage} from '@alwatr/type';
import './chat-avatar.js';
import './chat-bubble.js';

Expand All @@ -8,14 +10,11 @@ declare global {
}
}

export type ChatTextMessage = {
// TODO: ChatPhotoMessage
export type ChatMessage = TextMessage & {
from: string;
type: 'text';
text: string;
};

export type ChatMessage = ChatTextMessage; // TODO: ChatPhotoMessage

/**
* Alwatr chat message box element.
*
Expand Down Expand Up @@ -63,7 +62,7 @@ export class AlwatrChatMessage extends AlwatrDummyElement {
`;

@property({type: Object, attribute: false})
message?: ChatTextMessage;
message?: ChatMessage;

@property({type: Boolean, attribute: 'self', reflect: true})
self = false;
Expand Down

0 comments on commit 174fb02

Please sign in to comment.