Skip to content

Commit

Permalink
v4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitninawe-cometchat committed Jun 4, 2024
1 parent d9dffcb commit ad3a166
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[![Platform](https://img.shields.io/badge/Platform-ReactNative-brightgreen.svg)](#)
[![Platform](https://img.shields.io/badge/Language-TypeScript-yellowgreen.svg)](#)
![Version](https://shields.io/badge/version-v4.1.0-orange)
![Version](https://shields.io/badge/version-v4.1.1-orange)
![Twitter Follow](https://img.shields.io/twitter/follow/cometchat?style=social)

## Table of contents
Expand Down
2 changes: 1 addition & 1 deletion ios/FileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (void) openMedia:(NSString *) path {
RCT_EXPORT_METHOD(openFile:(NSString *) url name:(NSString *) fileName myCallback:(RCTResponseSenderBlock)callback) {
//new way
@try {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filepath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath: filepath isDirectory:false]) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cometchat/chat-uikit-react-native",
"version": "4.1.0",
"version": "4.1.1",
"description": "CometChat React Native UI Kit is a collection of custom UI Components designed to build text , chat and calling features in your application. The UI Kit is developed to keep developers in mind and aims to reduce development efforts significantly",
"main": "src/index",
"module": "src/index",
Expand Down
4 changes: 2 additions & 2 deletions src/AI/AIAssistBot/AIAssistBotDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class AIAssistBotDecorator extends DataSourceDecorator {
override getAIOptions(user: CometChat.User | null, group: CometChat.Group | null, theme: CometChatTheme, id?: any, AIOptionsStyle?: AIOptionsStyle): CometChatMessageComposerActionInterface[] {
this.user = user!;
this.group = group!;
if (!id?.parentMessageId) {
const numberOfBots = this.bots?.length;
const numberOfBots = this.bots?.length;
if (!id?.parentMessageId && numberOfBots > 0) {
const titleName = numberOfBots > 1 ? localize("COMETCHAT_ASK_AI_BOT") : `${localize("COMETCHAT_ASK_BOT")} ${this.bots[0]?.getName()}`;
const messageComposerActions: CometChatMessageComposerActionInterface[] = super.getAIOptions(user, group, theme, id, AIOptionsStyle);
let newAction = {
Expand Down
2 changes: 1 addition & 1 deletion src/CometChatMessageComposer/CometChatMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ export const CometChatMessageComposer = React.forwardRef(

return (
<>
{!isVisible && CustomView && <CustomView />}
{!isVisible && typeof CustomView === "function" && <CustomView />}
<Modal
animationType="slide"
visible={isVisible}
Expand Down
56 changes: 32 additions & 24 deletions src/CometChatMessageList/CometChatMessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const CometChatMessageList = forwardRef<
const callListenerId = "call_" + new Date().getTime();
const groupListenerId = "group_" + new Date().getTime();
const uiEventListener = "uiEvent_" + new Date().getTime();
const callEventListener = 'callEvent_' + new Date().getTime();
const uiEventListenerShow = "uiEvent_show_" + new Date().getTime();
const uiEventListenerHide = "uiEvent_hide_" + new Date().getTime();
const connectionListenerId = 'connectionListener_' + new Date().getTime();
Expand Down Expand Up @@ -242,6 +243,7 @@ export const CometChatMessageList = forwardRef<
const [ExtensionsComponent, setExtensionsComponent] = useState(null);
const [CustomListHeader, setCustomListHeader] = useState(null);
const [messageInfo, setMessageInfo] = useState(false);
const [ongoingCallView, setOngoingCallView] = useState(null);
// const [forwarding, setForwarding] = useState(false);

const infoObject = useRef<CometChat.BaseMessage>();
Expand Down Expand Up @@ -274,14 +276,12 @@ export const CometChatMessageList = forwardRef<
}

const markUnreadMessageAsRead = () => {
if (messagesList[messagesList.length - 1].getReceiverType() == ReceiverTypeConstants.user) {
for (let index = 0; index < unreadCount; index++) {
const message = messagesList[messagesList.length - (index + 1)];
if (index == 0)
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, { message });
CometChat.markAsRead(message);
setUnreadCount(0);
}
for (let index = 0; index < unreadCount; index++) {
const message = messagesList[messagesList.length - (index + 1)];
if (index == 0)
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, { message });
CometChat.markAsRead(message);
setUnreadCount(0);
}
}

Expand Down Expand Up @@ -637,6 +637,12 @@ export const CometChatMessageList = forwardRef<
bottomSheetRef.current?.togglePanel()
},
});
CometChatUIEventHandler.addCallListener(callEventListener, {
ccShowOngoingCall: (CometChatOngoingComponent) => {
//show ongoing call
setOngoingCallView(CometChatOngoingComponent?.child);
},
});
CometChat.getLoggedinUser()
.then(u => {
loggedInUser.current = u;
Expand All @@ -654,6 +660,7 @@ export const CometChatMessageList = forwardRef<
CometChatUIEventHandler.removeUIListener(uiEventListenerShow)
CometChatUIEventHandler.removeUIListener(uiEventListenerHide)
CometChatUIEventHandler.removeUIListener(uiEventListener);
CometChatUIEventHandler.removeCallListener(callEventListener);
onBack && onBack();
}
}, [])
Expand Down Expand Up @@ -846,15 +853,15 @@ export const CometChatMessageList = forwardRef<
},
onDisconnected: () => {
console.log("ConnectionListener => On Disconnected");
if (!messagesList[0].id) {
for (let i = 0; i < messagesList.length; i++) {
if (!messagesList[messagesList.length - 1].id) {
for (let i = (messagesList.length - 1); i >= 0; i--) {
if (messagesList[i].id) {
lastID.current = messagesList[i].id;
break;
}
}
} else {
lastID.current = messagesList[0].id;
lastID.current = messagesList[messagesList.length - 1].id;
}
}
})
Expand Down Expand Up @@ -1278,18 +1285,18 @@ export const CometChatMessageList = forwardRef<
return <EmptyStateView />
return (
<>
<View style={Style.msgContainerStyle}>
<Text
style={[
Style.msgTxtStyle, {
...(messageListStyle?.emptyStateTextFont),
color: messageListStyle?.emptyStateTextColor
}]}
>
{emptyStateText}
</Text>
</View >
{CustomListHeader && <CustomListHeader />}
<View style={Style.msgContainerStyle}>
<Text
style={[
Style.msgTxtStyle, {
...(messageListStyle?.emptyStateTextFont),
color: messageListStyle?.emptyStateTextColor
}]}
>
{emptyStateText}
</Text>
</View >
{CustomListHeader && <CustomListHeader />}
</>
)
}, [])
Expand Down Expand Up @@ -1360,7 +1367,7 @@ export const CometChatMessageList = forwardRef<
return (
<View style={{
height, width, backgroundColor, borderRadius, ...border,
paddingStart: 8, paddingEnd: 8,
paddingStart: 8, paddingEnd: 8,
}}>
{
listState == "loading" && messagesList.length == 0 ?
Expand Down Expand Up @@ -1419,6 +1426,7 @@ export const CometChatMessageList = forwardRef<
</ScrollView>
</SafeAreaView>
{CustomListHeader && <CustomListHeader />}
{ongoingCallView}
{
FooterView && <View style={[Style.stickyHeaderFooterStyle, { bottom: 0 }]}>
<FooterView
Expand Down
1 change: 1 addition & 0 deletions src/calls/CallEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export const CallUIEvents = {
ccCallEnded: "ccCallEnded",
ccCallJoined: "ccCallJoined",
ccOutgoingCall: "ccOutgoingCall",
ccShowOngoingCall: "ccShowOngoingCall",
}
101 changes: 56 additions & 45 deletions src/calls/CallingExtentionDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from "react";
import { Modal, Text, View, Image } from "react-native";
import React from "react";
import { Modal, Text, View, Image, Platform } from "react-native";
import { CometChat } from "@cometchat/chat-sdk-react-native";
import { CometChatMessageTemplate } from "../shared/modals";
import { localize } from "../shared/resources/CometChatLocalize";
Expand All @@ -14,6 +14,8 @@ import { CometChatCallButtons } from "./CometChatCallButtons";
import { CometChatOngoingCall } from "./CometChatOngoingCall";
import { CallingPackage } from "./CallingPackage";
import { CallUtils } from "./CallUtils";
import { CometChatUIEventHandler } from "../shared";
import { CallUIEvents } from "./CallEvents";

const CometChatCalls = CallingPackage.CometChatCalls;

Expand All @@ -25,12 +27,12 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
constructor(props: { dataSource: DataSource, configuration: CallingConfiguration }) {
super(props.dataSource);
CometChat.getLoggedinUser()
.then(user => {
this.loggedInUser = user;
})
.catch(err => {
console.log("unable to get logged in user.");
})
.then(user => {
this.loggedInUser = user;
})
.catch(err => {
console.log("unable to get logged in user.");
})
if (props.configuration) {
this.configuration = props.configuration;
}
Expand Down Expand Up @@ -63,13 +65,13 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
if (this.isDeletedMessage(message))
return null;
return <View style={{ justifyContent: "space-around", alignItems: "center" }}>
<View style={{flexDirection: "row", alignSelf: "center", borderWidth: 1, borderStyle: "dotted", borderRadius: 8, padding: 4}}>
<Image source={message['type'] == "audio" ? AudioIcon : VideoIcon} style={{height: 16, width: 16, alignSelf: "center"}} />
<Text style={{ color: theme.palette.getAccent(), marginStart: 8 }}>
{
CallUtils.getCallStatus(message, this.loggedInUser)
}
</Text>
<View style={{ flexDirection: "row", alignSelf: "center", borderWidth: 1, borderStyle: "dotted", borderRadius: 8, padding: 4 }}>
<Image source={message['type'] == "audio" ? AudioIcon : VideoIcon} style={{ height: 16, width: 16, alignSelf: "center" }} />
<Text style={{ color: theme.palette.getAccent(), marginStart: 8 }}>
{
CallUtils.getCallStatus(message, this.loggedInUser)
}
</Text>
</View>
</View>
}
Expand All @@ -86,7 +88,7 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
}
});
}

getUserVideoCallTemplates = (theme) => {
return new CometChatMessageTemplate({
category: MessageCategoryConstants.call,
Expand All @@ -103,28 +105,16 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
GroupCallBubbleView = (props: { message: CometChat.BaseMessage, theme: CometChatTheme, alignment: string }) => {
const { message, theme, alignment } = props;

const [joinCall, setJoinCall] = useState(false);
const callListener = useRef(undefined);

if (this.isDeletedMessage(message))
return null
useEffect(() => {
callListener.current = new CometChatCalls.OngoingCallListener({
onCallEnded: () => {
setJoinCall(false);
},
onCallEndButtonPressed: () => {
setJoinCall(false);
},
})
}, []);

return (
<View>
<CometChatCallBubble
buttonText={localize("JOIN")}
title={alignment == "right" ? localize("YOU_INITIATED_GROUP_CALL") : `${message['sender']['name']} ${localize("INITIATED_GROUP_CALL")}`}
icon={VideoIcon}
onClick={() => setJoinCall(true)}
onClick={() => this.startDirectCall(message['customData']['sessionId'], theme)}
style={{
backgroundColor: alignment == "left" ? "transparent" : theme.palette.getPrimary(),
titleColor: alignment == "left" ? theme.palette.getAccent() : theme.palette.getSecondary(),
Expand All @@ -133,25 +123,46 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
buttonTextColor: alignment == "left" ? theme.palette.getPrimary() : theme.palette.getPrimary(),
}}
/>
{
joinCall &&
<Modal>
<CometChatOngoingCall
sessionID={message['customData']['sessionId']}
callSettingsBuilder={
new CometChatCalls.CallSettingsBuilder()
.setCallEventListener(callListener.current)
}
onError={(e) => {
setJoinCall(false);
}}
/>
</Modal>
}
</View>
)
}

startDirectCall(sessionId: string, theme?: CometChatTheme) {

const callSettingsBuilder = new CometChatCalls.CallSettingsBuilder()
.setCallEventListener(
new CometChatCalls.OngoingCallListener({
onCallEndButtonPressed: () => {
CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccShowOngoingCall, {
child: null,
})
},
onError: (error) => {
CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccShowOngoingCall, {
child: null,
})
}
})
);

const ongoingCallScreen = (
<Modal>
<CometChatOngoingCall
sessionID={sessionId}
callSettingsBuilder={callSettingsBuilder}
onError={(e) => {
CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccShowOngoingCall, {
child: null,
});
}}
/>
</Modal>
);
CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccShowOngoingCall, {
child: ongoingCallScreen,
});
}

getAuxiliaryHeaderAppbarOptions(user, group, theme: CometChatTheme) {
return <View>
<CometChatCallButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class CometChatUIEventHandler {
case listener._eventListener.ccCallInitiated?.name:
listener._eventListener.ccCallInitiated(param);
break;
case listener._eventListener.ccShowOngoingCall?.name:
listener._eventListener.ccShowOngoingCall(param);
break;
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/shared/events/CometChatUIEventHandler/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type CallUIEvents = {
ccCallEnded?: Function,
ccCallInitiated?: Function,
ccCallFailled?: Function,
ccShowOngoingCall?: (CometChatOngoingComponent) => void,
}

type PanelUIEvents = {
Expand Down Expand Up @@ -153,6 +154,7 @@ export class CallUIEventListener {
ccOutgoingCallCancelled?: Function = undefined;
ccCallFailled?: Function = undefined;
ccCallInitiated?: Function = undefined;
ccShowOngoingCall?: (CometChatOngoingComponent) => void;

constructor({
ccIncomingCallReceived,
Expand All @@ -165,7 +167,8 @@ export class CallUIEventListener {
ccCallEnded,
ccOutgoingCallCancelled,
ccCallFailled,
ccCallInitiated
ccCallInitiated,
ccShowOngoingCall,
}: CallUIEvents) {
if (!isFalsy(ccCallFailled)) this.ccCallFailled = ccCallFailled;
if (!isFalsy(ccCallInitiated)) this.ccCallInitiated = ccCallInitiated;
Expand All @@ -178,6 +181,7 @@ export class CallUIEventListener {
if (!isFalsy(ccOutgoingCallAccepted)) this.ccOutgoingCallAccepted = ccOutgoingCallAccepted;
if (!isFalsy(ccOutgoingCallRejected)) this.ccOutgoingCallRejected = ccOutgoingCallRejected;
if (!isFalsy(ccIncomingCallCancelled)) this.ccIncomingCallCancelled = ccIncomingCallCancelled;
if (!isFalsy(ccShowOngoingCall)) this.ccShowOngoingCall = ccShowOngoingCall;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/conversationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CometChatConversationUtils {
}

static getLastMessage(conversation: CometChat.Conversation): CometChat.BaseMessage {
let msg = conversation.getLastMessage();
let msg = conversation?.getLastMessage && conversation?.getLastMessage();
if (!msg) {
return undefined;
}
Expand Down
Loading

0 comments on commit ad3a166

Please sign in to comment.