Skip to content

Commit

Permalink
Add gfycat/identicon from status-go
Browse files Browse the repository at this point in the history
Signed-off-by: yenda <eric@status.im>
  • Loading branch information
cammellos authored and yenda committed Sep 26, 2019
1 parent 42a65a7 commit acd7e56
Show file tree
Hide file tree
Showing 46 changed files with 612 additions and 3,630 deletions.
1 change: 0 additions & 1 deletion clj-rn.conf.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"react-native-status-keycard"
"react-native-camera"
"qrcode"
"identicon.js"
"react-native-fs"
"react-native-dialogs"
"react-native-image-resizer"
Expand Down
2 changes: 2 additions & 0 deletions externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ var TopLevel = {
"exists" : function () {},
"extPost" : function () {},
"extractGroupMembershipSignatures" : function () {},
"identicon": function() {},
"generateAlias": function() {},
"fallbacks" : function () {},
"fetch" : function () {},
"firebase" : function () {},
Expand Down
1 change: 0 additions & 1 deletion mobile/js_files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"hermes-engine": "0.2.1",
"hi-base32": "^0.5.0",
"i18n-js": "^3.3.0",
"identicon.js": "git+https://github.com/status-im/identicon.js.git#v1.2.1-status",
"qrcode": "^1.4.1",
"react": "16.8.6",
"react-dom": "16.4.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,17 @@ public void run() {
StatusThreadPoolExecutor.getInstance().execute(r);
}

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

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


@ReactMethod
public void getNodesFromContract(final String rpcEndpoint, final String contractAddress, final Callback callback) {
Log.d(TAG, "getNodesFromContract");
Expand Down
14 changes: 14 additions & 0 deletions modules/react-native-status/desktop/rctstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,17 @@ void RCTStatus::chaosModeUpdate(bool on, double callbackId) {
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
}, on, callbackId);
}

QString RCTStatus::generateAlias(QString publicKey) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::generateAlias call";
//return GenerateGfycat(publicKey.toUtf8().data());
return "test";
}

QString RCTStatus::identicon(QString publicKey) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::identicon call";
//return Identicon(publicKey.toUtf8().data());
return "test";
}
3 changes: 3 additions & 0 deletions modules/react-native-status/desktop/rctstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class RCTStatus : public QObject, public ModuleInterface {
Q_INVOKABLE static bool JSCEnabled();
Q_INVOKABLE static void statusGoEventCallback(const char* event);

Q_INVOKABLE QString identicon(QString publicKey);
Q_INVOKABLE QString generateAlias(QString publicKey);

void emitStatusGoEvent(QString event);

Q_SIGNALS:
Expand Down
8 changes: 8 additions & 0 deletions modules/react-native-status/ios/RCTStatus/RCTStatus.m
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,14 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config {
});
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(generateAlias:(NSString *)publicKey) {
return StatusgoGenerateAlias(publicKey);
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(identicon:(NSString *)publicKey) {
return StatusgoIdenticon(publicKey);
}

RCT_EXPORT_METHOD(callPrivateRPC:(NSString *)payload
callback:(RCTResponseSenderBlock)callback) {
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand Down
11 changes: 5 additions & 6 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
[chat-id {:keys [db now]}]
(let [name (get-in db [:contacts/contacts chat-id :name])]
{:chat-id chat-id
:name (or name (gfycat/generate-gfy chat-id))
:name (or name "")
:color (rand-nth colors/chat-colors)
:group-chat false
:is-active true
Expand Down Expand Up @@ -145,12 +145,11 @@
#(chats-store/save-chat % (get-in % [:db :chats chat-id])))))

(fx/defn deactivate-chat
"Deactivate chat in db, no side effects"
[{:keys [db now] :as cofx} chat-id]
(fx/merge cofx
{:db (-> db
(assoc-in [:chats chat-id :is-active] false)
(assoc-in [:current-chat-id] nil))}
#(chats-store/save-chat % (get-in % [:db :chats chat-id]))))
{:db (-> db
(assoc-in [:chats chat-id :is-active] false)
(assoc-in [:current-chat-id] nil))})

(fx/defn remove-chat
"Removes chat completely from app, producing all necessary effects for that"
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/contact/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(spec/def :contact/fcm-token (spec/nilable string?))
(spec/def :contact/last-online (spec/nilable int?))
(spec/def :contact/last-updated (spec/nilable int?))
(spec/def :contact/name :global/not-empty-string)
(spec/def :contact/name (spec/nilable string?))
(spec/def :contact/public-key :global/not-empty-string)
(spec/def :contact/photo-path (spec/nilable string?))

Expand All @@ -27,11 +27,11 @@
(spec/def :contact/tribute-transaction (spec/nilable string?))

(spec/def :contact/contact (spec/keys :req-un [:contact/address
:contact/name
:contact/photo-path
:contact/public-key
:contact/system-tags]
:opt-un [:contact/fcm-token
:contact/name
:contact/photo-path
:contact/last-online
:contact/last-updated
:contact/tags
Expand Down Expand Up @@ -65,7 +65,7 @@
(defn public-key->new-contact [public-key]
{:name (gfycat/generate-gfy public-key)
:address (ethereum/public-key->address public-key)
:photo-path (identicon/identicon public-key)
:identicon (identicon/identicon public-key)
:public-key public-key
:system-tags #{}})

Expand Down
13 changes: 7 additions & 6 deletions src/status_im/group_chats/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[clojure.spec.alpha :as spec]
[clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.utils.pairing :as pairing.utils]
[status-im.chat.models :as models.chat]
Expand Down Expand Up @@ -392,31 +393,31 @@
creator-contact (conj (format-message creator-contact
(i18n/label :t/group-chat-created
{:name chat-name
:member (:name creator-contact)})
:member (multiaccounts/displayed-name creator-contact)})
(:created-at clock-values)))
name-changed? (conj (format-message name-changed-author
(i18n/label :t/group-chat-name-changed
{:name chat-name
:member (:name name-changed-author)})
:member (multiaccounts/displayed-name name-changed-author)})
(:name-changed-at clock-values)))
(seq members-added) (concat (map #(format-message
%
(i18n/label :t/group-chat-member-added {:member (:name %)})
(i18n/label :t/group-chat-member-added {:member (multiaccounts/displayed-name %)})
(get-in clock-values [(:public-key %) :added]))
contacts-added))
(seq members-joined) (concat (map #(format-message
%
(i18n/label :t/group-chat-member-joined {:member (:name %)})
(i18n/label :t/group-chat-member-joined {:member (multiaccounts/displayed-name %)})
(get-in clock-values [(:public-key %) :joined]))
contacts-joined))
(seq admins-added) (concat (map #(format-message
%
(i18n/label :t/group-chat-admin-added {:member (:name %)})
(i18n/label :t/group-chat-admin-added {:member (multiaccounts/displayed-name %)})
(get-in clock-values [(:public-key %) :admin-added]))
admins-added))
(seq members-removed) (concat (map #(format-message
%
(i18n/label :t/group-chat-member-removed {:member (:name %)})
(i18n/label :t/group-chat-member-removed {:member (multiaccounts/displayed-name %)})
(get-in clock-values [(:public-key %) :removed]))
contacts-removed)))))

