making simpler with content instead of audioclips
This commit is contained in:
@@ -11,32 +11,28 @@ export interface IContent {
|
|||||||
|
|
||||||
// ? persist length of clip for easier viewing for others...
|
// ? persist length of clip for easier viewing for others...
|
||||||
// ?they have to load it anyway and will get metadata anyway?
|
// ?they have to load it anyway and will get metadata anyway?
|
||||||
export class AudioClip implements IContent {
|
export class ContentBlock implements IContent {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public creatorUserId: string,
|
public creatorUserId: string,
|
||||||
public contentUrl: string,
|
public contentUrl: string,
|
||||||
|
|
||||||
|
public contentType: ContentType,
|
||||||
|
public blobType: string,
|
||||||
|
|
||||||
public createdDate: Timestamp = Timestamp.now(),
|
public createdDate: Timestamp = Timestamp.now(),
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Link implements IContent {
|
export enum ContentType {
|
||||||
id: string;
|
audio = 'audio',
|
||||||
constructor(
|
|
||||||
public creatorUserId: string,
|
link = 'link',
|
||||||
public contentUrl: string,
|
|
||||||
public createdDate: Timestamp = Timestamp.now(),
|
image = 'image',
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Image implements IContent {
|
export function isUrlImage(url: string) {
|
||||||
id: string;
|
return url.match(/\.(jpeg|jpg|gif|png)$/) != null;
|
||||||
|
|
||||||
constructor(
|
|
||||||
public creatorUserId: string,
|
|
||||||
public contentUrl: string,
|
|
||||||
public thumbnailUrl?: string,
|
|
||||||
public createdDate: Timestamp = Timestamp.now(),
|
|
||||||
) {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,8 @@ import {
|
|||||||
joinConversation,
|
joinConversation,
|
||||||
leaveConversation,
|
leaveConversation,
|
||||||
searchUsers,
|
searchUsers,
|
||||||
sendAudioClipToConversation,
|
sendContentBlockToConversation,
|
||||||
} from '../firebase/firestore';
|
} from '../firebase/firestore';
|
||||||
import { Link, AudioClip, Image } from '@nirvana/core/src/models/content.model';
|
|
||||||
import { useImmer } from 'use-immer';
|
import { useImmer } from 'use-immer';
|
||||||
import { User } from '@nirvana/core/src/models/user.model';
|
import { User } from '@nirvana/core/src/models/user.model';
|
||||||
import { onSnapshot } from 'firebase/firestore';
|
import { onSnapshot } from 'firebase/firestore';
|
||||||
@@ -71,6 +70,7 @@ import { useDebounce, useEffectOnce, useKeyPressEvent } from 'react-use';
|
|||||||
import KeyboardShortcutLabel from './KeyboardShortcutLabel';
|
import KeyboardShortcutLabel from './KeyboardShortcutLabel';
|
||||||
import Channels from '../electron/constants';
|
import Channels from '../electron/constants';
|
||||||
import { uploadAudioClip } from '../firebase/firebaseStorage';
|
import { uploadAudioClip } from '../firebase/firebaseStorage';
|
||||||
|
import { ContentBlock, ContentType } from '@nirvana/core/src/models/content.model';
|
||||||
type ConversationMap = {
|
type ConversationMap = {
|
||||||
[conversationId: string]: Conversation;
|
[conversationId: string]: Conversation;
|
||||||
};
|
};
|
||||||
@@ -80,7 +80,7 @@ type UserMap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type ConversationContentMap = {
|
type ConversationContentMap = {
|
||||||
[conversationId: string]: { audio: AudioClip[]; links: Link[]; images: Image[] };
|
[conversationId: string]: ContentBlock[];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ITerminalContext {
|
interface ITerminalContext {
|
||||||
@@ -175,7 +175,7 @@ export function TerminalProvider({ children }: { children?: React.ReactNode }) {
|
|||||||
return () => unsub();
|
return () => unsub();
|
||||||
}, [user, updateConversationMap, enqueueSnackbar]);
|
}, [user, updateConversationMap, enqueueSnackbar]);
|
||||||
|
|
||||||
// cached listeners for audioClips
|
// cached listeners for a
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
|
|
||||||
// }, [])
|
// }, [])
|
||||||
@@ -296,8 +296,13 @@ export function TerminalProvider({ children }: { children?: React.ReactNode }) {
|
|||||||
audioChunks[0],
|
audioChunks[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
const audioClip = new AudioClip(user.uid, downloadUrl);
|
const contentBlock = new ContentBlock(
|
||||||
await sendAudioClipToConversation(audioClip, selectedConversation.id);
|
user.uid,
|
||||||
|
downloadUrl,
|
||||||
|
ContentType.audio,
|
||||||
|
audioChunks[0].type,
|
||||||
|
);
|
||||||
|
await sendContentBlockToConversation(contentBlock, selectedConversation.id);
|
||||||
|
|
||||||
enqueueSnackbar('clip sent!', { variant: 'success' });
|
enqueueSnackbar('clip sent!', { variant: 'success' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import Conversation, {
|
|||||||
MemberState,
|
MemberState,
|
||||||
} from '@nirvana/core/src/models/conversation.model';
|
} from '@nirvana/core/src/models/conversation.model';
|
||||||
import useAuth from '../providers/AuthProvider';
|
import useAuth from '../providers/AuthProvider';
|
||||||
import { AudioClip } from '@nirvana/core/src/models/content.model';
|
import { ContentBlock } from '@nirvana/core/src/models/content.model';
|
||||||
|
|
||||||
interface Document {
|
interface Document {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -66,8 +66,8 @@ const db = {
|
|||||||
conversation: (conversationId: string) =>
|
conversation: (conversationId: string) =>
|
||||||
docPoint<Conversation>(`conversations/${conversationId}`),
|
docPoint<Conversation>(`conversations/${conversationId}`),
|
||||||
|
|
||||||
conversationAudioClips: (conversationId: string) =>
|
conversationContent: (conversationId: string) =>
|
||||||
collectionPoint<AudioClip>(`conversations/${conversationId}/audioClips`),
|
collectionPoint<ContentBlock>(`conversations/${conversationId}/content`),
|
||||||
};
|
};
|
||||||
|
|
||||||
// enum COLLECTION {
|
// enum COLLECTION {
|
||||||
@@ -203,9 +203,12 @@ export const createGroupConversation = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendAudioClipToConversation = async (audioClip: AudioClip, conversationId: string) => {
|
export const sendContentBlockToConversation = async (
|
||||||
|
contentBlock: ContentBlock,
|
||||||
|
conversationId: string,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
await addDoc(db.conversationAudioClips(conversationId), audioClip);
|
await addDoc(db.conversationContent(conversationId), contentBlock);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error ', e);
|
console.error('Error ', e);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user