SendProfileEvent
This commit is contained in:
parent
ecb657a7a5
commit
7dfdb33c52
40
lib.go
40
lib.go
|
@ -111,6 +111,43 @@ func ACNEvents() string {
|
|||
}
|
||||
}
|
||||
|
||||
//export c_SendProfileEvent
|
||||
// A generic method for Rebroadcasting Profile Events from a UI
|
||||
func c_SendProfileEvent(onion_ptr *C.char, onion_len C.int, json_ptr *C.char, json_len C.int) {
|
||||
onion:= C.GoStringN(onion_ptr, onion_len)
|
||||
eventJson:= C.GoStringN(json_ptr, json_len)
|
||||
SendProfileEvent(onion, eventJson)
|
||||
}
|
||||
|
||||
// SendProfileEvent is a generic method for Rebroadcasting Profile Events from a UI
|
||||
func SendProfileEvent(onion string, eventJson string) {
|
||||
// Convert the Event Json back to a typed Event Struct, this will make the
|
||||
// rest of the logic nicer.
|
||||
var new_event event.Event
|
||||
json.Unmarshal([]byte(eventJson), &new_event)
|
||||
log.Infof("Event: %v %v", onion, new_event)
|
||||
|
||||
|
||||
// Get the correct Peer
|
||||
peer := application.GetPeer(onion)
|
||||
if peer == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// We need to update the local cache
|
||||
// Ideally I think this would be pushed back into Cwtch
|
||||
switch new_event.EventType {
|
||||
case event.SetAttribute: {
|
||||
peer.SetAttribute(new_event.Data[event.Key], new_event.Data[event.Data])
|
||||
}
|
||||
default: {
|
||||
// rebroadcast catch all
|
||||
log.Infof("Received Event %v for %v but no libCwtch handler found, relaying the event directly", new_event, onion)
|
||||
application.GetEventBus(onion).Publish(new_event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export c_GetAppBusEvent
|
||||
func c_GetAppBusEvent() *C.char {
|
||||
return C.CString(GetAppBusEvent())
|
||||
|
@ -192,7 +229,8 @@ func GetProfiles() string {
|
|||
peerList := application.ListPeers()
|
||||
profiles := make([]Profile, len(peerList))
|
||||
i := 0
|
||||
for onion, name := range peerList {
|
||||
for onion,_ := range peerList {
|
||||
name,_ := application.GetPeer(onion).GetAttribute(attr.GetPublicScope(constants.Name))
|
||||
profiles[i] = Profile{
|
||||
Name: name,
|
||||
Onion: onion,
|
||||
|
|
Loading…
Reference in New Issue