Merge branch 'trunk' into settings
This commit is contained in:
commit
d110e870ec
|
@ -82,7 +82,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
}
|
}
|
||||||
picPath := GetPicturePath(pic)
|
picPath := GetPicturePath(pic)
|
||||||
|
|
||||||
//tag, _ := Profile.GetAttribute(app.AttributeTag)
|
//tag, _ := profile.GetAttribute(app.AttributeTag)
|
||||||
|
|
||||||
online, _ := profile.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
online, _ := profile.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
||||||
|
|
||||||
|
@ -126,18 +126,18 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
|
|
||||||
switch ev.Event.EventType {
|
switch ev.Event.EventType {
|
||||||
|
|
||||||
/*case Event.NetworkStatus:
|
/*case event.NetworkStatus:
|
||||||
online, _ := peer.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
online, _ := peer.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
||||||
if e.Data[Event.Status] == plugins.NetworkCheckSuccess && online == Event.False {
|
if e.Data[event.Status] == plugins.NetworkCheckSuccess && online == event.False {
|
||||||
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), Event.True)
|
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.True)
|
||||||
uiManager.UpdateNetworkStatus(true)
|
uiManager.UpdateNetworkStatus(true)
|
||||||
// TODO we may have to reinitialize the peer
|
// TODO we may have to reinitialize the peer
|
||||||
} else if e.Data[Event.Status] == plugins.NetworkCheckError && online == Event.True {
|
} else if e.Data[event.Status] == plugins.NetworkCheckError && online == event.True {
|
||||||
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), Event.False)
|
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.False)
|
||||||
uiManager.UpdateNetworkStatus(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
|
// I Don't think we need to enrich
|
||||||
|
|
||||||
// TODO: deprecate and move to dart
|
// TODO: deprecate and move to dart
|
||||||
|
@ -151,18 +151,18 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// legacy
|
// legacy
|
||||||
//ts, _ := time.Parse(time.RFC3339Nano, e.Data[Event.TimestampReceived])
|
//ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
|
||||||
|
|
||||||
case event.PeerAcknowledgement:
|
case event.PeerAcknowledgement:
|
||||||
// No enrichement required
|
// 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
|
case event.NewMessageFromGroup: //event.TimestampReceived, event.TimestampSent, event.Data, event.GroupID, event.RemotePeer
|
||||||
ts, _ := time.Parse(time.RFC3339Nano, e.Data[Event.TimestampSent])
|
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)
|
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:
|
case event.NewGroupInvite:
|
||||||
gid, err := peer.ProcessInvite(e.Data[Event.GroupInvite], e.Data[Event.RemotePeer])
|
gid, err := peer.ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
|
||||||
group := peer.GetGroup(gid)
|
group := peer.GetGroup(gid)
|
||||||
if err == nil && group != nil {
|
if err == nil && group != nil {
|
||||||
uiManager.AddContact(gid)
|
uiManager.AddContact(gid)
|
||||||
|
@ -175,17 +175,17 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
case Event.SendMessageToGroupError:
|
case event.SendMessageToGroupError:
|
||||||
uiManager.AddSendMessageError(e.Data[Event.GroupServer], e.Data[Event.Signature], e.Data[Event.Error])
|
uiManager.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
|
||||||
case Event.SendMessageToPeerError:
|
case event.SendMessageToPeerError:
|
||||||
uiManager.AddSendMessageError(e.Data[Event.RemotePeer], e.Data[Event.EventID], e.Data[Event.Error])
|
uiManager.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error])
|
||||||
*/
|
*/
|
||||||
case event.PeerStateChange:
|
case event.PeerStateChange:
|
||||||
cxnState := connections.ConnectionStateToType[ev.Event.Data[event.ConnectionState]]
|
cxnState := connections.ConnectionStateToType[ev.Event.Data[event.ConnectionState]]
|
||||||
contact := peer.GetContact(ev.Event.Data[event.RemotePeer])
|
contact := peer.GetContact(ev.Event.Data[event.RemotePeer])
|
||||||
|
|
||||||
if cxnState == connections.AUTHENTICATED && contact == nil {
|
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)
|
peer.AddContact(ev.Event.Data[event.RemotePeer], ev.Event.Data[event.RemotePeer], model.AuthUnknown)
|
||||||
contact = peer.GetContact(ev.Event.Data[event.RemotePeer])
|
contact = peer.GetContact(ev.Event.Data[event.RemotePeer])
|
||||||
ev.Event.EventType = event.PeerCreated
|
ev.Event.EventType = event.PeerCreated
|
||||||
|
@ -205,12 +205,12 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*case Event.NewRetValMessageFromPeer:
|
/*case event.NewRetValMessageFromPeer:
|
||||||
onion := e.Data[Event.RemotePeer]
|
onion := e.Data[event.RemotePeer]
|
||||||
scope := e.Data[Event.Scope]
|
scope := e.Data[event.Scope]
|
||||||
path := e.Data[Event.Path]
|
path := e.Data[event.Path]
|
||||||
val := e.Data[Event.Data]
|
val := e.Data[event.Data]
|
||||||
exists, _ := strconv.ParseBool(e.Data[Event.Exists])
|
exists, _ := strconv.ParseBool(e.Data[event.Exists])
|
||||||
|
|
||||||
if exists && scope == attr.PublicScope {
|
if exists && scope == attr.PublicScope {
|
||||||
switch path {
|
switch path {
|
||||||
|
@ -223,14 +223,14 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case Event.ServerStateChange:
|
case event.ServerStateChange:
|
||||||
serverOnion := e.Data[Event.GroupServer]
|
serverOnion := e.Data[event.GroupServer]
|
||||||
state := connections.ConnectionStateToType[e.Data[Event.ConnectionState]]
|
state := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
||||||
groups := peer.GetGroups()
|
groups := peer.GetGroups()
|
||||||
for _, groupID := range groups {
|
for _, groupID := range groups {
|
||||||
group := peer.GetGroup(groupID)
|
group := peer.GetGroup(groupID)
|
||||||
if group != nil && group.GroupServer == serverOnion {
|
if group != nil && group.GroupServer == serverOnion {
|
||||||
group.State = e.Data[Event.ConnectionState]
|
group.State = e.Data[event.ConnectionState]
|
||||||
loading := false
|
loading := false
|
||||||
if state == connections.AUTHENTICATED {
|
if state == connections.AUTHENTICATED {
|
||||||
loading = true
|
loading = true
|
||||||
|
@ -239,7 +239,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
uiManager.UpdateContactStatus(serverOnion, int(state), loading)
|
uiManager.UpdateContactStatus(serverOnion, int(state), loading)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Event.DeletePeer:
|
case event.DeletePeer:
|
||||||
log.Infof("PeerHandler got DeletePeer, SHUTTING down!\n")
|
log.Infof("PeerHandler got DeletePeer, SHUTTING down!\n")
|
||||||
uiManager.ReloadProfiles()
|
uiManager.ReloadProfiles()
|
||||||
return
|
return
|
||||||
|
@ -274,7 +274,7 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
|
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 {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
ev := EventProfileEnvelope{Event: *e, Profile: onion}
|
ev := EventProfileEnvelope{Event: *e, Profile: onion}
|
||||||
|
|
|
@ -148,7 +148,7 @@ func GetPicturePath(pic *image) string {
|
||||||
case TypeImageDistro:
|
case TypeImageDistro:
|
||||||
return profilePicRelativize(pic.Val)
|
return profilePicRelativize(pic.Val)
|
||||||
default:
|
default:
|
||||||
log.Errorf("Unhandled Profile picture type of %v\n", pic.T)
|
log.Errorf("Unhandled profile picture type of %v\n", pic.T)
|
||||||
return ""
|
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) {
|
func AddProfile(gcd *GrandCentralDispatcher, handle string) {
|
||||||
p := the.CwtchApp.GetPeer(handle)
|
p := the.CwtchApp.GetPeer(handle)
|
||||||
if p != nil {
|
if p != nil {
|
||||||
|
@ -198,20 +198,20 @@ func AddProfile(gcd *GrandCentralDispatcher, handle string) {
|
||||||
online, _ := p.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
online, _ := p.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
||||||
|
|
||||||
log.Debugf("AddProfile %v %v %v %v %v\n", handle, nick, picPath, tag, online)
|
log.Debugf("AddProfile %v %v %v %v %v\n", handle, nick, picPath, tag, online)
|
||||||
gcd.AddProfile(handle, nick, picPath, tag, online == Event.True)
|
gcd.AddProfile(handle, nick, picPath, tag, online == event.True)
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
/*
|
/*
|
||||||
type manager struct {
|
type manager struct {
|
||||||
gcd *GrandCentralDispatcher
|
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)
|
// 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 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
|
// 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 {
|
type Manager interface {
|
||||||
Acknowledge(handle, mID string)
|
Acknowledge(handle, mID string)
|
||||||
AddContact(Handle string)
|
AddContact(Handle string)
|
||||||
|
@ -234,9 +234,9 @@ type Manager interface {
|
||||||
UpdateNetworkStatus(online bool)
|
UpdateNetworkStatus(online bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns a new Manager interface for a Profile to the gcd
|
// NewManager returns a new Manager interface for a profile to the gcd
|
||||||
func NewManager(Profile string, gcd *GrandCentralDispatcher) Manager {
|
func NewManager(profile string, gcd *GrandCentralDispatcher) Manager {
|
||||||
return &manager{gcd: gcd, Profile: Profile}
|
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
|
// 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) {
|
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() {
|
this.gcd.DoIfConversation(peer, func() {
|
||||||
log.Debugf("Received Error Sending Message: %v", err)
|
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
|
// 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
|
// 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) {
|
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() {
|
this.gcd.DoIfConversation(handle, func() {
|
||||||
updateLastReadTime(handle)
|
updateLastReadTime(handle)
|
||||||
// If the message is not from the user then add it, otherwise, just acknowledge.
|
// 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
|
// UpdateContactDisplayName updates a contact's display name in the contact list and conversations
|
||||||
func (this *manager) UpdateContactDisplayName(handle string) {
|
func (this *manager) UpdateContactDisplayName(handle string) {
|
||||||
this.gcd.DoIfProfile(this.Profile, func() {
|
this.gcd.DoIfProfile(this.profile, func() {
|
||||||
this.gcd.UpdateContactDisplayName(handle, GetNick(handle))
|
this.gcd.UpdateContactDisplayName(handle, GetNick(handle))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContactPicture updates a contact's picture in the contact list and conversations
|
// UpdateContactPicture updates a contact's picture in the contact list and conversations
|
||||||
func (this *manager) UpdateContactPicture(handle string) {
|
func (this *manager) UpdateContactPicture(handle string) {
|
||||||
this.gcd.DoIfProfile(this.Profile, func() {
|
this.gcd.DoIfProfile(this.profile, func() {
|
||||||
this.gcd.UpdateContactPicture(handle, GetProfilePic(handle))
|
this.gcd.UpdateContactPicture(handle, GetProfilePic(handle))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateContactAttribute update's a contacts attribute in the ui
|
// UpdateContactAttribute update's a contacts attribute in the ui
|
||||||
func (this *manager) UpdateContactAttribute(handle, key, value string) {
|
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)
|
this.gcd.UpdateContactAttribute(handle, key, value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -352,6 +352,6 @@ func (this *manager) ChangePasswordResponse(error bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *manager) UpdateNetworkStatus(online bool) {
|
func (this *manager) UpdateNetworkStatus(online bool) {
|
||||||
this.gcd.UpdateProfileNetworkStatus(this.Profile, online)
|
this.gcd.UpdateProfileNetworkStatus(this.profile, online)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue