Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing avatar and name in members of the community channels and group chats #20619

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public String hexToUtf8(final String str) {
return Statusgo.hexToUtf8(str);
}

@ReactMethod(isBlockingSynchronousMethod = true)
public String serializeLegacyKey(final String publicKey) {
return Statusgo.serializeLegacyKey(publicKey);
}

@ReactMethod
public void setBlankPreviewFlag(final Boolean blankPreview) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.reactContext);
Expand Down
4 changes: 4 additions & 0 deletions modules/react-native-status/ios/RCTStatus/EncryptionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ @implementation EncryptionUtils
return StatusgoHexToUtf8(str);
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(serializeLegacyKey:(NSString *)str) {
return StatusgoSerializeLegacyKey(str);
}

RCT_EXPORT_METHOD(setBlankPreviewFlag:(BOOL *)newValue)
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
Expand Down
33 changes: 33 additions & 0 deletions modules/react-native-status/nodejs/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,38 @@ void _Sha3(const FunctionCallbackInfo<Value>& args) {

}

void _SerializeLegacyKey(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();

if (args.Length() != 1) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8Literal(isolate, "Wrong number of arguments for SerializeLegacyKey")));
return;
}

// Check the argument types

if (!args[0]->IsString()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8Literal(isolate, "Wrong argument type for 'str'")));
return;
}


String::Utf8Value arg0Obj(isolate, args[0]->ToString(context).ToLocalChecked());
char *arg0 = *arg0Obj;

// Call exported Go function, which returns a C string
char *c = SerializeLegacyKey(arg0);

Local<String> ret = String::NewFromUtf8(isolate, c).ToLocalChecked();
args.GetReturnValue().Set(ret);
delete c;

}

void _ToChecksumAddress(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Expand Down Expand Up @@ -1976,6 +2008,7 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "checkAddressChecksum", _CheckAddressChecksum);
NODE_SET_METHOD(exports, "isAddress", _IsAddress);
NODE_SET_METHOD(exports, "sha3", _Sha3);
NODE_SET_METHOD(exports, "serializeLegacyKey", _SerializeLegacyKey);
NODE_SET_METHOD(exports, "toChecksumAddress", _ToChecksumAddress);
NODE_SET_METHOD(exports, "logout", _Logout);
NODE_SET_METHOD(exports, "hashMessage", _HashMessage);
Expand Down
5 changes: 5 additions & 0 deletions src/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@
:key input-key})
(.deserializeAndCompressKey ^js (encryption) input-key callback))

(defn serialize-legacy-key
"Compresses an old format public key (0x04...) to the new one zQ..."
[public-key]
(.serializeLegacyKey ^js (encryption) public-key))

(defn compressed-key->public-key
"Provides compressed key to status-go and gets back the uncompressed public key via deserialization"
[public-key deserialization-key callback]
Expand Down
18 changes: 15 additions & 3 deletions src/status_im/subs/chats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.contexts.chat.events :as chat.events]
[status-im.contexts.profile.utils :as profile.utils]))
[status-im.contexts.profile.utils :as profile.utils]
[status-im.subs.contact.utils :as contact.utils]))

(def memo-chats-stack-items (atom nil))

Expand Down Expand Up @@ -259,8 +260,19 @@
:chats/photo-path
:<- [:contacts/contacts]
:<- [:profile/profile-with-image]
(fn [[contacts {:keys [public-key] :as multiaccount}] [_ id]]
(let [contact (or (when (= id public-key) multiaccount) (get contacts id))]
:<- [:mediaserver/port]
:<- [:initials-avatar-font-file]
:<- [:theme]
(fn [[contacts {:keys [public-key] :as multiaccount} port font-file theme] [_ id]]
(let [contact (or (when (= id public-key) multiaccount)
(get contacts id)
(contact.utils/replace-contact-image-uri
{:contact {:public-key id
:customization-color constants/profile-default-color}
:port port
:public-key id
:font-file font-file
:theme theme}))]
(profile.utils/photo contact))))

(re-frame/reg-sub
Expand Down
67 changes: 18 additions & 49 deletions src/status_im/subs/contact.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
[legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
[quo.theme]
[re-frame.core :as re-frame]
[status-im.common.pixel-ratio :as pixel-ratio]
[status-im.constants :as constants]
[status-im.contexts.profile.utils :as profile.utils]
[status-im.subs.chat.utils :as chat.utils]
[status-im.subs.contact.utils :as contact.utils]
[utils.address :as address]
[utils.collection]
[utils.i18n :as i18n]))
Expand Down Expand Up @@ -37,50 +37,6 @@
(fn [multiaccount]
(get multiaccount :profile-pictures-visibility)))

