aboutsummaryrefslogtreecommitdiff
path: root/src/utils/messages.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/messages.ts')
-rw-r--r--src/utils/messages.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils/messages.ts b/src/utils/messages.ts
index ae8e7cec..d63f2b7a 100644
--- a/src/utils/messages.ts
+++ b/src/utils/messages.ts
@@ -1,4 +1,6 @@
import moment from 'moment';
+import {RootState} from '../store/rootReducer';
+import {ChannelGroupedType} from '../types';
/**
* Finds the difference in time in minutes
@@ -57,3 +59,25 @@ export const isOnline = (lastActive: string | undefined) => {
}
return diff <= 15;
};
+
+/**
+ * Gets the other member in the channel.
+ * @param channel the current chat channel
+ * @param state the current redux state
+ * @returns other member or undefined
+ */
+export const getMember = (
+ channel: ChannelGroupedType | undefined,
+ state: RootState,
+) => {
+ if (!channel) {
+ return undefined;
+ }
+ const loggedInUserId = state.user.user.userId;
+ const otherMembers = channel
+ ? Object.values(channel.state.members).filter(
+ (member) => member.user?.id !== loggedInUserId,
+ )
+ : [];
+ return otherMembers.length === 1 ? otherMembers[0] : undefined;
+};