sending message nicely
This commit is contained in:
@@ -11,9 +11,9 @@ export default class Conversation {
|
||||
activeMembers: string[]; // userIds
|
||||
membersInLiveRoom: string[] = [] as string[]; // all members in a live call right now for this convo
|
||||
|
||||
cachedAudioClips: AudioClip[] = [] as AudioClip[];
|
||||
cachedDrawerItems: Link[] = [] as Link[];
|
||||
tldrClips: AudioClip[] = [] as AudioClip[];
|
||||
cachedAudioClip?: AudioClip; // last message pretty much
|
||||
cachedDrawerItem?: Link; // last link pretty much
|
||||
cachedTldrClip?: string;
|
||||
|
||||
createdDate: Timestamp = Timestamp.now();
|
||||
createdByUserId: string;
|
||||
@@ -68,7 +68,7 @@ export enum ConversationMemberState {
|
||||
export class AudioClip {
|
||||
id: string = uuid();
|
||||
|
||||
audioDataUrl: string;
|
||||
audioDataUrl?: string;
|
||||
|
||||
senderUserId: string;
|
||||
createdDate: Timestamp = Timestamp.now();
|
||||
|
||||
@@ -14,6 +14,7 @@ enum Collections {
|
||||
// v2
|
||||
conversations = "conversations",
|
||||
conversationMembers = "members",
|
||||
conversationAudioClips = "audioClips",
|
||||
}
|
||||
|
||||
export default Collections;
|
||||
|
||||
@@ -9,9 +9,13 @@ import {
|
||||
runTransaction,
|
||||
writeBatch,
|
||||
} from "firebase/firestore";
|
||||
import Conversation, { ConversationMember } from "../models/conversation";
|
||||
import Conversation, {
|
||||
AudioClip,
|
||||
ConversationMember,
|
||||
ConversationMemberState,
|
||||
} from "../models/conversation";
|
||||
import Collections from "./collections";
|
||||
import { ConversationMemberState } from "../models/conversation";
|
||||
import { cloudStorageService } from "./index";
|
||||
|
||||
export default class ConversationService {
|
||||
private db: Firestore = getFirestore();
|
||||
@@ -103,4 +107,47 @@ export default class ConversationService {
|
||||
|
||||
await setDoc(docRef, newUpdates, { merge: true });
|
||||
}
|
||||
|
||||
async sendAudioClip(
|
||||
createdByUserId: string,
|
||||
audioMp3File: File,
|
||||
convoId: string
|
||||
) {
|
||||
// upload to cloud storage
|
||||
const downloadUrl = await cloudStorageService.uploadMessageAudioFile(
|
||||
audioMp3File
|
||||
);
|
||||
const newAudioClip = new AudioClip(downloadUrl, createdByUserId);
|
||||
newAudioClip.audioDataUrl = downloadUrl;
|
||||
|
||||
const audioClipRef = doc(
|
||||
this.db,
|
||||
Collections.conversations,
|
||||
convoId,
|
||||
Collections.conversationAudioClips,
|
||||
newAudioClip.id
|
||||
);
|
||||
|
||||
const conversationDoc = doc(this.db, Collections.conversations, convoId);
|
||||
|
||||
await runTransaction(this.db, async (transaction) => {
|
||||
// want to add to the long term collection of all audio clips for a conversation
|
||||
transaction.set(
|
||||
audioClipRef,
|
||||
{ ...newAudioClip, createdDate: serverTimestamp() },
|
||||
{ merge: true }
|
||||
);
|
||||
|
||||
// want to make updates to the conversation document itself: set the last item for just the basic information to be
|
||||
// published to users
|
||||
transaction.set(
|
||||
conversationDoc,
|
||||
{
|
||||
lastActivityDate: serverTimestamp(),
|
||||
cachedAudioClip: { ...newAudioClip, createdDate: serverTimestamp() },
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import CloudStorageService from "./cloudStorageService";
|
||||
import ConversationService from "./conversationService";
|
||||
import UserService from "./userService";
|
||||
|
||||
export const conversationService = new ConversationService();
|
||||
|
||||
export const userService = new UserService();
|
||||
|
||||
export const cloudStorageService = new CloudStorageService();
|
||||
|
||||
Reference in New Issue
Block a user