Invitation errors when no servers defined
This commit is contained in:
parent
d5760e8439
commit
8bde6802de
@ -33,7 +33,7 @@ func CreateIdentity(nickname string) *Identity {
|
|||||||
return &id
|
return &id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) *meowlib.ContactCard {
|
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerIdxs []int) (*meowlib.ContactCard, error) {
|
||||||
var peer Peer
|
var peer Peer
|
||||||
var myContactCard meowlib.ContactCard
|
var myContactCard meowlib.ContactCard
|
||||||
peer.MyIdentity = meowlib.NewKeyPair()
|
peer.MyIdentity = meowlib.NewKeyPair()
|
||||||
@ -41,6 +41,9 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerI
|
|||||||
peer.MyLookupKp = meowlib.NewKeyPair()
|
peer.MyLookupKp = meowlib.NewKeyPair()
|
||||||
peer.Name = ContactName
|
peer.Name = ContactName
|
||||||
peer.InvitationId = uuid.New().String()
|
peer.InvitationId = uuid.New().String()
|
||||||
|
if id.MessageServers.Servers == nil {
|
||||||
|
return nil, errors.New("no servers defined in your identity")
|
||||||
|
}
|
||||||
for _, i := range MessageServerIdxs {
|
for _, i := range MessageServerIdxs {
|
||||||
srv := id.MessageServers.Servers[i].ServerData
|
srv := id.MessageServers.Servers[i].ServerData
|
||||||
myContactCard.PullServers = append(myContactCard.PullServers, &srv)
|
myContactCard.PullServers = append(myContactCard.PullServers, &srv)
|
||||||
@ -52,7 +55,7 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerI
|
|||||||
myContactCard.InvitationId = peer.InvitationId
|
myContactCard.InvitationId = peer.InvitationId
|
||||||
id.Peers = append(id.Peers, peer)
|
id.Peers = append(id.Peers, peer)
|
||||||
|
|
||||||
return &myContactCard
|
return &myContactCard, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAnswer bool, proposedNick string, receivedNick string) {
|
func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAnswer bool, proposedNick string, receivedNick string) {
|
||||||
|
@ -59,7 +59,7 @@ func (pl *PeerList) GetFromName(name string) *Peer {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) BuildSimpleUserUMessage(message []byte) (*meowlib.UserMessage, error) {
|
func (p *Peer) BuildSimpleUserMessage(message []byte) (*meowlib.UserMessage, error) {
|
||||||
var msg meowlib.UserMessage
|
var msg meowlib.UserMessage
|
||||||
msg.From = p.MyIdentity.Public
|
msg.From = p.MyIdentity.Public
|
||||||
msg.Data = message
|
msg.Data = message
|
||||||
|
@ -30,7 +30,10 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
// Create an invitation for a friend, I want him/her to know me as Bender //
|
// Create an invitation for a friend, I want him/her to know me as Bender //
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
fmt.Println("Creating an invitation for the first friend...")
|
fmt.Println("Creating an invitation for the first friend...")
|
||||||
invitation := Me.InvitePeer("Bender", "myfirstfriend", []int{1, 2})
|
invitation, err := Me.InvitePeer("Bender", "myfirstfriend", []int{1, 2})
|
||||||
|
if err != nil {
|
||||||
|
println(err)
|
||||||
|
}
|
||||||
// print my invitation
|
// print my invitation
|
||||||
a, _ := json.Marshal(invitation)
|
a, _ := json.Marshal(invitation)
|
||||||
fmt.Println(string(a))
|
fmt.Println(string(a))
|
||||||
@ -79,7 +82,7 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
MyFirstFriend := Me.Peers[0]
|
MyFirstFriend := Me.Peers[0]
|
||||||
textmessage := "Hello friend!"
|
textmessage := "Hello friend!"
|
||||||
// Creating User message
|
// Creating User message
|
||||||
usermessage, err := MyFirstFriend.BuildSimpleUserUMessage([]byte(textmessage))
|
usermessage, err := MyFirstFriend.BuildSimpleUserMessage([]byte(textmessage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user