Skip to content

Commit

Permalink
feat: import push notifications from weshnet
Browse files Browse the repository at this point in the history
Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
  • Loading branch information
D4ryl00 committed Mar 15, 2024
1 parent 8ba1bfa commit 4fd1ace
Show file tree
Hide file tree
Showing 57 changed files with 45,048 additions and 2,918 deletions.
10 changes: 5 additions & 5 deletions api/accounttypes/accounttypes.proto
Expand Up @@ -3,7 +3,7 @@ syntax = "proto3";
package berty.account.v1;

import "gogoproto/gogo.proto";
import "pushtypes/pushtypes.proto";
import "pushtypes/bertypushtypes.proto";
import "protocoltypes.proto";

option go_package = "berty.tech/berty/go/pkg/accounttypes";
Expand Down Expand Up @@ -360,17 +360,17 @@ message NetworkConfigGetPreset {
message PushReceive {
message Request {
string payload = 1;
weshnet.push.v1.PushServiceTokenType token_type = 2;
berty.push.v1.PushServiceTokenType token_type = 2;
}
message Reply {
weshnet.push.v1.DecryptedPush push_data = 1;
weshnet.push.v1.FormatedPush push = 2;
berty.push.v1.DecryptedPush push_data = 1;
berty.push.v1.FormatedPush push = 2;
}
}

message PushPlatformTokenRegister {
message Request {
weshnet.protocol.v1.PushServiceReceiver receiver = 1;
push.v1.PushServiceReceiver receiver = 1;
}
message Reply {}
}
15 changes: 15 additions & 0 deletions api/berty/errcode.proto
Expand Up @@ -171,6 +171,21 @@ enum ErrCode {
ErrBertyAccountCreationFailed = 5016;
ErrBertyAccountUpdateFailed = 5017;
ErrAppStorageNotSupported = 5018;

// Push Services

ErrPush = 6000;
ErrPushWrongAccount = 6001;
ErrPushUnableToDecrypt = 6002;
ErrPushInvalidPayload = 6003;
ErrPushInvalidServerConfig = 6004;
ErrPushMissingBundleID = 6005;
ErrPushUnknownDestination = 6006;
ErrPushProvider = 6007;
ErrPushUnknownProvider = 6008;
ErrNoProvidersConfigured = 6009;
ErrInvalidPrivateKey = 6010;
ErrPushServerNotFound = 6011;
}

message ErrDetails { repeated ErrCode codes = 1; }
168 changes: 150 additions & 18 deletions api/messengertypes/messengertypes.proto
Expand Up @@ -4,11 +4,15 @@ package berty.messenger.v1;

import "gogoproto/gogo.proto";
import "protocoltypes.proto";
import "pushtypes/bertypushtypes.proto";

option go_package = "berty.tech/berty/go/pkg/messengertypes";
option (gogoproto.goproto_unkeyed_all) = false;
option (gogoproto.goproto_unrecognized_all) = false;
option (gogoproto.goproto_sizecache_all) = false;
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.sizer_all) = true;

