From 44e5c38aa6ee2b5aa4d220d72d13eab0820e1e8c Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 7 Feb 2022 14:21:52 -0800 Subject: [PATCH] Add DefaultPicture parameter to Contact and Profiles --- constants/attributes.go | 1 + lib.go | 10 ---------- utils/contacts.go | 29 +++++++++++++++-------------- utils/eventHandler.go | 32 +++++++++++++++++--------------- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/constants/attributes.go b/constants/attributes.go index 78031c4..122f390 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -5,6 +5,7 @@ const SchemaVersion = "schemaVersion" const Name = "name" const LastRead = "last-read" const Picture = "picture" +const DefaultProfilePicture = "defaultPicture" const ShowBlocked = "show-blocked" const Archived = "archived" diff --git a/lib.go b/lib.go index 25e0390..8823381 100644 --- a/lib.go +++ b/lib.go @@ -741,16 +741,6 @@ func ShareFile(profileOnion string, conversationID int, sharefilepath string) { // FIXME: At some point we might want to allow arbitrary public files, but for now this API will assume // there is only one, and it is the custom profile image... profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants2.CustomProfileImageKey, fileKey) - path, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - // tell the UI the the file has been "downloaded" - if exists { - eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{ - ProfileOnion: profileOnion, - event.FileKey: fileKey, - event.FilePath: path, - event.TempFile: "", - })) - } } else { profile.SendMessage(conversationID, overlay) } diff --git a/utils/contacts.go b/utils/contacts.go index 9ddeabf..4d5ae57 100644 --- a/utils/contacts.go +++ b/utils/contacts.go @@ -1,18 +1,19 @@ package utils type Contact struct { - Name string `json:"name"` - Onion string `json:"onion"` - Status string `json:"status"` - Picture string `json:"picture"` - Accepted bool `json:"accepted"` - Blocked bool `json:"blocked"` - SaveHistory string `json:"saveConversationHistory"` - Messages int `json:"numMessages"` - Unread int `json:"numUnread"` - LastMessage string `json:"lastMsgTime"` - IsGroup bool `json:"isGroup"` - GroupServer string `json:"groupServer"` - IsArchived bool `json:"isArchived"` - Identifier int `json:"identifier"` + Name string `json:"name"` + Onion string `json:"onion"` + Status string `json:"status"` + Picture string `json:"picture"` + DefaultPicture string `json:"defaultPicture"` + Accepted bool `json:"accepted"` + Blocked bool `json:"blocked"` + SaveHistory string `json:"saveConversationHistory"` + Messages int `json:"numMessages"` + Unread int `json:"numUnread"` + LastMessage string `json:"lastMsgTime"` + IsGroup bool `json:"isGroup"` + GroupServer string `json:"groupServer"` + IsArchived bool `json:"isArchived"` + Identifier int `json:"identifier"` } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 08c261d..32cf941 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -130,7 +130,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { online, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerOnline) // Name always exists e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) - + e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion) // if a custom profile image exists then default to it. key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) if !exists { @@ -221,20 +221,21 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { lastMessage, _ := profile.GetMostRecentMessages(conversationInfo.ID, 0, 0, 1) contacts = append(contacts, Contact{ - Name: name, - Identifier: conversationInfo.ID, - Onion: conversationInfo.Handle, - Status: connections.ConnectionStateName[state], - Picture: cpicPath, - Accepted: conversationInfo.Accepted, - Blocked: blocked, - SaveHistory: saveHistory, - Messages: count, - Unread: 0, - LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), - IsGroup: conversationInfo.IsGroup(), - GroupServer: groupServer, - IsArchived: isArchived == event.True, + Name: name, + Identifier: conversationInfo.ID, + Onion: conversationInfo.Handle, + Status: connections.ConnectionStateName[state], + Picture: cpicPath, + DefaultPicture: RandomProfileImage(conversationInfo.Handle), + Accepted: conversationInfo.Accepted, + Blocked: blocked, + SaveHistory: saveHistory, + Messages: count, + Unread: 0, + LastMessage: strconv.Itoa(getLastMessageTime(lastMessage)), + IsGroup: conversationInfo.IsGroup(), + GroupServer: groupServer, + IsArchived: isArchived == event.True, }) } } @@ -356,6 +357,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... ev.Event.Data[constants2.Picture] = RandomProfileImage(conversationInfo.Handle) + ev.Event.Data[constants2.DefaultProfilePicture] = RandomProfileImage(conversationInfo.Handle) ev.Event.Data["numMessages"] = strconv.Itoa(count) ev.Event.Data["nick"] = conversationInfo.Handle ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)]