Skip to content

Commit

Permalink
handling errors cooly
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioconselheiro committed Oct 17, 2024
1 parent 8fc0da0 commit a1c0f37
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
21 changes: 12 additions & 9 deletions src/app/pages/chat/chat.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ <h2 class="online">{{currentOnline}}</h2>
*ngFor="let message of messages"
class="chat"
>
<svg *ngIf="message[1]" class="messageNotSent" [title]="message[1]" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M17 3.34a10 10 0 1 1 -15 8.66l.005 -.324a10 10 0 0 1 14.995 -8.336m-5 11.66a1 1 0 0 0 -1 1v.01a1 1 0 0 0 2 0v-.01a1 1 0 0 0 -1 -1m0 -7a1 1 0 0 0 -1 1v4a1 1 0 0 0 2 0v-4a1 1 0 0 0 -1 -1" />
</svg>
<span
[class.authorStranger]="message[0].author === authorStrange"
[class.authorYou]="message[0].author === authorYou"
>{{message[0].author | author}}: </span>
<span class="text">{{message[0].text}}</span>
<span
[class.authorStranger]="message[0].author === authorStrange"
[class.authorYou]="message[0].author === authorYou"
>{{message[0].author | author}}: </span>
<span class="text">{{message[0].text}}</span>
<span *ngIf="message[1]" class="errorWrap">
<svg class="messageNotSent" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M17 3.34a10 10 0 1 1 -15 8.66l.005 -.324a10 10 0 0 1 14.995 -8.336m-5 11.66a1 1 0 0 0 -1 1v.01a1 1 0 0 0 2 0v-.01a1 1 0 0 0 -1 -1m0 -7a1 1 0 0 0 -1 1v4a1 1 0 0 0 2 0v-4a1 1 0 0 0 -1 -1" />
</svg>
<span class="errorMessage">{{message[1]}}</span>
</span>
</div>

<div class="message" *ngIf="strangeIsTyping">
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class ChatComponent implements OnDestroy, OnInit {
this.strangeIsTyping = true;
this.scrollConversationToTheEnd();
} else if (event.content === 'disconnected') {
debugger;
this.strangeIsTyping = false;
this.whoDisconnected = MessageAuthor.STRANGE;
this.currentState = ChatState.DISCONNECTED;
Expand Down
9 changes: 6 additions & 3 deletions src/app/shared/nostr/main.npool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { NostrEvent, NostrFilter, NPool, NRelay1, NSet } from '@nostrify/nostrify';
import { NostrEvent, NostrFilter, NPool, NRelay1 } from '@nostrify/nostrify';
import { RelayConfigService } from '@shared/relay-config/relay-config.service';
import { finalize, Observable, Subject } from 'rxjs';

Expand Down Expand Up @@ -27,7 +27,7 @@ export class NPoolService extends NPool<NRelay1> {
console.info(new Date().toLocaleString(),'[[subscribe filter]]', filters);
const abort = new AbortController();
const subject = new Subject<NostrEvent>();
const nset = new NSet();
const nset = new Map<string, NostrEvent>();

(async () => {
for await (const msg of this.req(filters, abort)) {
Expand All @@ -36,10 +36,13 @@ export class NPoolService extends NPool<NRelay1> {
break;
} else if (msg[0] === 'EVENT') {
const nsetSize = nset.size;
nset.add(msg[2]);
nset.set(msg[2].id, msg[2]);

if (nsetSize !== nset.size) {
subject.next(msg[2]);
} else {
console.debug(new Date().toLocaleString(), 'event deduplicated, not emiting again: ', msg[2]);
console.debug(new Date().toLocaleString(), 'current nset from request: ', nset);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/omegle-service/talk-to-stranger.nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { finalize, Observable, Subject } from 'rxjs';
@Injectable()
export class TalkToStrangerNostr {

readonly updateUserCountTimeout = 1000 * 60 * 2;
readonly updateUserCountTimeout = 1000 * 60 * 5;

constructor(
private nostrEventFactory: NostrEventFactory,
Expand Down
49 changes: 46 additions & 3 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,55 @@ body {
margin-bottom: 0.7rem;
}

.messageNotSent {
color: #ff8100;
margin: -.5rem 1rem;
.errorWrap {
position: relative;

.messageNotSent {
color: #ff8100;
margin: -.5rem 1rem;
cursor: pointer;

&:hover ~ .errorMessage {
display: block;
}
}

.errorMessage {
border: 1px solid;
border-radius: 5px;
padding: .5rem 1rem;
background-color: #ffdebd;
position: absolute;
display: none;
top: -.5rem;

&:before,
&:after {
content: "";
display: block;
border: 10px solid transparent;
width: 0px;
height: 0px;
z-index: 1;
position: absolute;
border-right-color: black;
white-space: nowrap;
left: -20px;
top: 10px;
}

&:after {
z-index: 2;
border: 8px solid transparent;
border-right-color: #ffdebd;
left: -16px;
top: 12px;
}
}
}

.chat {
position: relative;
margin-bottom: 0.7rem;
}

Expand Down

0 comments on commit a1c0f37

Please sign in to comment.