Skip to content

Commit

Permalink
add preview-client.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
felicio committed Feb 10, 2023
1 parent 72c58aa commit 058d989
Show file tree
Hide file tree
Showing 17 changed files with 4,155 additions and 806 deletions.
7 changes: 5 additions & 2 deletions packages/status-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"typegen": "tsc --noEmit false --emitDeclarationOnly || true",
"lint": "eslint src",
"format": "prettier --write src",
"protos": "protons protos/*.proto",
"proto:lint": "buf lint",
"proto": "buf generate",
"protos": "protons src/protos/*.proto",
"clean": "rm -rf dist node_modules .turbo"
},
"dependencies": {
Expand All @@ -38,7 +40,8 @@
"protons-runtime": "^1.0.4"
},
"devDependencies": {
"protons": "^3.0.4"
"protons": "^3.0.4",
"ts-proto": "^1.115.1"
},
"files": [
"dist/",
Expand Down
74 changes: 74 additions & 0 deletions packages/status-js/proto/communities/v1/chat_identity.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
syntax = "proto3";

package communities.v1;

import "communities/v1/enums.proto";

// Cha// ChatIdentity represents the user defined identity associated with their public chat key
message ChatIdentity {
// Lamport timestamp of the message
uint64 clock = 1;

// ens_name is the valid ENS name associated with the chat key
string ens_name = 2;

// images is a string indexed mapping of images associated with an identity
map<string, IdentityImage> images = 3;

// display name is the user set identity
string display_name = 4;

// description is the user set description
string description = 5;

string color = 6;

string emoji = 7;

repeated SocialLink social_links = 8;

// first known message timestamp in seconds (valid only for community chats for now)
// 0 - unknown
// 1 - no messages
uint32 first_message_timestamp = 9;
}

// ProfileImage represents data associated with a user's profile image
message IdentityImage {

// payload is a context based payload for the profile image data,
// context is determined by the `source_type`
bytes payload = 1;

// source_type signals the image payload source
SourceType source_type = 2;

// image_type signals the image type and method of parsing the payload
ImageType image_type = 3;

// encryption_keys is a list of encrypted keys that can be used to decrypted an encrypted payload
repeated bytes encryption_keys = 4;

// encrypted signals the encryption state of the payload, default is false.
bool encrypted = 5;

// SourceType are the predefined types of image source allowed
enum SourceType {
UNKNOWN_SOURCE_TYPE = 0;

// RAW_PAYLOAD image byte data
RAW_PAYLOAD = 1;

// ENS_AVATAR uses the ENS record's resolver get-text-data.avatar data
// The `payload` field will be ignored if ENS_AVATAR is selected
// The application will read and parse the ENS avatar data as image payload data, URLs will be ignored
// The parent `ChatMessageIdentity` must have a valid `ens_name` set
ENS_AVATAR = 2;
}
}

// SocialLinks represents social link assosiated with given chat identity (personal/community)
message SocialLink {
string text = 1;
string url = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ message CommunityMember {
UNKNOWN_ROLE = 0;
ROLE_ALL = 1;
ROLE_MANAGE_USERS = 2;
ROLE_MODERATE_CONTENT = 3;
}
repeated Roles roles = 1;
}
Expand All @@ -42,6 +43,16 @@ message CommunityDescription {
map<string,CommunityChat> chats = 6;
repeated string ban_list = 7;
map<string,CommunityCategory> categories = 8;
uint64 archive_magnetlink_clock = 9;
CommunityAdminSettings admin_settings = 10;
string intro_message = 11;
string outro_message = 12;
bool encrypted = 13;
repeated string tags = 14;
}

message CommunityAdminSettings {
bool pin_message_all_members_enabled = 1;
}

message CommunityChat {
Expand Down Expand Up @@ -70,11 +81,67 @@ message CommunityRequestToJoin {
string ens_name = 2;
string chat_id = 3;
bytes community_id = 4;
string display_name = 5;
}

message CommunityCancelRequestToJoin {
uint64 clock = 1;
string ens_name = 2;
string chat_id = 3;
bytes community_id = 4;
string display_name = 5;
}

message CommunityRequestToJoinResponse {
uint64 clock = 1;
CommunityDescription community = 2;
bool accepted = 3;
bytes grant = 4;
bytes community_id = 5;
string magnet_uri = 6;
}

message CommunityRequestToLeave {
uint64 clock = 1;
bytes community_id = 2;
}

message CommunityMessageArchiveMagnetlink {
uint64 clock = 1;
string magnet_uri = 2;
}

message WakuMessage {
bytes sig = 1;
uint64 timestamp = 2;
bytes topic = 3;
bytes payload = 4;
bytes padding = 5;
bytes hash = 6;
string thirdPartyId = 7;
}

message WakuMessageArchiveMetadata {
uint32 version = 1;
uint64 from = 2;
uint64 to = 3;
repeated bytes contentTopic = 4;
}

message WakuMessageArchive {
uint32 version = 1;
WakuMessageArchiveMetadata metadata = 2;
repeated WakuMessage messages = 3;
}

message WakuMessageArchiveIndexMetadata {
uint32 version = 1;
WakuMessageArchiveMetadata metadata = 2;
uint64 offset = 3;
uint64 size = 4;
uint64 padding = 5;
}

message WakuMessageArchiveIndex {
map<string, WakuMessageArchiveIndexMetadata> archives = 1;
}
25 changes: 25 additions & 0 deletions packages/status-js/proto/communities/v1/enums.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";

package communities.v1;

enum MessageType {
UNKNOWN_MESSAGE_TYPE = 0;
ONE_TO_ONE = 1;
PUBLIC_GROUP = 2;
PRIVATE_GROUP = 3;
// Only local
SYSTEM_MESSAGE_PRIVATE_GROUP = 4;
COMMUNITY_CHAT = 5;
// Only local
SYSTEM_MESSAGE_GAP = 6;
}

enum ImageType {
UNKNOWN_IMAGE_TYPE = 0;

// Raster image files is payload data that can be read as a raster image
PNG = 1;
JPEG = 2;
WEBP = 3;
GIF = 4;
}
105 changes: 105 additions & 0 deletions packages/status-js/proto/communities/v1/push_notifications.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
syntax = "proto3";

package communities.v1;

import "communities/v1/chat_identity.proto";

message PushNotificationRegistration {
enum TokenType {
UNKNOWN_TOKEN_TYPE = 0;
APN_TOKEN = 1;
FIREBASE_TOKEN = 2;
}
TokenType token_type = 1;
string device_token = 2;
string installation_id = 3;
string access_token = 4;
bool enabled = 5;
uint64 version = 6;
repeated bytes allowed_key_list = 7;
repeated bytes blocked_chat_list = 8;
bool unregister = 9;
bytes grant = 10;
bool allow_from_contacts_only = 11;
string apn_topic = 12;
bool block_mentions = 13;
repeated bytes allowed_mentions_chat_list = 14;
}

message PushNotificationRegistrationResponse {
bool success = 1;
ErrorType error = 2;
bytes request_id = 3;

enum ErrorType {
UNKNOWN_ERROR_TYPE = 0;
MALFORMED_MESSAGE = 1;
VERSION_MISMATCH = 2;
UNSUPPORTED_TOKEN_TYPE = 3;
INTERNAL_ERROR = 4;
}
}

message ContactCodeAdvertisement {
repeated PushNotificationQueryInfo push_notification_info = 1;
ChatIdentity chat_identity = 2;
}

message PushNotificationQuery {
repeated bytes public_keys = 1;
}

message PushNotificationQueryInfo {
string access_token = 1;
string installation_id = 2;
bytes public_key = 3;
repeated bytes allowed_key_list = 4;
bytes grant = 5;
uint64 version = 6;
bytes server_public_key = 7;
}

message PushNotificationQueryResponse {
repeated PushNotificationQueryInfo info = 1;
bytes message_id = 2;
bool success = 3;
}

message PushNotification {
string access_token = 1;
bytes chat_id = 2;
bytes public_key = 3;
string installation_id = 4;
bytes message = 5;
PushNotificationType type = 6;
enum PushNotificationType {
UNKNOWN_PUSH_NOTIFICATION_TYPE = 0;
MESSAGE = 1;
MENTION = 2;
REQUEST_TO_JOIN_COMMUNITY = 3;
}
bytes author = 7;
}

message PushNotificationRequest {
repeated PushNotification requests = 1;
bytes message_id = 2;
}

message PushNotificationReport {
bool success = 1;
ErrorType error = 2;
enum ErrorType {
UNKNOWN_ERROR_TYPE = 0;
WRONG_TOKEN = 1;
INTERNAL_ERROR = 2;
NOT_REGISTERED = 3;
}
bytes public_key = 3;
string installation_id = 4;
}

message PushNotificationResponse {
bytes message_id = 1;
repeated PushNotificationReport reports = 2;
}
2 changes: 2 additions & 0 deletions packages/status-js/proto/status/v1/protocol_message.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
syntax = "proto3";

package status.v1;

message SignedPreKey {
bytes signed_pre_key = 1;
uint32 version = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { mapCommunityPreview } from './map-community-preview'

import type {
CommunityChat,
CommunityDescription,
} from '../proto/communities/v1/communities'
import type { CommunityPreview } from './map-community-preview'

export type CommunityChatPreview = {
emoji?: string
displayName: string
description: string
appUrl: string
color: string
community: CommunityPreview
}

export function mapCommunityChatPreview(
communityChat: CommunityChat,
communityDescription: CommunityDescription,
communityPublicKey: string,
communityChatUuid: string
): CommunityChatPreview | undefined {
const community = mapCommunityPreview(
communityDescription,
communityPublicKey
)

if (!community) {
return
}

const { identity } = communityChat

if (!identity) {
return
}

const communityChatPreview: CommunityChatPreview = {
emoji: identity.emoji,
displayName: identity.displayName,
description: identity.description,
color: identity.color,
appUrl: `status-im://cc/${communityPublicKey}/${communityChatUuid}`,
community,
}

return communityChatPreview
}
Loading

0 comments on commit 058d989

Please sign in to comment.