Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
add reverse name lookup for fromAddresses (#68)
Browse files Browse the repository at this point in the history
* fix merge

* add reverse name lookup for fromAddresses
closes #66

* remove log
add coverage
  • Loading branch information
tboeckmann committed Aug 26, 2019
1 parent 257ec2d commit b78eae0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Coverage Status](https://coveralls.io/repos/github/mailchain/mailchain-web/badge.svg?branch=master)](https://coveralls.io/github/mailchain/mailchain-web?branch=master)
[![Join the chat at https://gitter.im/Mailchain/community](https://badges.gitter.im/Mailchain/mailchain.svg)](https://gitter.im/Mailchain/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->

<!-- code_chunk_output -->
Expand Down
8 changes: 7 additions & 1 deletion src/app/inbox/inbox-compose/inbox-compose.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,14 @@ describe('InboxComposeComponent', () => {
expect(component.model.subject).toBe('Re: Mailchain Test!')
})

it('should not re-initialize the model "subject" field with an extra prefix of "Re: "', async() => {
component.currentMessage.subject = "Re: Mailchain Test!"
await component.ngOnInit();
expect(component.model.subject).toBe('Re: Mailchain Test!')
})

it('should initialize the model "body" field with the original message field', async() => {
let response = "\r\n\r\n>From: <0x0123456789012345678901234567890123456789@testnet.ethereum>\r\n>Date: 2019-06-07T14:53:36Z\r\n>To: <0x0123456789abcdef0123456789abcdef01234567@testnet.ethereum>\r\n>Subject: Re: Mailchain Test!\r\n>\r\n>A body"
let response = "\r\n\r\n>From: <0x0123456789012345678901234567890123456789@testnet.ethereum>\r\n>Date: 2019-06-07T14:53:36Z\r\n>To: <0x0123456789abcdef0123456789abcdef01234567@testnet.ethereum>\r\n>Subject: Mailchain Test!\r\n>\r\n>A body"

await component.ngOnInit();
expect(JSON.stringify(component.model.body)).toBe(JSON.stringify(response))
Expand Down
2 changes: 1 addition & 1 deletion src/app/inbox/inbox-compose/inbox-compose.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class InboxComposeComponent implements OnInit {
* Checks for 'Re: ' on the subject and adds it if it is not there already.
* @param subject the message subject
*/
private addRePrefixToSubject(subject: string) {
private addRePrefixToSubject(subject: string) {
if (subject.startsWith("Re: ") ) {
return subject
} else {
Expand Down
1 change: 1 addition & 0 deletions src/app/inbox/inbox.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h1 class="page-title">Mailchain</h1>
</div>
<div class="col-9 p-0 my-auto">
<a class="nav-link" (click)="changeAccount(address)">{{address}}</a>
<span class="nav-link accountNameRecord" *ngIf="accountNameRecord[address] != undefined">({{accountNameRecord[address]}})</span>
</div>
<div class="col-1 p-0 my-auto">
<a class="nav-link" (click)="changeAccount(address)">
Expand Down
5 changes: 5 additions & 0 deletions src/app/inbox/inbox.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@

.addressFolderIcon{
width: 100%;
}

.accountNameRecord {
display: block;
padding: 0 1rem 0.5rem 1rem;
}
38 changes: 34 additions & 4 deletions src/app/inbox/inbox.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AddressesService } from '../services/mailchain/addresses/addresses.serv
import { ProtocolsService } from '../services/mailchain/protocols/protocols.service';
import { MailchainService } from '../services/mailchain/mailchain.service';
import { ActivatedRoute } from '@angular/router';
import { NameserviceService } from '../services/mailchain/nameservice/nameservice.service';

describe('InboxComponent', () => {
let component: InboxComponent;
Expand All @@ -28,6 +29,7 @@ describe('InboxComponent', () => {
let localStorageAccountService: LocalStorageAccountService
let localStorageServerService: LocalStorageServerService
let mailchainService: MailchainService
let nameserviceService: NameserviceService
let activatedRoute: any
let networkList: any
let currentWebProtocolsList: any
Expand All @@ -36,6 +38,9 @@ describe('InboxComponent', () => {
const currentProtocol: string = "ethereum"
const currentAccount = '0x0123456789012345678901234567890123456789';
const currentAccount2 = '0x0123456789abcdef0123456789abcdef01234567';
const currentAccountNameLookup = 'myaddress.eth';
const currentAccount2NameLookup = 'someaddress.myaddress.eth';

const currentNetwork = 'testnet';
const currentWebProtocol = 'https';
const currentHost = 'example.com';
Expand Down Expand Up @@ -109,6 +114,20 @@ describe('InboxComponent', () => {
return of(mailchainTestService.protocolsServerResponse())
}
}
class NameserviceServiceStub {
resolveAddress(protocol,network,value) {
let returnVals = {}
returnVals[currentAccount] = currentAccountNameLookup,
returnVals[currentAccount2] = currentAccount2NameLookup

return of(
{
"body": { name: returnVals[value] },
"ok": true
}
)
}
}

class ActivatedRouteStub {
//Observable that contains a map of the parameters
Expand Down Expand Up @@ -145,9 +164,6 @@ describe('InboxComponent', () => {
}
}




beforeEach(async(() => {

TestBed.configureTestingModule({
Expand All @@ -164,7 +180,8 @@ describe('InboxComponent', () => {
{ provide: AddressesService, useClass: AddressesServiceStub },
{ provide: ProtocolsService, useClass: ProtocolsServiceStub },
{ provide: MessagesService, useClass: MessagesServiceStub },
{ provide: ActivatedRoute, useClass: ActivatedRouteStub }
{ provide: ActivatedRoute, useClass: ActivatedRouteStub },
{ provide: NameserviceService, useClass: NameserviceServiceStub }

],
imports: [
Expand All @@ -181,6 +198,7 @@ describe('InboxComponent', () => {
localStorageAccountService = TestBed.get(LocalStorageAccountService);
localStorageServerService = TestBed.get(LocalStorageServerService);
mailchainService = TestBed.get(MailchainService);
nameserviceService = TestBed.get(NameserviceService);

}));

Expand Down Expand Up @@ -605,6 +623,18 @@ describe('InboxComponent', () => {
component.fromAddresses
});
});

describe('setAccountNameRecords', () => {
it('should lookup a name each fromAddress', () => {
component.fromAddressesKeys = [currentAccount,currentAccount2]
component.setAccountNameRecords()

expect(component.accountNameRecord[currentAccount]).toEqual(currentAccountNameLookup)

expect(component.accountNameRecord[currentAccount2]).toEqual(currentAccount2NameLookup)

});
});

describe('setupServerSettingsForm', () => {
it('should initialize values for the form', () => {
Expand Down
23 changes: 20 additions & 3 deletions src/app/inbox/inbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ActivatedRoute } from '@angular/router';
import { AddressesService } from '../services/mailchain/addresses/addresses.service';
import { ProtocolsService } from '../services/mailchain/protocols/protocols.service';
import { throwError } from 'rxjs';
import { NameserviceService } from '../services/mailchain/nameservice/nameservice.service';

@Component({
selector: 'app-inbox',
Expand Down Expand Up @@ -39,6 +40,7 @@ export class InboxComponent implements OnInit {
public serverSettings: any = {};

public accountIdenticons: any = {};
public accountNameRecord: any = {};


constructor(
Expand All @@ -49,6 +51,7 @@ export class InboxComponent implements OnInit {
private mailchainService: MailchainService,
private messagesService: MessagesService,
private activatedRoute: ActivatedRoute,
private nameserviceService: NameserviceService,
) {}

/**
Expand Down Expand Up @@ -281,6 +284,19 @@ export class InboxComponent implements OnInit {
this.accountIdenticons[address] = this.mailchainService.generateIdenticon(address)
});
}

/**
* Lookup name records for addresses
*/
setAccountNameRecords() {
this.fromAddressesKeys.forEach(address => {
this.nameserviceService.resolveAddress(this.currentProtocol,this.currentNetwork,address).subscribe(res =>{
if ( res['ok'] ) {
this.accountNameRecord[address] = res['body']['name']
}
})
});
}

/**
* Initiates the server settings form with default values. Default values are retrieved from local storage
Expand Down Expand Up @@ -339,12 +355,13 @@ export class InboxComponent implements OnInit {
await this.setFromAddressList()
this.getMails()
this.setAccountIdenticons()
this.setAccountNameRecords()
}


/**
* Fetch mails from the server
* @param
* @param quietMode (default: false) when true, messages are quietly loaded
*/
public getMails(quietMode: boolean = false){

Expand All @@ -355,7 +372,7 @@ export class InboxComponent implements OnInit {
this.fromAddressesKeys.forEach(address => {
var self = this
this.messagesService.getMessages(address, this.currentNetwork).subscribe(function(res){

self.processUnreadMessagesInboxCounter(address, res["messages"])
self.processInboxMessages(res["messages"])

Expand Down Expand Up @@ -395,7 +412,7 @@ export class InboxComponent implements OnInit {
messages,
{status: "ok"}
)
validMessages.forEach(msg => this.addMailToInboxMessages(msg));
validMessages.forEach(msg => this.addMailToInboxMessages(msg));
}


Expand Down
2 changes: 1 addition & 1 deletion src/app/test/test-helpers/mailchain-test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MailchainTestService {
"message-id": "0020c"
},
"body": "A body",
"subject": "Re: Mailchain Test!",
"subject": "Mailchain Test!",
"status": "ok",
"status-code": "",
"read": true,
Expand Down

0 comments on commit b78eae0

Please sign in to comment.