Prefer local overrides
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2021-11-26 15:07:20 -08:00
parent 92d2925622
commit bd176f89cd
1 changed files with 96 additions and 73 deletions

View File

@ -126,19 +126,20 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline)
// Name always exists // Name always exists
e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
// Resolve the profile image of the profile.
e.Data[constants2.Picture] = RandomProfileImage(onion) e.Data[constants2.Picture] = RandomProfileImage(onion)
e.Data["Online"] = online e.Data["Online"] = online
// Construct our conversations and our srever lists
var contacts []Contact var contacts []Contact
var servers []groups.Server var servers []groups.Server
conversations, err := profile.FetchConversations() conversations, err := profile.FetchConversations()
if err != nil {
/// um....
return ""
}
for _, conversationInfo := range conversations {
if err == nil {
// We have conversations attached to this profile...
for _, conversationInfo := range conversations {
// Only compile the server info if we have enabled the experiment... // Only compile the server info if we have enabled the experiment...
// Note that this means that this info can become stale if when first loaded the experiment // Note that this means that this info can become stale if when first loaded the experiment
// has been disabled and then is later re-enabled. As such we need to ensure that this list is // has been disabled and then is later re-enabled. As such we need to ensure that this list is
@ -151,44 +152,57 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
continue continue
} }
name, exists := conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) // Prefer local override to public name...
name, exists := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name)
if !exists { if !exists {
name, exists = conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) name, exists = conversationInfo.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
if !exists { if !exists {
name = conversationInfo.Handle name = conversationInfo.Handle
} }
} }
// Resolve the profile image of the contact
var cpicPath string var cpicPath string
if conversationInfo.IsGroup() { if conversationInfo.IsGroup() {
cpicPath = RandomGroupImage(conversationInfo.Handle) cpicPath = RandomGroupImage(conversationInfo.Handle)
} else { } else {
cpicPath = RandomProfileImage(conversationInfo.Handle) cpicPath = RandomProfileImage(conversationInfo.Handle)
} }
// Resolve Save History Setting
saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey) saveHistory, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, event.SaveHistoryKey)
if !set { if !set {
saveHistory = event.DeleteHistoryDefault saveHistory = event.DeleteHistoryDefault
} }
// Resolve Archived Setting
isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived) isArchived, set := conversationInfo.GetAttribute(attr.LocalScope, attr.ProfileZone, constants2.Archived)
if !set { if !set {
isArchived = event.False isArchived = event.False
} }
// Resolve Peer State (should probably be DISCONNECTED)
state := profile.GetPeerState(conversationInfo.Handle) state := profile.GetPeerState(conversationInfo.Handle)
if !set { if !set {
state = connections.DISCONNECTED state = connections.DISCONNECTED
} }
// Resolve Conversation Auth State
// TODO: Align this with ACLs
authorization := model.AuthUnknown authorization := model.AuthUnknown
if conversationInfo.Accepted { if conversationInfo.Accepted {
authorization = model.AuthApproved authorization = model.AuthApproved
} }
// If ACL has blocked conversation then hide them...
if acl, exists := conversationInfo.ACL[conversationInfo.Handle]; exists && acl.Blocked { if acl, exists := conversationInfo.ACL[conversationInfo.Handle]; exists && acl.Blocked {
authorization = model.AuthBlocked authorization = model.AuthBlocked
} }
// Check if we are a server...
groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer) groupServer, _ := conversationInfo.GetAttribute(attr.LocalScope, attr.LegacyGroupZone, constants.GroupServer)
// Fetch the message count, and the time of the most recent message
count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0) count, err := profile.GetChannelMessageCount(conversationInfo.ID, 0)
if err != nil { if err != nil {
log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err) log.Errorf("error fetching channel message count %v %v", conversationInfo.ID, err)
@ -212,6 +226,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
IsArchived: isArchived == event.True, IsArchived: isArchived == event.True,
}) })
} }
}
bytes, _ := json.Marshal(contacts) bytes, _ := json.Marshal(contacts)
e.Data["ContactsJson"] = string(bytes) e.Data["ContactsJson"] = string(bytes)
@ -246,15 +261,23 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
// TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it...
log.Errorf("todo wait for contact to be added before processing this event...") log.Errorf("todo wait for contact to be added before processing this event...")
} }
var exists bool
ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name)
if !exists {
ev.Event.Data["Nick"], _ = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) ev.Event.Data["Nick"], _ = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
}
ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data["RemotePeer"]) ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data["RemotePeer"])
case event.NewMessageFromGroup: case event.NewMessageFromGroup:
// only needs contact nickname and picture, for displaying on popup notifications // only needs contact nickname and picture, for displaying on popup notifications
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
if ci != nil && err == nil { if ci != nil && err == nil {
var exists bool
ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name)
if !exists {
ev.Event.Data["Nick"], _ = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) ev.Event.Data["Nick"], _ = ci.GetAttribute(attr.PublicScope, attr.ProfileZone, constants.Name)
} }
}
ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.GroupID]) ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.GroupID])
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)