(defn- replace-contact-image-uri
[contact port public-key font-file theme]
(let [{:keys [images ens-name customization-color]} contact
images
(reduce (fn [acc image]
(let [image-name (:type image)
clock (:clock image)
options {:port port
:ratio pixel-ratio/ratio
:public-key
public-key
:image-name
image-name
; We pass the clock so that we reload the
; image if the image is updated
:clock
clock
:theme
theme
:override-ring?
(when ens-name false)}]
(assoc-in acc
[(keyword image-name) :config]
{:type :contact
:options options})))
images
(vals images))

images (if (seq images)
images
{:thumbnail
{:config {:type :initials
:options {:port port
:ratio pixel-ratio/ratio
:public-key public-key
:override-ring? (when ens-name false)
:uppercase-ratio (:uppercase-ratio
constants/initials-avatar-font-conf)
:customization-color customization-color
:theme theme
:font-file font-file}}}})]

(assoc contact :images images)))

(defn- enrich-contact
([contact] (enrich-contact contact nil nil))
([{:keys [public-key] :as contact} setting own-public-key]
Expand All @@ -103,7 +59,12 @@
(defn- reduce-contacts-image-uri
[contacts port font-file theme]
(reduce-kv (fn [acc public-key contact]
(let [contact (replace-contact-image-uri contact port public-key font-file theme)]
(let [contact (contact.utils/replace-contact-image-uri
{:contact contact
:port port
:public-key public-key
:font-file font-file
:theme theme})]
(assoc acc public-key contact)))
{}
contacts))
Expand Down Expand Up @@ -230,7 +191,12 @@
[_ contact-identity ens-name port font-file theme]
(let [contact (enrich-contact
(public-key-and-ens-name->new-contact contact-identity ens-name))]
(replace-contact-image-uri contact port contact-identity font-file theme)))
(contact.utils/replace-contact-image-uri
{:contact contact
:port port
:public-key contact-identity
:font-file font-file
:theme theme})))

(re-frame/reg-sub
:contacts/current-contact
Expand All @@ -250,7 +216,10 @@
:contacts/contact-by-identity
:<- [:contacts/contacts]
(fn [contacts [_ contact-identity]]
(get contacts contact-identity {:public-key contact-identity})))
(get
contacts
contact-identity
(contact.utils/build-contact-from-public-key contact-identity))))

(re-frame/reg-sub
:contacts/contact-two-names-by-identity
Expand Down Expand Up @@ -288,7 +257,7 @@
(assoc public-key current-contact))]
(->> members
(map #(or (get all-contacts %)
{:public-key %}))
(contact.utils/build-contact-from-public-key %)))
(sort-by (comp string/lower-case
(fn [{:keys [primary-name name alias public-key]}]
(or primary-name
Expand Down
54 changes: 54 additions & 0 deletions src/status_im/subs/contact/utils.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(ns status-im.subs.contact.utils
(:require
[native-module.core :as native-module]
[status-im.common.pixel-ratio :as pixel-ratio]
[status-im.constants :as constants]
[utils.address :as address]))

(defn replace-contact-image-uri
[{:keys [contact port public-key font-file theme]}]
(let [{:keys [images ens-name customization-color]} contact
images
(reduce (fn [acc image]
(let [image-name (:type image)
clock (:clock image)
options {:port port
:ratio pixel-ratio/ratio
:public-key public-key
:image-name image-name
; We pass the clock so that we reload the
; image if the image is updated
:clock clock
:theme theme
:override-ring? (when ens-name false)}]
(assoc-in acc
[(keyword image-name) :config]
{:type :contact
:options options})))
images
(vals images))

images (if (seq images)
images
{:thumbnail
{:config {:type :initials
:options {:port port
:ratio pixel-ratio/ratio
:public-key public-key
:override-ring? (when ens-name false)
:uppercase-ratio (:uppercase-ratio
constants/initials-avatar-font-conf)
:customization-color customization-color
:theme theme
:font-file font-file}}}})]

(assoc contact :images images)))


(defn build-contact-from-public-key
[public-key]
(when public-key
(let [compressed-key (native-module/serialize-legacy-key public-key)]
{:public-key public-key
:compressed-key compressed-key
:primary-name (address/get-shortened-compressed-key (or compressed-key public-key))})))
2 changes: 2 additions & 0 deletions src/tests/test_utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
(clj->js
{:sha3
(fn [s] (.sha3 native-status s))
:serializeLegacyKey
(fn [s] (.serializeLegacyKey native-status s))
:setBlankPreviewFlag
identity
:encodeTransfer
Expand Down