tmp fix test

This commit is contained in:
Felicio Mununga 2022-05-31 13:14:48 +02:00
parent c1d611827f
commit 0cc21dd908
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 23 additions and 23 deletions

View File

@ -1,7 +1,7 @@
import { Reader } from 'protobufjs' import { Reader } from 'protobufjs'
import * as proto from '../proto/communities/v1/chat_message' import * as proto from '../proto/communities/v1/chat_message'
import { ChatMessage_ContentType } from '../proto/communities/v1/chat_message' // import { proto.ChatMessage_ContentType } from '../proto/communities/v1/chat_message'
import { MessageType } from '../proto/communities/v1/enums' import { MessageType } from '../proto/communities/v1/enums'
import type { import type {
@ -62,7 +62,7 @@ function isAudio(content: Content): content is AudioContent {
} }
export class ChatMessage { export class ChatMessage {
private constructor(public proto: proto.ChatMessage) {} private constructor(public _proto: proto.ChatMessage) {}
/** /**
* Create a chat message to be sent to an Open (permission = no membership) community. * Create a chat message to be sent to an Open (permission = no membership) community.
@ -80,26 +80,26 @@ export class ChatMessage {
image, image,
audio, audio,
text = 'Upgrade to the latest version to see this media content.' text = 'Upgrade to the latest version to see this media content.'
let contentType = ChatMessage_ContentType.CONTENT_TYPE_TEXT_PLAIN let contentType = proto.ChatMessage_ContentType.CONTENT_TYPE_TEXT_PLAIN
if (isText(content)) { if (isText(content)) {
if (!content.text) throw 'Malformed Text Content' if (!content.text) throw 'Malformed Text Content'
text = content.text text = content.text
contentType = ChatMessage_ContentType.CONTENT_TYPE_TEXT_PLAIN contentType = proto.ChatMessage_ContentType.CONTENT_TYPE_TEXT_PLAIN
} else if (isSticker(content)) { } else if (isSticker(content)) {
if (!content.hash || !content.pack) throw 'Malformed Sticker Content' if (!content.hash || !content.pack) throw 'Malformed Sticker Content'
sticker = { sticker = {
hash: content.hash, hash: content.hash,
pack: content.pack, pack: content.pack,
} }
contentType = ChatMessage_ContentType.CONTENT_TYPE_STICKER contentType = proto.ChatMessage_ContentType.CONTENT_TYPE_STICKER
} else if (isImage(content)) { } else if (isImage(content)) {
if (!content.image || !content.imageType) throw 'Malformed Image Content' if (!content.image || !content.imageType) throw 'Malformed Image Content'
image = { image = {
payload: content.image, payload: content.image,
type: content.imageType, type: content.imageType,
} }
contentType = ChatMessage_ContentType.CONTENT_TYPE_IMAGE contentType = proto.ChatMessage_ContentType.CONTENT_TYPE_IMAGE
} else if (isAudio(content)) { } else if (isAudio(content)) {
if (!content.audio || !content.audioType || !content.durationMs) if (!content.audio || !content.audioType || !content.durationMs)
throw 'Malformed Audio Content' throw 'Malformed Audio Content'
@ -108,10 +108,10 @@ export class ChatMessage {
type: content.audioType, type: content.audioType,
durationMs: content.durationMs, durationMs: content.durationMs,
} }
contentType = ChatMessage_ContentType.CONTENT_TYPE_AUDIO contentType = proto.ChatMessage_ContentType.CONTENT_TYPE_AUDIO
} }
const proto = { const __proto = {
clock, // ms? clock, // ms?
timestamp, //ms? timestamp, //ms?
text, text,
@ -132,7 +132,7 @@ export class ChatMessage {
grant: undefined, grant: undefined,
} }
return new ChatMessage(proto) return new ChatMessage(__proto)
} }
static decode(bytes: Uint8Array): ChatMessage { static decode(bytes: Uint8Array): ChatMessage {
@ -142,12 +142,12 @@ export class ChatMessage {
} }
encode(): Uint8Array { encode(): Uint8Array {
return proto.ChatMessage.encode(this.proto).finish() return proto.ChatMessage.encode(this._proto).finish()
} }
/** Lamport timestamp of the chat message */ /** Lamport timestamp of the chat message */
public get clock(): number | undefined { public get clock(): number | undefined {
return this.proto.clock return this._proto.clock
} }
/** /**
@ -155,28 +155,28 @@ export class ChatMessage {
* so that we don't rely on it * so that we don't rely on it
*/ */
public get timestamp(): number | undefined { public get timestamp(): number | undefined {
return this.proto.timestamp return this._proto.timestamp
} }
/** /**
* Text of the message * Text of the message
*/ */
public get text(): string | undefined { public get text(): string | undefined {
return this.proto.text return this._proto.text
} }
/** /**
* Id of the message that we are replying to * Id of the message that we are replying to
*/ */
public get responseTo(): string | undefined { public get responseTo(): string | undefined {
return this.proto.responseTo return this._proto.responseTo
} }
/** /**
* Ens name of the sender * Ens name of the sender
*/ */
public get ensName(): string | undefined { public get ensName(): string | undefined {
return this.proto.ensName return this._proto.ensName
} }
/** /**
@ -186,39 +186,39 @@ export class ChatMessage {
* Probably should be the concatenation of sender-pk & receiver-pk in alphabetical order * Probably should be the concatenation of sender-pk & receiver-pk in alphabetical order
*/ */
public get chatId(): string { public get chatId(): string {
return this.proto.chatId return this._proto.chatId
} }
/** /**
* The type of message (public/one-to-one/private-group-chat) * The type of message (public/one-to-one/private-group-chat)
*/ */
public get messageType(): MessageType | undefined { public get messageType(): MessageType | undefined {
return this.proto.messageType return this._proto.messageType
} }
/** /**
* The type of the content of the message * The type of the content of the message
*/ */
public get contentType(): ChatMessage_ContentType | undefined { public get contentType(): proto.ChatMessage_ContentType | undefined {
return this.proto.contentType return this._proto.contentType
} }
public get sticker(): StickerMessage | undefined { public get sticker(): StickerMessage | undefined {
return this.proto.sticker return this._proto.sticker
} }
public get image(): ImageMessage | undefined { public get image(): ImageMessage | undefined {
return this.proto.image return this._proto.image
} }
public get audio(): AudioMessage | undefined { public get audio(): AudioMessage | undefined {
return this.proto.audio return this._proto.audio
} }
/** /**
* Used when sharing a community via a chat message. * Used when sharing a community via a chat message.
*/ */
public get community(): Uint8Array | undefined { public get community(): Uint8Array | undefined {
return this.proto.community return this._proto.community
} }
} }