Skip to content
Open
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
7 changes: 4 additions & 3 deletions src/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@
<mat-icon [matBadgeHidden]="(ui.unreadNotifications$ | async) == 0" [matBadge]="ui.unreadNotifications$ | async">notifications</mat-icon>
<span *ngIf="displayLabels">{{ 'App.Notifications' | translate }}</span>
</a>
<!-- <a [routerLink]="['/chat']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
<a [routerLink]="['/chat']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
<mat-icon>chat</mat-icon>
<span *ngIf="displayLabels">Channels</span>
<span *ngIf="displayLabels">Chats</span>
</a>

<a [routerLink]="['/m']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
<mat-icon matBadge="2">mail</mat-icon>
<span *ngIf="displayLabels">Messages</span>
</a> -->
</a>
<a [routerLink]="['/people']" mat-menu-item (click)="toggleMenu()" [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active">
<mat-icon>people</mat-icon>
<span *ngIf="displayLabels">{{ 'App.People' | translate }}</span>
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
import { DragScrollModule } from 'ngx-drag-scroll';
import { ZappersListDialogComponent } from './shared/zappers-list-dialog/zappers-list-dialog.component';
import { ExampleComponent } from './example/example';
import { MessageListComponent } from './shared/message-list/message-list.component';
@NgModule({
declarations: [
AppComponent,
Expand Down Expand Up @@ -245,7 +246,8 @@ import { ExampleComponent } from './example/example';
TagsComponent,
BadgeComponent,
ZappersListDialogComponent,
ExampleComponent
ExampleComponent,
MessageListComponent
],
imports: [
HttpClientModule,
Expand Down
4 changes: 2 additions & 2 deletions src/app/chat/chat.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<mat-sidenav-container class="drawer-container" autosize>
<mat-tab-group mat-align-tabs="center">
<mat-tab label="Messages">
<mat-tab label="Subscribed">
<app-chat-list (openChatSidebar)="open.chatSideBar($event)"></app-chat-list>
</mat-tab>
<mat-tab label="Users">
<mat-tab label="Public">
<app-user-list (openUserSidebar)="open.userSideBar($event)"></app-user-list>
</mat-tab>
</mat-tab-group>
Expand Down
16 changes: 15 additions & 1 deletion src/app/chat/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, ChangeDetectorRef, ViewChild, ViewEncapsulation } from '@angular/core';
import { MatSidenav } from '@angular/material/sidenav';
import { ApplicationState } from '../services/applicationstate';
import { UIService } from '../services/ui';
import { RelayService } from '../services/relay';
import { Kind } from 'nostr-tools';
@Component({
selector: 'app-chat',
templateUrl: './chat.html',
Expand All @@ -10,7 +13,9 @@ import { ApplicationState } from '../services/applicationstate';
export class ChatComponent {
@ViewChild('chatSidebar', { static: false }) chatSidebar!: MatSidenav;
@ViewChild('userSidebar', { static: false }) userSidebar!: MatSidenav;
constructor(private appState: ApplicationState) {}
subscription?: string;

constructor(private appState: ApplicationState, private relayService: RelayService, public ui: UIService) {}
sidebarTitles = {
user: '',
chat: '',
Expand All @@ -22,15 +27,24 @@ export class ChatComponent {
this.me.sidebarTitles.user = title;
},
chatSideBar: function (title: string = '') {
debugger;
this.me.chatSidebar.open();
this.me.userSidebar.close();
this.me.sidebarTitles.chat = title;
},
};

async ngOnInit() {
this.ui.clearChats();
this.subscription = this.relayService.subscribe([{ kinds: [Kind.ChannelCreation, Kind.ChannelMetadata], limit: 10 }]).id;

this.appState.updateTitle('Chat');
this.appState.goBack = true;
this.appState.actions = [];
}

ngOnDestroy() {
// this.relayService.unsubscribe(this.subscription!);
// this.ui.clearChats();
}
}
2 changes: 1 addition & 1 deletion src/app/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class MessageComponent {
};

async ngOnInit() {
this.appState.updateTitle('@Milad');
this.appState.updateTitle('');
this.appState.goBack = true;
this.appState.showBackButton = true;
this.appState.actions = [];
Expand Down
36 changes: 36 additions & 0 deletions src/app/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,42 @@ export class ChatService {

subscriptions: Subscription[] = [];

downloadChatRooms() {
debugger;
// this.chats2 = [];
this.#chats = [];

this.dataService
.downloadEventsByQuery([{ kinds: [40, 41] }], 3000)
.pipe(
finalize(async () => {
debugger;
for (let index = 0; index < this.#chats.length; index++) {
const event = this.#chats[index];
const content = await this.nostr.decrypt(event.pubkey, event.content);
event.content = content;
console.log('DECRYPTED EVENT:', event);
}
})
)
.subscribe(async (event) => {
if (this.#chats.findIndex((e) => e.id === event.id) > -1) {
return;
}

// const gt = globalThis as any;
// const content = await gt.nostr.nip04.decrypt(event.pubkey, event.content);
// event.content = content;

this.#chats.unshift(event);

// this.chats2.push(event);
// this.#chatsChanged2.next(this.chats2);
});

// this.subscriptions.push(this.dataService.downloadEventsByQuery([{}]));
}

download() {
// this.chats2 = [];
this.#chats = [];
Expand Down
5 changes: 1 addition & 4 deletions src/app/services/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ export class DataService {
downloadFromRelay(filters: Filter[], relay: NostrRelay, requestTimeout = 10000): Observable<NostrEventDocument> {
return new Observable<NostrEventDocument>((observer: Observer<NostrEventDocument>) => {
const sub = relay.sub([...filters], {}) as NostrSubscription;
// relay.subscriptions.push(sub);

sub.on('event', (originalEvent: any) => {
const event = this.eventService.processEvent(originalEvent);
Expand All @@ -599,16 +598,14 @@ export class DataService {
});

return () => {
// console.log('downloadFromRelay:finished:unsub');
// When the observable is finished, this return function is called.
sub.unsub();
};
}).pipe(
timeout(requestTimeout),
catchError((error) => {
console.warn('The observable was timed out.');
return of();
}) // Simply return undefined when the timeout is reached.
})
);
}

Expand Down
18 changes: 12 additions & 6 deletions src/app/services/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,32 @@ export interface UserModel {
bio: string;
}

export interface MessageModel {
id: number;
cover: string;
message: string;
}
// export interface MessageModel {
// id: number;
// cover: string;
// message: string;
// }

export interface CustomObjectModel {
tmpl: string;
data: any;
formatted?: string;
}

export interface NostrEventChat extends NostrEvent {
about: string;
name: string;
picture: string;
}

export class ChatModel {
'id': number;
'targetUserId': number;
'username': string;
'cover': string;
'lastMessage': string;
'lastMessageLength': string | number;
'chat': Array<MessageModel>;
// 'chat': Array<MessageModel>;
}

export interface LabelModel {
Expand Down
12 changes: 12 additions & 0 deletions src/app/services/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ export class RelayService {
this.zapUi.addZap(event);
}

if (event.kind == Kind.ChannelCreation) {
this.ui.putChat(event);
}

if (event.kind == Kind.ChannelMetadata) {
this.ui.putChatMetadata(event);
}

if (event.kind == Kind.ChannelMessage) {
this.ui.putChatMessage(event);
}

if (response.subscription) {
const sub = this.subs.get(response.subscription);
if (sub) {
Expand Down
Loading