Expand Down
1 change: 0 additions & 1 deletion src/status_im/js_dependencies.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(def Chance (js/require "chance"))
(def emojis (js/require "emojilib"))
(def phishing-detect (js/require "eth-phishing-detect"))
(def identicon-js (js/require "identicon.js"))
(def BigNumber (js/require "bignumber.js"))
(def web3-utils (js/require "web3-utils"))
(def hi-base32 (js/require "hi-base32"))
18 changes: 15 additions & 3 deletions src/status_im/multiaccounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
[status-im.utils.fx :as fx]
[status-im.utils.handlers]
[status-im.utils.gfycat.core :as gfycat]
[status-im.utils.identicon :as identicon]
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]))

(defn displayed-name [account]
(let [name (or (:preferred-name account) (:name account))]
(defn displayed-name
"Use preferred name, name or alias in that order"
[{:keys [name preferred-name alias public-key]}]
(let [name (or preferred-name
name
alias)]
(if (ens/is-valid-eth-name? name)
(let [username (stateofus/username name)]
(str "@" (or username name)))
(or name (gfycat/generate-gfy (:public-key account))))))
(or name (gfycat/generate-gfy public-key)))))

(defn displayed-photo
"If a photo-path is set use it, otherwise fallback on identicon or generate"
[{:keys [photo-path identicon public-key]}]
(or photo-path
identicon
(identicon/identicon public-key)))

(re-frame/reg-fx
::chaos-mode-changed
Expand Down
13 changes: 13 additions & 0 deletions src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.native-module.core
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status_im.utils.db :as utils.db]
[status-im.react-native.js-dependencies :as rn-dependencies]
[status-im.ui.components.react :as react]
[status-im.utils.platform :as platform]
Expand Down Expand Up @@ -265,3 +266,15 @@

;; in unknown scenarios we also consider the device rooted to avoid degrading security
:else (callback true)))

(defn generate-gfycat
"Generate a 3 words random name based on the user public-key, synchronously"
[public-key]
{:pre [(utils.db/valid-public-key? public-key)]}
(.generateAlias (status) public-key))

(defn identicon
"Generate a icon based on a string, synchronously"
[seed]
(.identicon (status) seed))

