UNPKG

@towns-protocol/sdk

Version:

For more details, visit the following resources:

208 lines 9.28 kB
import { ChannelMessage_Post_AttachmentSchema, ChannelMessage_PostSchema, } from '@towns-protocol/proto'; import { isDefined, logNever } from '../../check'; import { create } from '@bufbuild/protobuf'; export var EventStatus; (function (EventStatus) { /** The event was not sent and will no longer be retried. */ EventStatus["NOT_SENT"] = "not_sent"; /** The message is being encrypted */ EventStatus["ENCRYPTING"] = "encrypting"; /** The event is in the process of being sent. */ EventStatus["SENDING"] = "sending"; /** The event is in a queue waiting to be sent. */ EventStatus["QUEUED"] = "queued"; /** The event has been sent to the server, but we have not yet received the echo. */ EventStatus["SENT"] = "sent"; /** The event was cancelled before it was successfully sent. */ EventStatus["CANCELLED"] = "cancelled"; /** We received this event */ EventStatus["RECEIVED"] = "received"; })(EventStatus || (EventStatus = {})); export var RiverTimelineEvent; (function (RiverTimelineEvent) { RiverTimelineEvent["ChannelCreate"] = "m.channel.create"; RiverTimelineEvent["ChannelMessage"] = "m.channel.message"; RiverTimelineEvent["ChannelMessageEncrypted"] = "m.channel.encrypted"; RiverTimelineEvent["ChannelMessageEncryptedWithRef"] = "m.channel.encrypted_with_ref"; RiverTimelineEvent["ChannelMessageMissing"] = "m.channel.missing"; RiverTimelineEvent["ChannelProperties"] = "m.channel.properties"; RiverTimelineEvent["EncryptedChannelProperties"] = "m.channel.encrypted_properties"; RiverTimelineEvent["Fulfillment"] = "m.fulfillment"; RiverTimelineEvent["Inception"] = "m.inception"; RiverTimelineEvent["KeySolicitation"] = "m.key_solicitation"; RiverTimelineEvent["MemberBlockchainTransaction"] = "m.member_blockchain_transaction"; RiverTimelineEvent["MiniblockHeader"] = "m.miniblockheader"; RiverTimelineEvent["Pin"] = "m.pin"; RiverTimelineEvent["Reaction"] = "m.reaction"; RiverTimelineEvent["RedactedEvent"] = "m.redacted_event"; RiverTimelineEvent["RedactionActionEvent"] = "m.redaction_action"; RiverTimelineEvent["SpaceUpdateAutojoin"] = "m.space.update_autojoin"; RiverTimelineEvent["SpaceUpdateHideUserJoinLeaves"] = "m.space.update_channel_hide_user_join_leaves"; RiverTimelineEvent["SpaceImage"] = "m.space.image"; RiverTimelineEvent["SpaceUsername"] = "m.space.username"; RiverTimelineEvent["SpaceDisplayName"] = "m.space.display_name"; RiverTimelineEvent["SpaceEnsAddress"] = "m.space.ens_name"; RiverTimelineEvent["SpaceNft"] = "m.space.nft"; RiverTimelineEvent["SpaceReview"] = "m.space.review"; RiverTimelineEvent["StreamEncryptionAlgorithm"] = "m.stream_encryption_algorithm"; RiverTimelineEvent["StreamMembership"] = "m.stream_membership"; RiverTimelineEvent["TipEvent"] = "m.tip_event"; RiverTimelineEvent["TokenTransfer"] = "m.token_transfer"; RiverTimelineEvent["Unpin"] = "m.unpin"; RiverTimelineEvent["UserBlockchainTransaction"] = "m.user_blockchain_transaction"; RiverTimelineEvent["UserReceivedBlockchainTransaction"] = "m.user_received_blockchain_transaction"; })(RiverTimelineEvent || (RiverTimelineEvent = {})); // the same as MembershipOp but with a different name export var Membership; (function (Membership) { Membership["Join"] = "join"; Membership["Invite"] = "invite"; Membership["Leave"] = "leave"; Membership["None"] = ""; })(Membership || (Membership = {})); export var MessageType; (function (MessageType) { MessageType["Text"] = "m.text"; MessageType["GM"] = "m.gm"; MessageType["Image"] = "m.image"; })(MessageType || (MessageType = {})); export function isMessageTipEvent(event) { return (event.content?.kind === RiverTimelineEvent.TipEvent && event.content.transaction?.content.case === 'tip'); } export function transformAttachments(attachments) { if (!attachments) { return []; } return attachments .map((attachment) => { switch (attachment.type) { case 'chunked_media': return create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'chunkedMedia', value: { info: attachment.info, streamId: attachment.streamId, encryption: { case: 'aesgcm', value: attachment.encryption, }, thumbnail: { info: attachment.thumbnail?.info, content: attachment.thumbnail?.content, }, }, }, }); case 'embedded_media': return create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'embeddedMedia', value: { info: attachment.info, content: attachment.content, }, }, }); case 'image': return create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'image', value: { info: attachment.info, }, }, }); case 'embedded_message': { const { channelMessageEvent, ...content } = attachment; if (!channelMessageEvent) { return; } const post = create(ChannelMessage_PostSchema, { threadId: channelMessageEvent.threadId, threadPreview: channelMessageEvent.threadPreview, content: { case: 'text', value: { ...channelMessageEvent, attachments: transformAttachments(channelMessageEvent.attachments), }, }, }); const value = create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'embeddedMessage', value: { ...content, post, }, }, }); return value; } case 'unfurled_link': return create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'unfurledUrl', value: { url: attachment.url, title: attachment.title, description: attachment.description, image: attachment.image ? { height: attachment.image.height, width: attachment.image.width, url: attachment.image.url, } : undefined, }, }, }); case 'ticker': return create(ChannelMessage_Post_AttachmentSchema, { content: { case: 'ticker', value: { chainId: attachment.chainId, address: attachment.address, }, }, }); default: logNever(attachment); return undefined; } }) .filter(isDefined); } export function getEditsId(content) { return content?.kind === RiverTimelineEvent.ChannelMessage ? content.editsEventId : undefined; } export function getRedactsId(content) { return content?.kind === RiverTimelineEvent.RedactionActionEvent ? content.refEventId : undefined; } export function getThreadParentId(content) { return content?.kind === RiverTimelineEvent.ChannelMessage ? content.threadId : content?.kind === RiverTimelineEvent.TokenTransfer ? content.threadParentId : undefined; } export function getReplyParentId(content) { return content?.kind === RiverTimelineEvent.ChannelMessage ? content.replyId : undefined; } export function getReactionParentId(content) { return content?.kind === RiverTimelineEvent.Reaction ? content.targetEventId : undefined; } export function getIsMentioned(content, userId) { //TODO: comparison below should be changed as soon as this HNT-1576 will be resolved return content?.kind === RiverTimelineEvent.ChannelMessage ? content.mentions.findIndex((x) => (x.userId ?? '') .toLowerCase() .localeCompare(userId.toLowerCase(), undefined, { sensitivity: 'base' }) == 0) >= 0 : false; } //# sourceMappingURL=timelineTypes.js.map