Skip to content

Commit

Permalink
feat: new deeplink status-im->status-app
Browse files Browse the repository at this point in the history
Signed-off-by: yqrashawn <namy.19@gmail.com>
  • Loading branch information
yqrashawn committed Oct 26, 2023
1 parent 27b770c commit 4617ba3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
22 changes: 18 additions & 4 deletions protocol/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"math/rand"
"strings"
"time"

"github.com/status-im/status-go/deprecation"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
v1protocol "github.com/status-im/status-go/protocol/v1"
"github.com/status-im/status-go/services/utils"
)

var chatColors = []string{
Expand Down Expand Up @@ -501,18 +503,30 @@ func CreateCommunityChat(orgID, chatID string, orgChat *protobuf.CommunityChat,

func (c *Chat) DeepLink() string {
if c.OneToOne() {
return "status-im://p/" + c.ID
return "status-app://p/" + c.ID
}
if c.PrivateGroupChat() {
return "status-im://g/args?a2=" + c.ID
return "status-app://g/args?a2=" + c.ID
}

if c.CommunityChat() {
return "status-im://cc/" + c.ID
communityChannelID := strings.TrimPrefix(c.ID, c.CommunityID)
pubkey, err := types.DecodeHex(c.CommunityID)
if err != nil {
return ""
}

base58CommunityID, err := utils.SerializePublicKey(pubkey)

if err != nil {
return ""
}

return "status-app://cc/" + communityChannelID + "#" + base58CommunityID
}

if c.Public() {
return "status-im://" + c.ID
return "status-app://" + c.ID
}

return ""
Expand Down
10 changes: 10 additions & 0 deletions protocol/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ func (s *ChatTestSuite) TestUpdateFirstMessageTimestamp() {
setAndCheck(FirstMessageTimestampNoMessage, false, 200)
setAndCheck(100, true, 100)
}

func (s *ChatTestSuite) TestDeepLink() {
chat := &Chat{
CommunityID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89e",
ID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89ec432709e-fc73-440d-bb67-cb3a0929dfda",
ChatType: ChatTypeCommunityChat,
}

s.Require().Equal(chat.DeepLink(), "status-app://cc/c432709e-fc73-440d-bb67-cb3a0929dfda#zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo")
}
2 changes: 1 addition & 1 deletion protocol/local_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (n NotificationBody) toCommunityRequestToJoinNotification(id string) *local
Message: n.Contact.PrimaryName() + " wants to join message " + n.Community.Name(),
BodyType: localnotifications.TypeMessage,
Category: localnotifications.CategoryCommunityRequestToJoin,
Deeplink: "status-im://cr/" + n.Community.IDString(),
Deeplink: "status-app://cr/" + n.Community.IDString(),
Image: "",
}
}
15 changes: 1 addition & 14 deletions protocol/messenger_share_urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,7 @@ const baseShareURL = "https://status.app"
const channelUUIDRegExp = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$"

func (m *Messenger) SerializePublicKey(compressedKey types.HexBytes) (string, error) {
rawKey, err := crypto.DecompressPubkey(compressedKey)
if err != nil {
return "", err
}
pubKey := types.EncodeHex(crypto.FromECDSAPub(rawKey))

secp256k1Code := "0xe701"
base58btc := "z"
multiCodecKey := secp256k1Code + strings.TrimPrefix(pubKey, "0x")
cpk, err := multiformat.SerializePublicKey(multiCodecKey, base58btc)
if err != nil {
return "", err
}
return cpk, nil
return utils.SerializePublicKey(compressedKey)
}

func (m *Messenger) DeserializePublicKey(compressedKey string) (types.HexBytes, error) {
Expand Down
2 changes: 1 addition & 1 deletion services/local-notifications/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type transactionState string

const (
walletDeeplinkPrefix = "status-im://wallet/"
walletDeeplinkPrefix = "status-app://wallet/"

failed transactionState = "failed"
inbound transactionState = "inbound"
Expand Down
17 changes: 17 additions & 0 deletions services/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ func DeserializePublicKey(compressedKey string) (types.HexBytes, error) {

return crypto.CompressPubkey(pubKey), nil
}

func SerializePublicKey(compressedKey types.HexBytes) (string, error) {
rawKey, err := crypto.DecompressPubkey(compressedKey)
if err != nil {
return "", err
}
pubKey := types.EncodeHex(crypto.FromECDSAPub(rawKey))

secp256k1Code := "0xe701"
base58btc := "z"
multiCodecKey := secp256k1Code + strings.TrimPrefix(pubKey, "0x")
cpk, err := multiformat.SerializePublicKey(multiCodecKey, base58btc)
if err != nil {
return "", err
}
return cpk, nil
}

0 comments on commit 4617ba3

Please sign in to comment.