|
@ -1,6 +1,7 @@ |
|
|
package Hush::Contact; |
|
|
package Hush::Contact; |
|
|
use strict; |
|
|
use strict; |
|
|
use warnings; |
|
|
use warnings; |
|
|
|
|
|
use lib 'lib'; |
|
|
use Hush::Util qw/barf is_valid_zaddr/; |
|
|
use Hush::Util qw/barf is_valid_zaddr/; |
|
|
use Data::Dumper; |
|
|
use Data::Dumper; |
|
|
use File::Spec::Functions; |
|
|
use File::Spec::Functions; |
|
@ -25,18 +26,23 @@ sub contact { |
|
|
my $chain = "hush"; |
|
|
my $chain = "hush"; |
|
|
my $contacts_file = catdir($HUSHLIST_CONFIG_DIR,"$chain-contacts.txt"); |
|
|
my $contacts_file = catdir($HUSHLIST_CONFIG_DIR,"$chain-contacts.txt"); |
|
|
|
|
|
|
|
|
if (-e $contacts_file) { |
|
|
unless (-e $contacts_file) { |
|
|
my %contacts = read_file( $contacts_file ) =~ /^(z[a-z0-9]+) (.*)$/mgi ; |
|
|
# first contact being added, create the file |
|
|
|
|
|
open my $fh, ">>", $contacts_file or barf "Could not create contacts file $contacts_file ! : $!"; |
|
|
# TODO: check if zaddr OR nickname exists |
|
|
print $fh ""; |
|
|
if ($contacts{$zaddr}) { |
|
|
close $fh; |
|
|
} else { |
|
|
} |
|
|
# TODO: see if this contact exists already in this chain |
|
|
|
|
|
open my $fh, ">>", $contacts_file or barf "Could not write file $contacts_file ! : $!"; |
|
|
my %contacts = read_file( $contacts_file ) =~ /^(z[a-z0-9]+) (.*)$/mgi ; |
|
|
#TODO: validation? |
|
|
|
|
|
print $fh "$zaddr $name\n"; |
|
|
# TODO: check if zaddr OR nickname exists |
|
|
close $fh; |
|
|
if ($contacts{$zaddr}) { |
|
|
} |
|
|
} else { |
|
|
|
|
|
# TODO: see if this contact exists already in this chain |
|
|
|
|
|
open my $fh, ">>", $contacts_file or barf "Could not write file $contacts_file ! : $!"; |
|
|
|
|
|
#TODO: validation? |
|
|
|
|
|
print $fh "$zaddr $name\n"; |
|
|
|
|
|
close $fh; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
"rm" => sub { |
|
|
"rm" => sub { |
|
|