20 changes: 8 additions & 12 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[status-im.group-chats.db :as group-chats.db]
[status-im.i18n :as i18n]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.multiaccounts.db :as multiaccounts.db]
[status-im.pairing.core :as pairing]
[status-im.tribute-to-talk.core :as tribute-to-talk]
Expand Down Expand Up @@ -722,9 +723,10 @@
:<- [:contacts/contacts]
:<- [:multiaccount]
(fn [[contacts multiaccount] [_ id]]
(or (:photo-path (contacts id))
(when (= id (:public-key multiaccount))
(:photo-path multiaccount)))))
(multiaccounts/displayed-photo (or (contacts id)
(when (= id (:public-key multiaccount))
multiaccount)
(contact.db/public-key->new-contact id)))))

(re-frame/reg-sub
:chats/unread-messages-number
Expand Down Expand Up @@ -1510,15 +1512,9 @@
(re-frame/subscribe [:contacts/contacts-by-chat filter chat-id])])
(fn [[chat contacts] [_ chat-id]]
(when (and chat (not (:group-chat chat)))
(cond
(:photo-path chat)
(:photo-path chat)

(pos? (count contacts))
(:photo-path (first contacts))

:else
(identicon/identicon chat-id)))))
(if (pos? (count contacts))
(multiaccounts/displayed-photo (first contacts))
(multiaccounts/displayed-photo chat)))))

(re-frame/reg-sub
:contacts/contact-by-address
Expand Down
5 changes: 3 additions & 2 deletions src/status_im/transport/message/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
in order to stop receiving that message"
[cofx now-in-s filter-chat-id message]
(let [blocked-contacts (get-in cofx [:db :contacts/blocked] #{})
{{:keys [payload sig timestamp ttl hash]} :message
{{:keys [payload timestamp]} :message
metadata :metadata
raw-payload :raw-payload} (add-raw-payload message)
status-message (-> payload
ethereum/hex-to-utf8
transit/deserialize)]
transit/deserialize)
sig (-> metadata :author :publicKey)]
(when (and sig
status-message
(not (blocked-contacts sig)))
Expand Down
2 changes: 2 additions & 0 deletions src/status_im/transport/message/protocol.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
:whisper-timestamp timestamp
:raw-payload-hash (ethereum/sha3
(.-payload (:js-obj cofx)))
:alias (get-in cofx [:metadata :author :alias])
:identicon (get-in cofx [:metadata :author :identicon])
:from signature
:metadata (:metadata cofx)
:js-obj (:js-obj cofx))]}]
Expand Down
39 changes: 25 additions & 14 deletions src/status_im/ui/components/chat_icon/screen.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.ui.components.chat-icon.screen
(:require [clojure.string :as string]
[re-frame.core :as re-frame.core]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.components.chat-icon.styles :as styles]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.react :as react]
Expand Down Expand Up @@ -42,10 +43,10 @@
[react/view pending-inner-circle]]])

(defn chat-icon-view
[{:keys [photo-path added?] :as contact} _group-chat name _online styles & [hide-dapp?]]
[{:keys [photo-path added?] :as contact} group-chat name _online styles & [hide-dapp?]]
[react/view (:container styles)
(if-not (string/blank? photo-path)
[photos/photo photo-path styles]
(if-not group-chat
[photos/photo (multiaccounts/displayed-photo contact) styles]
[default-chat-icon name styles])
(when (and contact (not added?))
[pending-contact-badge styles])])
Expand Down Expand Up @@ -90,11 +91,11 @@
:default-chat-icon-text styles/default-chat-icon-text}]])

(defn contact-icon-view
[{:keys [photo-path name dapp?]} {:keys [container] :as styles}]
[{:keys [name dapp?] :as contact} {:keys [container] :as styles}]
[react/view container
(if-not (string/blank? photo-path)
[photos/photo photo-path styles]
[default-chat-icon name styles])
(if dapp?
[default-chat-icon name styles]
[photos/photo (multiaccounts/displayed-photo contact) styles])
(when dapp?
[dapp-badge styles])])

Expand Down Expand Up @@ -168,14 +169,24 @@
[photos/photo photo-path styles]
[default-chat-icon name styles])]))

(defn my-profile-icon [{{:keys [photo-path name]} :multiaccount
edit? :edit?}]
(defn my-profile-icon [{multiaccount :multiaccount
edit? :edit?}]
(let [color colors/default-chat-color
size 64]
[profile-icon-view photo-path name color edit? size {}]))

(defn my-profile-header-icon [{{:keys [photo-path name]} :multiaccount
edit? :edit?}]
[profile-icon-view
(multiaccounts/displayed-photo multiaccount)
(multiaccounts/displayed-name multiaccount)
color
edit?
size {}]))

(defn my-profile-header-icon [{multiaccount :multiaccount
edit? :edit?}]
(let [color colors/default-chat-color
size 40]
[profile-icon-view photo-path name color edit? size {}]))
[profile-icon-view
(multiaccounts/displayed-photo multiaccount)
(multiaccounts/displayed-name multiaccount)
color
edit?
size {}]))
Loading

0 comments on commit acd7e56

Please sign in to comment.