core: Minor fixes for inbound contact requests

This commit is contained in:
John Brooks 2017-08-11 18:04:28 -06:00
parent 2e8b9f2828
commit 23e22f0260
3 changed files with 20 additions and 3 deletions

View File

@ -22,8 +22,9 @@ type ContactList struct {
func LoadContactList(core *Ricochet) (*ContactList, error) {
list := &ContactList{
core: core,
events: utils.CreatePublisher(),
core: core,
events: utils.CreatePublisher(),
inboundRequests: make(map[string]*InboundContactRequest),
}
config := core.Config.OpenRead()
@ -46,7 +47,6 @@ func LoadContactList(core *Ricochet) (*ContactList, error) {
list.contacts[id] = contact
}
// XXX Requests aren't implemented
return list, nil
}

View File

@ -82,6 +82,18 @@ func (cr *InboundContactRequest) Update(nickname, message string) {
}
}
func (cr *InboundContactRequest) SetNickname(nickname string) error {
cr.mutex.Lock()
defer cr.mutex.Unlock()
if IsNicknameAcceptable(nickname) {
cr.data.FromNickname = nickname
} else {
return errors.New("Invalid nickname")
}
return nil
}
func (cr *InboundContactRequest) Accept() (*Contact, error) {
cr.mutex.Lock()
defer cr.mutex.Unlock()

View File

@ -159,6 +159,11 @@ func (s *RpcServer) AcceptInboundRequest(ctx context.Context, req *ricochet.Cont
if request == nil {
return nil, errors.New("Request does not exist")
}
if len(req.FromNickname) > 0 {
if err := request.SetNickname(req.FromNickname); err != nil {
return nil, err
}
}
contact, err := request.Accept()
if err != nil {
return nil, err