diff --git a/lib.go b/lib.go index 47b1d4e..4995f38 100644 --- a/lib.go +++ b/lib.go @@ -7,6 +7,7 @@ import ( "crypto/rand" "cwtch.im/cwtch/app" "cwtch.im/cwtch/event" + "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/peer" @@ -183,6 +184,10 @@ func SendProfileEvent(onion string, eventJson string) { switch new_event.EventType { case event.SetAttribute: peer.SetAttribute(new_event.Data[event.Key], new_event.Data[event.Data]) + case event.SetPeerAttribute: + peer.SetContactAttribute(new_event.Data[event.RemotePeer], new_event.Data[event.Key], new_event.Data[event.Data]) + case event.SetPeerAuthorization: + peer.SetContactAuthorization(new_event.Data[event.RemotePeer], model.Authorization(new_event.Data[event.Authorization])) case event.SendMessageToGroup: // TODO Uncomment and integrate once contacts/messages are loaded. //groupHandler,err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments) @@ -252,29 +257,6 @@ func GetProfiles() string { return string(jsonBytes) } -//export c_GetContacts -func c_GetContacts(onion_ptr *C.char, onion_len C.int) *C.char { - return C.CString(GetContacts(C.GoStringN(onion_ptr, onion_len))) -} - -func GetContacts(onion string) string { - log.Infof("Get Contacts for %v", onion) - mypeer := application.GetPeer(onion) - - contactEventsQueue = event.NewQueue() - application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue) - - var contacts []utils.Contact - for _, contact := range mypeer.GetContacts() { - contactInfo := mypeer.GetContact(contact) - log.Infof("contactInfo %v", contactInfo) - contacts = append(contacts, utils.Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State}) - } - - bytes, _ := json.Marshal(contacts) - return string(bytes) -} - //export c_CreateProfile func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) { CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len)) @@ -328,7 +310,7 @@ func c_NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, h func NumMessages(profile, handle string) (n int) { n = len(application.GetPeer(profile).GetContact(handle).Timeline.Messages) - log.Infof("NumMessagse(%s, %s) = %d", profile, handle, n) + //log.Infof("NumMessagse(%s, %s) = %d", profile, handle, n) return } diff --git a/utils/contacts.go b/utils/contacts.go index ddd1f9a..d9f6176 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -1,8 +1,9 @@ package utils type Contact struct { - Name string `json:"name"` - Onion string `json:"onion"` - Status string `json:"status"` - Picture string `json:"picture"` + Name string `json:"name"` + Onion string `json:"onion"` + Status string `json:"status"` + Picture string `json:"picture"` + Authorization string `json:"authorization"` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 45d0318..4670be0 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -106,7 +106,8 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { } cpicPath := GetPicturePath(cpic) contactInfo := profile.GetContact(contact) - contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath}) + name, _ := contactInfo.GetAttribute(attr.GetLocalScope(constants.Name)) + contacts = append(contacts, Contact{Name: name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath, Authorization: string(contactInfo.Authorization)}) } bytes, _ := json.Marshal(contacts)