Implements getBuddyConnections helper function
@@ -71,6 +71,33 @@ export function getSuggestedConnectionsByAtomUri(state, atomUri) {
: Immutable.Map();
}
+/**
+ * Returns all buddyConnections of an atom
+ * @param state
+ * @param atomUri
+ * @param excludeClosed -> exclude Closed connections
+ * @param excludeSuggested -> exclude Suggested connections
+ * @returns {*}
+ */
+export function getBuddyConnectionsByAtomUri(
+ state,
+ atomUri,
+ excludeClosed = false,
+ excludeSuggested = false
+) {
+ const atoms = getAtoms(state);
+ const connections = getIn(atoms, [atomUri, "connections"]);
+
+ return connections
+ ? connections
+ .filter(conn => isBuddyConnection(atoms, conn))
+ .filter(conn => !(excludeClosed && connectionUtils.isClosed(conn)))
+ .filter(
+ conn => !(excludeSuggested && connectionUtils.isSuggested(conn))
+ )
+ : Immutable.Map();
+}
+
/**
* @param state
* @returns {Immutable.Map|*}
@@ -140,6 +167,21 @@ export function isChatToChatConnection(allAtoms, connection) {
);
}
+/**
+ * Returns true if both sockets are BuddySockets
+ * @param allAtoms all atoms of the state
+ * @param connection to check sockettypes of
+ * @returns {boolean}
+ */
+export function isBuddyConnection(allAtoms, connection) {
+ const { socket, targetSocket } = getSockets(allAtoms, connection);
+
+ return (
+ socket === won.BUDDY.BuddySocketCompacted &&
+ targetSocket === won.BUDDY.BuddySocketCompacted
+ );
+}
+
/**
* Returns true if socket is a ChatSocket and targetSocket is a GroupSocket
* @param allAtoms all atoms of the state
