@poolse/react-native 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -956,10 +956,14 @@ function ConversationList({
956
956
  conversations: controlled,
957
957
  loading: controlledLoading,
958
958
  error: controlledError,
959
- unreadCounts
959
+ unreadCounts,
960
+ labelFor,
961
+ avatarFor
960
962
  }) {
961
963
  const theme = usePoolseTheme();
962
964
  const auto = react$1.useConversations();
965
+ const { me } = react$1.useMe();
966
+ const meExternalId = me?.external_id ?? null;
963
967
  const isControlled = controlled !== void 0;
964
968
  const conversations = isControlled ? controlled : auto.conversations;
965
969
  const loading = isControlled ? controlledLoading ?? false : auto.loading;
@@ -985,38 +989,66 @@ function ConversationList({
985
989
  if (renderItem) {
986
990
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderItem(item, selected) });
987
991
  }
988
- const unread = counts?.[item.id] ?? 0;
989
- return /* @__PURE__ */ jsxRuntime.jsxs(
990
- reactNative.Pressable,
992
+ return /* @__PURE__ */ jsxRuntime.jsx(
993
+ ConversationRow,
991
994
  {
992
- onPress: () => onSelect?.(item),
993
- style: [
994
- styles5.row,
995
- {
996
- backgroundColor: selected ? theme.colors.surface2 : "transparent"
997
- }
998
- ],
999
- children: [
1000
- /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: null, name: item.name ?? null, seed: item.id, size: "md" }),
1001
- /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles5.body, children: [
1002
- /* @__PURE__ */ jsxRuntime.jsx(
1003
- reactNative.Text,
1004
- {
1005
- style: [styles5.name, { color: theme.colors.ink, fontFamily: theme.type.fontBody }],
1006
- numberOfLines: 1,
1007
- children: item.name ?? "Untitled conversation"
1008
- }
1009
- ),
1010
- item.last_message_at ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.preview, { color: theme.colors.ink3 }], numberOfLines: 1, children: formatRelative(item.last_message_at) }) : null
1011
- ] }),
1012
- unread > 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles5.unreadPill, { backgroundColor: theme.colors.unreadPill }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.unreadText, { color: theme.colors.unreadPillText }], children: unread > 99 ? "99+" : String(unread) }) }) : null
1013
- ]
995
+ conv: item,
996
+ selected,
997
+ meExternalId,
998
+ unread: counts?.[item.id] ?? 0,
999
+ ...labelFor ? { labelFor } : {},
1000
+ ...avatarFor ? { avatarFor } : {},
1001
+ ...onSelect ? { onSelect } : {}
1014
1002
  }
1015
1003
  );
1016
1004
  }
1017
1005
  }
1018
1006
  );
1019
1007
  }
1008
+ function ConversationRow({
1009
+ conv,
1010
+ selected,
1011
+ meExternalId,
1012
+ unread,
1013
+ labelFor,
1014
+ avatarFor,
1015
+ onSelect
1016
+ }) {
1017
+ const theme = usePoolseTheme();
1018
+ const isDirect = conv.type === "direct";
1019
+ const otherExtId = isDirect && meExternalId ? (conv.member_external_ids ?? []).find((x) => x !== meExternalId) ?? null : null;
1020
+ const resolvedOther = react$1.useUser(isDirect ? otherExtId : null);
1021
+ const title = isDirect ? otherExtId ? labelFor?.(otherExtId) ?? resolvedOther.profile?.displayName ?? otherExtId : "Direct chat" : conv.name ?? "Untitled conversation";
1022
+ const avatarUrl = isDirect && otherExtId ? avatarFor?.(otherExtId) ?? resolvedOther.profile?.avatarUrl ?? null : null;
1023
+ const avatarSeed = isDirect ? otherExtId ?? conv.id : conv.id;
1024
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1025
+ reactNative.Pressable,
1026
+ {
1027
+ onPress: () => onSelect?.(conv),
1028
+ style: [
1029
+ styles5.row,
1030
+ {
1031
+ backgroundColor: selected ? theme.colors.surface2 : "transparent"
1032
+ }
1033
+ ],
1034
+ children: [
1035
+ avatarUrl ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Image, { source: { uri: avatarUrl }, style: styles5.rowAvatar }) : /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: null, name: title, seed: avatarSeed, size: "md" }),
1036
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles5.body, children: [
1037
+ /* @__PURE__ */ jsxRuntime.jsx(
1038
+ reactNative.Text,
1039
+ {
1040
+ style: [styles5.name, { color: theme.colors.ink, fontFamily: theme.type.fontBody }],
1041
+ numberOfLines: 1,
1042
+ children: title
1043
+ }
1044
+ ),
1045
+ conv.last_message_preview ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.preview, { color: theme.colors.ink3 }], numberOfLines: 1, children: conv.last_message_preview }) : conv.last_message_at ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.preview, { color: theme.colors.ink3 }], numberOfLines: 1, children: formatRelative(conv.last_message_at) }) : null
1046
+ ] }),
1047
+ unread > 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles5.unreadPill, { backgroundColor: theme.colors.unreadPill }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.unreadText, { color: theme.colors.unreadPillText }], children: unread > 99 ? "99+" : String(unread) }) }) : null
1048
+ ]
1049
+ }
1050
+ );
1051
+ }
1020
1052
  function formatRelative(iso) {
1021
1053
  try {
1022
1054
  const d = new Date(iso);
@@ -1044,6 +1076,11 @@ var styles5 = reactNative.StyleSheet.create({
1044
1076
  paddingVertical: 10,
1045
1077
  gap: 10
1046
1078
  },
1079
+ rowAvatar: {
1080
+ width: 40,
1081
+ height: 40,
1082
+ borderRadius: 20
1083
+ },
1047
1084
  body: {
1048
1085
  flex: 1,
1049
1086
  gap: 2