undo bad refactor

This commit is contained in:
erinn 2021-03-16 13:16:45 -07:00
parent 51c7b56438
commit fe674e35fc
2 changed files with 45 additions and 45 deletions

View File

@ -82,7 +82,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
}
picPath := GetPicturePath(pic)
//tag, _ := Profile.GetAttribute(app.AttributeTag)
//tag, _ := profile.GetAttribute(app.AttributeTag)
online, _ := profile.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
@ -126,18 +126,18 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
switch ev.Event.EventType {
/*case Event.NetworkStatus:
/*case event.NetworkStatus:
online, _ := peer.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
if e.Data[Event.Status] == plugins.NetworkCheckSuccess && online == Event.False {
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), Event.True)
if e.Data[event.Status] == plugins.NetworkCheckSuccess && online == event.False {
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.True)
uiManager.UpdateNetworkStatus(true)
// TODO we may have to reinitialize the peer
} else if e.Data[Event.Status] == plugins.NetworkCheckError && online == Event.True {
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), Event.False)
} else if e.Data[event.Status] == plugins.NetworkCheckError && online == event.True {
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.False)
uiManager.UpdateNetworkStatus(false)
}*/
case event.NewMessageFromPeer: //Event.TimestampReceived, Event.RemotePeer, Event.Data
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
// I Don't think we need to enrich
// TODO: deprecate and move to dart
@ -151,18 +151,18 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
}*/
// legacy
//ts, _ := time.Parse(time.RFC3339Nano, e.Data[Event.TimestampReceived])
//ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
case event.PeerAcknowledgement:
// No enrichement required
//Acknowledge(ev.Event.Data[Event.RemotePeer], ev.Event.Data[Event.EventID])
//Acknowledge(ev.Event.Data[event.RemotePeer], ev.Event.Data[event.EventID])
/*
case Event.NewMessageFromGroup: //Event.TimestampReceived, Event.TimestampSent, Event.Data, Event.GroupID, Event.RemotePeer
ts, _ := time.Parse(time.RFC3339Nano, e.Data[Event.TimestampSent])
uiManager.AddMessage(e.Data[Event.GroupID], e.Data[Event.RemotePeer], e.Data[Event.Data], e.Data[Event.RemotePeer] == peer.GetOnion(), hex.EncodeToString([]byte(e.Data[Event.Signature])), ts, true)
case event.NewMessageFromGroup: //event.TimestampReceived, event.TimestampSent, event.Data, event.GroupID, event.RemotePeer
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampSent])
uiManager.AddMessage(e.Data[event.GroupID], e.Data[event.RemotePeer], e.Data[event.Data], e.Data[event.RemotePeer] == peer.GetOnion(), hex.EncodeToString([]byte(e.Data[event.Signature])), ts, true)
case Event.NewGroupInvite:
gid, err := peer.ProcessInvite(e.Data[Event.GroupInvite], e.Data[Event.RemotePeer])
case event.NewGroupInvite:
gid, err := peer.ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
group := peer.GetGroup(gid)
if err == nil && group != nil {
uiManager.AddContact(gid)
@ -175,17 +175,17 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
return ""
}
/*
case Event.SendMessageToGroupError:
uiManager.AddSendMessageError(e.Data[Event.GroupServer], e.Data[Event.Signature], e.Data[Event.Error])
case Event.SendMessageToPeerError:
uiManager.AddSendMessageError(e.Data[Event.RemotePeer], e.Data[Event.EventID], e.Data[Event.Error])
case event.SendMessageToGroupError:
uiManager.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
case event.SendMessageToPeerError:
uiManager.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.eventID], e.Data[event.Error])
*/
case event.PeerStateChange:
cxnState := connections.ConnectionStateToType[ev.Event.Data[event.ConnectionState]]
contact := peer.GetContact(ev.Event.Data[event.RemotePeer])
if cxnState == connections.AUTHENTICATED && contact == nil {
// Contact does not exist, change Event to NewPeer
// 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
@ -205,12 +205,12 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
}
}
/*case Event.NewRetValMessageFromPeer:
onion := e.Data[Event.RemotePeer]
scope := e.Data[Event.Scope]
path := e.Data[Event.Path]
val := e.Data[Event.Data]
exists, _ := strconv.ParseBool(e.Data[Event.Exists])
/*case event.NewRetValMessageFromPeer:
onion := e.Data[event.RemotePeer]
scope := e.Data[event.Scope]
path := e.Data[event.Path]
val := e.Data[event.Data]
exists, _ := strconv.ParseBool(e.Data[event.Exists])
if exists && scope == attr.PublicScope {
switch path {
@ -223,14 +223,14 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
}
}
case Event.ServerStateChange:
serverOnion := e.Data[Event.GroupServer]
state := connections.ConnectionStateToType[e.Data[Event.ConnectionState]]
case event.ServerStateChange:
serverOnion := e.Data[event.GroupServer]
state := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
groups := peer.GetGroups()
for _, groupID := range groups {
group := peer.GetGroup(groupID)
if group != nil && group.GroupServer == serverOnion {
group.State = e.Data[Event.ConnectionState]
group.State = e.Data[event.ConnectionState]
loading := false
if state == connections.AUTHENTICATED {
loading = true
@ -239,7 +239,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
uiManager.UpdateContactStatus(serverOnion, int(state), loading)
}
}
case Event.DeletePeer:
case event.DeletePeer:
log.Infof("PeerHandler got DeletePeer, SHUTTING down!\n")
uiManager.ReloadProfiles()
return
@ -274,7 +274,7 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
}
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
// TODO: graceful shutdown, via an injected Event of special QUIT type exiting loop/go routine
// TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine
for {
e := q.Next()
ev := EventProfileEnvelope{Event: *e, Profile: onion}

View File

@ -148,7 +148,7 @@ func GetPicturePath(pic *image) string {
case TypeImageDistro:
return profilePicRelativize(pic.Val)
default:
log.Errorf("Unhandled Profile picture type of %v\n", pic.T)
log.Errorf("Unhandled profile picture type of %v\n", pic.T)
return ""
}
}
@ -174,7 +174,7 @@ func getLastMessageTime(tl *model.Timeline) int {
}
/*
// AddProfile adds a new Profile to the UI
// AddProfile adds a new profile to the UI
func AddProfile(gcd *GrandCentralDispatcher, handle string) {
p := the.CwtchApp.GetPeer(handle)
if p != nil {
@ -204,14 +204,14 @@ func AddProfile(gcd *GrandCentralDispatcher, handle string) {
/*
type manager struct {
gcd *GrandCentralDispatcher
Profile string
profile string
}
// Manager is a middleware helper for entities like peer Event listeners wishing to trigger ui changes (via the gcd)
// each manager is for one Profile/peer
// each manager is for one profile/peer
// manager takes minimal arguments and builds the full struct of data (usually pulled from a cwtch peer) required to call the GCD to perform the ui action
// manager also performs call filtering based on UI state: users of manager can safely always call it on events and not have to worry about weather the relevant ui is active
// ie: you can always safely call AddMessage even if in the ui a different Profile is selected. manager will check with gcd, and if the correct conditions are not met, it will not call on gcd to update the ui incorrectly
// ie: you can always safely call AddMessage even if in the ui a different profile is selected. manager will check with gcd, and if the correct conditions are not met, it will not call on gcd to update the ui incorrectly
type Manager interface {
Acknowledge(handle, mID string)
AddContact(Handle string)
@ -234,9 +234,9 @@ type Manager interface {
UpdateNetworkStatus(online bool)
}
// NewManager returns a new Manager interface for a Profile to the gcd
func NewManager(Profile string, gcd *GrandCentralDispatcher) Manager {
return &manager{gcd: gcd, Profile: Profile}
// NewManager returns a new Manager interface for a profile to the gcd
func NewManager(profile string, gcd *GrandCentralDispatcher) Manager {
return &manager{gcd: gcd, profile: profile}
}
@ -283,7 +283,7 @@ func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) erro
/*
// AddSendMessageError adds an error not and icon to a message in a conversation in the ui for the message identified by the peer/sig combo
func (this *manager) AddSendMessageError(peer string, signature string, err string) {
this.gcd.DoIfProfile(this.Profile, func() {
this.gcd.DoIfProfile(this.profile, func() {
this.gcd.DoIfConversation(peer, func() {
log.Debugf("Received Error Sending Message: %v", err)
// FIXME: Sometimes, for the first Peer message we send our error beats our message to the UI
@ -304,7 +304,7 @@ func (this *manager) MessageJustAdded() {
/*
// AddMessage adds a message to the message pane for the supplied conversation if it is active
func (this *manager) AddMessage(handle string, from string, message string, fromMe bool, messageID string, timestamp time.Time, Acknowledged bool) {
this.gcd.DoIfProfile(this.Profile, func() {
this.gcd.DoIfProfile(this.profile, func() {
this.gcd.DoIfConversation(handle, func() {
updateLastReadTime(handle)
// If the message is not from the user then add it, otherwise, just acknowledge.
@ -328,21 +328,21 @@ func (this *manager) ReloadProfiles() {
// UpdateContactDisplayName updates a contact's display name in the contact list and conversations
func (this *manager) UpdateContactDisplayName(handle string) {
this.gcd.DoIfProfile(this.Profile, func() {
this.gcd.DoIfProfile(this.profile, func() {
this.gcd.UpdateContactDisplayName(handle, GetNick(handle))
})
}
// UpdateContactPicture updates a contact's picture in the contact list and conversations
func (this *manager) UpdateContactPicture(handle string) {
this.gcd.DoIfProfile(this.Profile, func() {
this.gcd.DoIfProfile(this.profile, func() {
this.gcd.UpdateContactPicture(handle, GetProfilePic(handle))
})
}
// UpdateContactAttribute update's a contacts attribute in the ui
func (this *manager) UpdateContactAttribute(handle, key, value string) {
this.gcd.DoIfProfile(this.Profile, func() {
this.gcd.DoIfProfile(this.profile, func() {
this.gcd.UpdateContactAttribute(handle, key, value)
})
}
@ -352,6 +352,6 @@ func (this *manager) ChangePasswordResponse(error bool) {
}
func (this *manager) UpdateNetworkStatus(online bool) {
this.gcd.UpdateProfileNetworkStatus(this.Profile, online)
this.gcd.UpdateProfileNetworkStatus(this.profile, online)
}
*/