mo wirin
continuous-integration/drone/pr Build is running Details

This commit is contained in:
erinn 2021-04-09 19:31:05 -07:00
parent 0c963172ff
commit 6e1cb20d66
4 changed files with 25 additions and 16 deletions

2
go.mod
View File

@ -6,4 +6,4 @@ require (
cwtch.im/cwtch v0.6.3
git.openprivacy.ca/openprivacy/connectivity v1.3.3
git.openprivacy.ca/openprivacy/log v1.0.2
)
)

30
lib.go
View File

@ -293,7 +293,6 @@ func c_SelectProfile(onion_ptr *C.char, onion_len C.int) *C.char {
}
func SelectProfile(onion string) string {
log.Infof("Select Profile: %v", onion)
contactEventsQueue = event.NewQueue()
application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue)
return ""
@ -329,7 +328,14 @@ func c_AcceptContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, ha
func AcceptContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthApproved)
if err != nil {
if err == nil {
eventHandler.Push(event.NewEvent(event.PeerStateChange, map[event.Field]string{
//application.GetPrimaryBus().Publish(event.NewEvent(event.PeerStateChange, map[event.Field]string{
"ProfileOnion": profile,
event.RemotePeer: handle,
"authorization": string(model.AuthApproved),
}))
} else {
log.Errorf("error accepting contact: %s", err.Error())
}
}
@ -341,7 +347,13 @@ func c_BlockContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, han
func BlockContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthBlocked)
if err != nil {
if err == nil {
application.GetPrimaryBus().Publish(event.NewEvent(event.PeerStateChange, map[event.Field]string{
"ProfileOnion": profile,
event.RemotePeer: handle,
"authorization": string(model.AuthBlocked),
}))
} else {
log.Errorf("error blocking contact: %s", err.Error())
}
}
@ -353,10 +365,14 @@ func c_DebugResetContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char
func DebugResetContact(profile, handle string) {
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthUnknown)
if err != nil {
log.Errorf("error resetting contact: %s", err.Error())
if err == nil {
application.GetPrimaryBus().Publish(event.NewEvent(event.PeerStateChange, map[event.Field]string{
"ProfileOnion": profile,
event.RemotePeer: handle,
"authorization": string(model.AuthUnknown),
}))
} else {
log.Infof("reset contact! %s -> %s", profile, handle)
log.Errorf("error resetting contact: %s", err.Error())
}
}
@ -369,7 +385,6 @@ 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)
return
}
@ -384,7 +399,6 @@ func c_GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, ha
func GetMessage(profile, handle string, message_index int) string {
message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index]
bytes, _ := json.Marshal(message)
log.Infof("GetMessage(%s, %s, %d) = %s", profile, handle, message_index, string(bytes))
return string(bytes)
}

View File

@ -192,14 +192,8 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
contact := peer.GetContact(ev.Event.Data[event.RemotePeer])
if cxnState == connections.AUTHENTICATED && contact == nil {
// Contact does not exist, change event to NewPeer
peer.AddContact(ev.Event.Data[event.RemotePeer], ev.Event.Data[event.RemotePeer], model.AuthUnknown)
contact = peer.GetContact(ev.Event.Data[event.RemotePeer])
ev.Event.EventType = event.PeerCreated
err := EnrichNewPeer(ev.Event.Data[event.RemotePeer], ph, ev)
if err != nil {
return ""
}
return ""
}
if contact != nil {

View File

@ -264,6 +264,7 @@ func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) erro
if contact != nil {
lastRead := ph.InitLastReadTime(contact.Onion)
ev.Event.Data["unread"] = strconv.Itoa(ph.CountUnread(contact.Timeline.GetMessages(), lastRead))
ev.Event.Data["numMessages"] = strconv.Itoa(contact.Timeline.Len())
ev.Event.Data["picture"] = ph.GetProfilePic(handle)
ev.Event.Data["nick"] = ph.GetNick(handle)