From aef23fde74e96c6e43311d590b21eca1cfdacca3 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sun, 2 May 2021 20:43:28 -0700 Subject: [PATCH] Return Enhanced Peer Message --- lib.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib.go b/lib.go index 9857613..9766ae8 100644 --- a/lib.go +++ b/lib.go @@ -447,16 +447,24 @@ func c_GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, ha return C.CString(GetMessage(profile, handle, int(message_index))) } +// EnhancedMessage wraps a Cwtch model.Message with some additional data to reduce calls from the UI. +type EnhancedMessage struct { + model.Message + ContactImage string +} + func GetMessage(profileOnion, handle string, message_index int) string { profile := application.GetPeer(profileOnion) ph := utils.NewPeerHelper(profile) - var message model.Message + var message EnhancedMessage if ph.IsGroup(handle) { if len(profile.GetGroup(handle).Timeline.Messages) > message_index { - message = profile.GetGroup(handle).Timeline.Messages[message_index] + message.Message = profile.GetGroup(handle).Timeline.Messages[message_index] + message.ContactImage = ph.GetProfilePic(message.Message.PeerID) } } else { - message = profile.GetContact(handle).Timeline.Messages[message_index] + message.Message = profile.GetContact(handle).Timeline.Messages[message_index] + message.ContactImage = ph.GetProfilePic(handle) } bytes, _ := json.Marshal(message) return string(bytes)