// MessengerService is the top-level API that uses the weshnet.protocol to implement the Berty Messenger specific logic.
// Today, most of the Berty Messenger logic is implemented directly in the application (see the /js folder of this repo).
Expand Down Expand Up @@ -96,6 +100,16 @@ service MessengerService {
// PushReceive handles a push payload, decrypts it if possible, adds it to the local store
rpc PushReceive(PushReceive.Request) returns (PushReceive.Reply);

// PushSend sends a push payload to a specified list of group members
rpc PushSend(PushSend.Request) returns (PushSend.Reply);

// PushSetDeviceToken registers a push token for the current device
rpc PushSetDeviceToken(PushSetDeviceToken.Request) returns (PushSetDeviceToken.Reply);

// PushSetServer registers a push server for the current device
rpc PushSetServer(PushSetServer.Request) returns (PushSetServer.Reply);


// DirectoryServiceRegister registers a verified credential on a directory service
rpc DirectoryServiceRegister(DirectoryServiceRegister.Request) returns (DirectoryServiceRegister.Reply);

Expand Down Expand Up @@ -329,6 +343,9 @@ message AppMessage {
reserved 7; // TypeReplyOptions
TypeAccountDirectoryServiceRegistered = 8;
TypeAccountDirectoryServiceUnregistered = 9;
TypePushSetDeviceToken = 10;
TypePushSetServer = 11;
TypePushSetMemberToken = 12;
}
message UserMessage {
string body = 1;
Expand Down Expand Up @@ -364,6 +381,18 @@ message AppMessage {
string server_addr = 4;
string directory_record_token = 5;
}

message PushSetDeviceToken {
push.v1.PushServiceReceiver device_token = 1;
}

message PushSetServer {
PushServer server = 1;
}

message PushSetMemberToken {
PushMemberTokenUpdate member_token = 1;
}
}

message SystemInfo {
Expand Down Expand Up @@ -391,9 +420,12 @@ message SystemInfo {
int64 conversation_replication_info = 8;
int64 metadata_events = 10;
reserved 11; // int64 medias = 11;
int64 shared_push_tokens = 12;
int64 push_member_token = 12;
int64 account_verified_credentials = 13;
int64 account_directory_service_record = 14;
int64 push_device_token = 15;
int64 push_server_record = 16;
int64 push_local_device_shared_token = 17;
// older, more recent
}
}
Expand All @@ -419,8 +451,8 @@ message Account {
bool replicate_new_groups_automatically = 6 [(gogoproto.moretags) = "gorm:\"default:true\""];
reserved 7; // string avatar_cid = 7 [(gogoproto.moretags) = "gorm:\"column:avatar_cid\"", (gogoproto.customname) = "AvatarCID"];
bool auto_share_push_token_flag = 8;
bytes device_push_token = 9;
bytes device_push_server = 10;
PushDeviceToken push_device_token = 9 [(gogoproto.moretags) = "gorm:\"foreignKey:AccountPK\""];
repeated PushServerRecord push_server_records = 10 [(gogoproto.moretags) = "gorm:\"foreignKey:AccountPK\""];
int64 muted_until = 11;
bool hide_in_app_notifications = 12;
bool hide_push_previews = 13;
Expand Down Expand Up @@ -463,15 +495,15 @@ message Interaction {

message Contact {
string public_key = 1 [(gogoproto.moretags) = "gorm:\"primaryKey\""];
string conversation_public_key = 2;
string conversation_public_key = 2 [(gogoproto.moretags) = "gorm:\"primaryKey\""];
Conversation conversation = 3;
State state = 4;
string display_name = 5;
reserved 9; // string avatar_cid = 9 [(gogoproto.moretags) = "gorm:\"column:avatar_cid\"", (gogoproto.customname) = "AvatarCID"];
int64 created_date = 7;
// specific to outgoing requests
int64 sent_date = 8;
repeated Device devices = 6 [(gogoproto.moretags) = "gorm:\"foreignKey:MemberPublicKey\""];
repeated Device devices = 6 [(gogoproto.moretags) = "gorm:\"foreignKey:MemberPublicKey;references:PublicKey\""];
int64 info_date = 10;

enum State {
Expand Down Expand Up @@ -514,9 +546,10 @@ message Conversation {
reserved 17; // string avatar_cid = 17 [(gogoproto.moretags) = "gorm:\"column:avatar_cid\"", (gogoproto.customname) = "AvatarCID"];
// info_date is used when SetGroupInfo is called
int64 info_date = 18;
string shared_push_token_identifier = 19;
string local_member_public_key = 20;
int64 muted_until = 21;
string local_member_public_key = 19;
int64 muted_until = 20;
repeated PushLocalDeviceSharedToken push_local_device_shared_tokens = 21 [(gogoproto.moretags) = "gorm:\"foreignKey:ConversationPublicKey\""];
repeated PushMemberToken push_member_tokens = 22 [(gogoproto.moretags) = "gorm:\"foreignKey:ConversationPublicKey\""];
}

message ConversationReplicationInfo {
Expand Down Expand Up @@ -544,13 +577,6 @@ message Device {
string member_public_key = 2 [(gogoproto.moretags) = "gorm:\"index\""];
}

message SharedPushToken {
string device_public_key = 1 [(gogoproto.moretags) = "gorm:\"index\""];
string member_public_key = 2 [(gogoproto.moretags) = "gorm:\"index\""];
string conversation_public_key = 3 [(gogoproto.moretags) = "gorm:\"index\""];
string token = 4 [(gogoproto.moretags) = "gorm:\"index\""];
}

message AccountVerifiedCredential {
string account_pk = 1 [(gogoproto.customname) = "AccountPK"];
string identifier = 2;
Expand All @@ -571,6 +597,30 @@ message AccountDirectoryServiceRecord {
string directory_record_unregister_token = 9;
}

message PushDeviceToken {
// account_pk is the account public key that owns the device token
string account_pk = 1 [(gogoproto.customname) = "AccountPK", (gogoproto.moretags) = "gorm:\"primaryKey\""];
// token_type is the type of the token used, it allows us to act as a proxy to the appropriate push server
push.v1.PushServiceTokenType token_type = 2;

// bundle_id is the app identifier
string bundle_id = 3 [(gogoproto.customname) = "BundleID"];

// token is the device identifier used
bytes token = 4;

// public_key is the public key which will be used to encrypt the payload
bytes public_key = 5;
}

message PushServerRecord {
string account_pk = 1 [(gogoproto.customname) = "AccountPK", (gogoproto.moretags) = "gorm:\"primaryKey\""];

string server_addr = 2 [(gogoproto.moretags) = "gorm:\"primaryKey\""];

bytes server_key = 3;
}

message ContactMetadata {
string display_name = 1;
}
Expand Down Expand Up @@ -856,6 +906,13 @@ message TyberHostAttach {
}
}

message PushSetDeviceToken {
message Request {
push.v1.PushServiceReceiver receiver = 1;
}
message Reply {}
}

message PushSetAutoShare {
message Request {
bool enabled = 1;
Expand All @@ -865,8 +922,7 @@ message PushSetAutoShare {
}

message PushReceivedData {
// weshnet.protocol.v1.PushReceive.Reply protocol_data = 1;
bytes protocol_data = 1; // @FIXME(push): weshnet.protocol.v1.PushReceive.Reply has been removed
weshnet.protocol.v1.OutOfStoreReceive.Reply protocol_data = 1;
Interaction interaction = 2;
bool already_received = 3;
bool account_muted = 4;
Expand Down Expand Up @@ -905,7 +961,7 @@ message PushTokenSharedForConversation {
string conversation_pk = 1 [(gogoproto.customname) = "ConversationPK"];
}
message Reply {
SharedPushToken push_token = 1;
PushMemberToken token = 1;
}
}

Expand Down Expand Up @@ -941,3 +997,79 @@ message DirectoryServiceQuery {
bytes verified_credential = 4;
}
}

message PushServer {
string addr = 1;
bytes key = 2;
}

message PushLocalDeviceSharedToken {
string token_id = 1 [(gogoproto.moretags) = "gorm:\"primaryKey\"", (gogoproto.customname) = "TokenID"];
// group_pk is the public key of the group for whom the token is for
string conversation_public_key = 2;
}

message PushMemberToken {
// token_id is the id of the token
string token_id = 1 [(gogoproto.moretags) = "gorm:\"primaryKey\"", (gogoproto.customname) = "TokenID"];

// group_pk is the public key of the group for whom the token is for
string conversation_public_key = 2;

// device_pk is the public key of the device sending the message
string device_pk = 3 [(gogoproto.customname) = "DevicePK"];

// server_addr is the push server address
string server_addr = 4;

// server_key is the push server public key
bytes server_key = 5;

// token is the sealed token of the device
bytes token = 6;
}

message PushMemberTokenUpdate {
// device_pk is the public key of the device sending the message
string device_pk = 1 [(gogoproto.customname) = "DevicePK"];

// server is the push server to use
PushServer server = 2;

// token is the sealed token of the device
bytes token = 3;
}

message MemberWithDevices {
string member_pk = 1 [(gogoproto.customname) = "MemberPK"];
repeated string devices_pks = 2 [(gogoproto.customname) = "DevicePKs"];
}

message PushSend {
message Request {
bytes cid = 1 [(gogoproto.customname) = "CID"];
string group_pk = 2 [(gogoproto.customname) = "GroupPK"];
repeated MemberWithDevices group_members = 3;
}
message Reply {
repeated MemberWithDevices group_members = 1;
}
}

message PushShareToken {
message Request {
string device_pk = 1 [(gogoproto.customname) = "DevicePK"];
string group_pk = 2 [(gogoproto.customname) = "GroupPK"];
PushServer server = 3;
push.v1.PushServiceReceiver receiver = 4;
}
message Reply {}
}

message PushSetServer {
message Request {
PushServer server = 1;
}
message Reply {}
}

0 comments on commit 4fd1ace

Please sign in to comment.