@smart-link/rn-im 1.0.22 → 1.0.24

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.
Files changed (155) hide show
  1. package/dist/api/addressList.js +6 -17
  2. package/dist/api/backup.js +8 -20
  3. package/dist/api/file.js +6 -35
  4. package/dist/api/user.js +6 -16
  5. package/dist/components/CachedImage.js +14 -42
  6. package/dist/components/Camera/Camera.js +26 -54
  7. package/dist/components/Camera/CameraCapture.js +99 -128
  8. package/dist/components/Camera/CameraResult.js +33 -61
  9. package/dist/components/ChatAvatar/ChatAvatar.d.ts +1 -1
  10. package/dist/components/ChatAvatar/ChatAvatar.js +34 -62
  11. package/dist/components/ChatAvatar/ChatAvatarId.d.ts +2 -2
  12. package/dist/components/ChatAvatar/ChatAvatarId.js +26 -51
  13. package/dist/components/ChatAvatar/ChatAvatarLocal.d.ts +2 -2
  14. package/dist/components/ChatAvatar/ChatAvatarLocal.js +23 -25
  15. package/dist/components/ChatAvatar/index.js +2 -23
  16. package/dist/components/Favicon.js +6 -34
  17. package/dist/components/FormatTimeText.js +5 -10
  18. package/dist/components/Highlighter.js +9 -34
  19. package/dist/components/IndicatorText.js +14 -39
  20. package/dist/components/LocalImage.js +7 -32
  21. package/dist/components/NetworkUnconnected.js +14 -42
  22. package/dist/components/PopoverWrapper.js +22 -47
  23. package/dist/components/VideoPlayer.js +111 -138
  24. package/dist/components/styles.js +10 -13
  25. package/dist/default-assets.d.ts +1 -0
  26. package/dist/default-assets.js +8 -10
  27. package/dist/hooks/useDownloadSource.js +7 -12
  28. package/dist/hooks/useFormatMsgTime.js +5 -13
  29. package/dist/hooks/useImReady.js +7 -10
  30. package/dist/hooks/useImSelector.js +34 -48
  31. package/dist/hooks/useTranslation.js +5 -10
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +8 -28
  34. package/dist/init.js +30 -40
  35. package/dist/interface.js +1 -2
  36. package/dist/locales/en/addressList.js +1 -3
  37. package/dist/locales/index.js +4 -27
  38. package/dist/locales/lao/addressList.js +1 -3
  39. package/dist/locales/zh/addressList.js +1 -3
  40. package/dist/pages/address-list/AddressList.js +33 -61
  41. package/dist/pages/address-list/CardInfo.js +10 -18
  42. package/dist/pages/address-list/ChooseContact.js +50 -78
  43. package/dist/pages/address-list/Icons.js +7 -14
  44. package/dist/pages/address-list/Organization.js +59 -89
  45. package/dist/pages/address-list/UserDetail.js +55 -83
  46. package/dist/pages/address-list/UserJobs.js +31 -33
  47. package/dist/pages/address-list/UserSearch.js +29 -54
  48. package/dist/pages/address-list/addressList.routes.js +11 -16
  49. package/dist/pages/collection/Collection.js +53 -81
  50. package/dist/pages/collection/ContentFactory.js +53 -82
  51. package/dist/pages/collection/collection.routes.js +3 -9
  52. package/dist/pages/conversation/ForwardToConversation.js +63 -91
  53. package/dist/pages/conversation/List.js +74 -102
  54. package/dist/pages/conversation/components/ConversationCard.js +52 -81
  55. package/dist/pages/conversation/components/ConversationOption.js +27 -55
  56. package/dist/pages/conversation/conversation.routes.js +17 -23
  57. package/dist/pages/conversation/setting/GroupTransfer.js +32 -60
  58. package/dist/pages/conversation/setting/OptionAvatars.js +62 -90
  59. package/dist/pages/conversation/setting/OptionCancelGroup.js +14 -42
  60. package/dist/pages/conversation/setting/OptionConversation.js +20 -48
  61. package/dist/pages/conversation/setting/OptionGroup.js +20 -48
  62. package/dist/pages/conversation/setting/OptionGroupManage.js +21 -49
  63. package/dist/pages/conversation/setting/OptionGroupMoreMember.js +48 -53
  64. package/dist/pages/conversation/setting/OptionGroupNameOrNoticeEdit.js +49 -77
  65. package/dist/pages/conversation/setting/Setting.js +49 -54
  66. package/dist/pages/conversation/setting/SettingChatBg.js +26 -54
  67. package/dist/pages/index.js +7 -27
  68. package/dist/pages/message/ChooseMember.js +56 -84
  69. package/dist/pages/message/MessageBackup/Bar.js +18 -43
  70. package/dist/pages/message/MessageBackup/MessageBackup.js +42 -72
  71. package/dist/pages/message/MessageBackup/RestoreBackupPage.js +48 -76
  72. package/dist/pages/message/MessageBackup/StartBackupPage.js +48 -76
  73. package/dist/pages/message/MessageBackup/index.js +3 -12
  74. package/dist/pages/message/MessageBackup/utils.js +14 -22
  75. package/dist/pages/message/MessageList.js +141 -134
  76. package/dist/pages/message/MessageRecord.js +49 -73
  77. package/dist/pages/message/components/BusiNotifyCard.js +60 -85
  78. package/dist/pages/message/components/ChatBg.js +11 -36
  79. package/dist/pages/message/components/MessageItem.js +82 -110
  80. package/dist/pages/message/components/MessageItemQuote.js +30 -58
  81. package/dist/pages/message/components/MessageItemTips.js +27 -55
  82. package/dist/pages/message/components/MessageOption.js +96 -120
  83. package/dist/pages/message/components/MessagePayload.js +36 -64
  84. package/dist/pages/message/components/MessagePictureAlbum.js +32 -60
  85. package/dist/pages/message/components/MessageReceiptStatus.js +18 -43
  86. package/dist/pages/message/components/MessageUndo.js +18 -48
  87. package/dist/pages/message/components/MultipleBar/index.js +48 -76
  88. package/dist/pages/message/components/Payload/PayloadContact.js +30 -58
  89. package/dist/pages/message/components/Payload/PayloadFile.js +41 -65
  90. package/dist/pages/message/components/Payload/PayloadMultiple.js +38 -66
  91. package/dist/pages/message/components/Payload/PayloadNotify.js +28 -56
  92. package/dist/pages/message/components/Payload/PayloadPicture.js +21 -49
  93. package/dist/pages/message/components/Payload/PayloadShare.js +39 -67
  94. package/dist/pages/message/components/Payload/PayloadText.js +39 -67
  95. package/dist/pages/message/components/Payload/PayloadVideo.js +28 -56
  96. package/dist/pages/message/components/Payload/PayloadVoice.js +80 -93
  97. package/dist/pages/message/components/Payload/PayloadWrapper.js +18 -43
  98. package/dist/pages/message/components/Payload/type.js +1 -2
  99. package/dist/pages/message/components/ReceiptBack.js +31 -61
  100. package/dist/pages/message/components/TextMixMessage.js +13 -38
  101. package/dist/pages/message/components/TextMixQuote.js +129 -158
  102. package/dist/pages/message/components/TextMixQuoteMessage.js +16 -44
  103. package/dist/pages/message/components/UploadProgress.js +12 -37
  104. package/dist/pages/message/components/messageBar/EmojiPanel.js +25 -50
  105. package/dist/pages/message/components/messageBar/Icons.js +56 -74
  106. package/dist/pages/message/components/messageBar/MessageBar.js +84 -115
  107. package/dist/pages/message/components/messageBar/MessageInput.js +30 -55
  108. package/dist/pages/message/components/messageBar/OptionPanel.js +54 -82
  109. package/dist/pages/message/components/messageBar/VoiceBar.js +122 -100
  110. package/dist/pages/message/components/messageBar/index.js +2 -23
  111. package/dist/pages/message/message.routes.js +11 -40
  112. package/dist/pages/search/Search.js +38 -66
  113. package/dist/pages/search/SearchChatRecords.js +64 -92
  114. package/dist/pages/search/SearchFile.js +68 -96
  115. package/dist/pages/search/SearchManager.js +60 -65
  116. package/dist/pages/search/SearchPicturePage.js +16 -44
  117. package/dist/pages/search/components/ChatRecords.js +46 -74
  118. package/dist/pages/search/components/MyGroupChat.js +41 -69
  119. package/dist/pages/search/components/PictureMulipleBar.js +35 -63
  120. package/dist/pages/search/components/SearchFileList.js +59 -64
  121. package/dist/pages/search/components/SearchPictures.js +68 -98
  122. package/dist/pages/search/components/SearchShareLinkList.js +50 -55
  123. package/dist/pages/search/components/SearchUser.js +25 -53
  124. package/dist/pages/search/components/useSearchMessage.js +12 -16
  125. package/dist/pages/search/search.routes.js +11 -17
  126. package/dist/pages/search/utils.js +4 -12
  127. package/dist/pages/types.js +1 -2
  128. package/dist/slice/contact/contact.action.js +1 -2
  129. package/dist/slice/contact/contact.slice.js +7 -11
  130. package/dist/slice/index.js +7 -13
  131. package/dist/slice/panel/panel.slice.d.ts +2 -1
  132. package/dist/slice/panel/panel.slice.js +8 -7
  133. package/dist/slice/video/video.action.d.ts +1 -0
  134. package/dist/slice/video/video.action.js +56 -38
  135. package/dist/slice/video/video.slice.d.ts +1 -1
  136. package/dist/slice/video/video.slice.js +7 -8
  137. package/dist/utils/audio.d.ts +3 -0
  138. package/dist/utils/audio.js +10 -0
  139. package/dist/utils/color.js +2 -9
  140. package/dist/utils/common-action-sheet.js +9 -14
  141. package/dist/utils/cookie.js +6 -14
  142. package/dist/utils/emoji.js +9 -12
  143. package/dist/utils/file-icon.js +33 -60
  144. package/dist/utils/file-operate.js +1 -2
  145. package/dist/utils/file.d.ts +1 -1
  146. package/dist/utils/file.js +74 -87
  147. package/dist/utils/golden-rectangle.js +3 -7
  148. package/dist/utils/phone.js +13 -22
  149. package/dist/utils/request.js +7 -15
  150. package/dist/utils/scroll.js +5 -9
  151. package/dist/utils/summary.js +4 -11
  152. package/dist/utils/take-camera.js +12 -19
  153. package/dist/utils/text-mix.js +4 -11
  154. package/dist/utils/upload.js +20 -41
  155. package/package.json +6 -7
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,14 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MessageRestoreUtils = exports.MessageBackupUtils = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const init_1 = require("../../../init");
18
- const backup_1 = require("../../../api/backup");
10
+ import axios from "axios";
11
+ import { getImManager } from "../../../init";
12
+ import { uploadMessage, cancelBackupMessage, queryMyBackMessage, queryMyLastBackupMessageSeq } from "../../../api/backup";
19
13
  class Queue {
20
14
  constructor() {
21
15
  this.queue = [];
@@ -96,7 +90,7 @@ class BaseUtils {
96
90
  }
97
91
  class TaskItem {
98
92
  constructor(limit, offset) {
99
- this.cancelToken = axios_1.default.CancelToken.source();
93
+ this.cancelToken = axios.CancelToken.source();
100
94
  this.limit = limit;
101
95
  this.offset = offset;
102
96
  }
@@ -119,19 +113,19 @@ class BackupTaskItem extends TaskItem {
119
113
  }
120
114
  execute(callback, batchId) {
121
115
  return __awaiter(this, void 0, void 0, function* () {
122
- const { data, lastMessageSeq } = yield (0, init_1.getImManager)().db.selectMessageForBackup({
116
+ const { data, lastMessageSeq } = yield getImManager().db.selectMessageForBackup({
123
117
  messageSeq: this.messageSeq,
124
118
  limit: this.limit,
125
119
  offset: this.offset
126
120
  });
127
121
  let prevCount = Math.ceil(data.length / 5);
128
122
  callback(prevCount, batchId);
129
- const { data: newBatchId } = yield (0, backup_1.uploadMessage)({ batchId: batchId, lastMessageSeq, messages: data }, { cancelToken: this.cancelToken.token });
123
+ const { data: newBatchId } = yield uploadMessage({ batchId: batchId, lastMessageSeq, messages: data }, { cancelToken: this.cancelToken.token });
130
124
  callback(data.length - prevCount, newBatchId || batchId);
131
125
  });
132
126
  }
133
127
  }
134
- class MessageBackupUtils extends BaseUtils {
128
+ export class MessageBackupUtils extends BaseUtils {
135
129
  constructor(callback) {
136
130
  super(callback);
137
131
  }
@@ -146,9 +140,9 @@ class MessageBackupUtils extends BaseUtils {
146
140
  return __awaiter(this, void 0, void 0, function* () {
147
141
  this.state = 'running';
148
142
  // 查询最近一次备份的消息序列
149
- const { data: messageSeq } = yield (0, backup_1.queryMyLastBackupMessageSeq)();
143
+ const { data: messageSeq } = yield queryMyLastBackupMessageSeq();
150
144
  console.log('LastBackup messageSeq: ', messageSeq);
151
- const total = yield (0, init_1.getImManager)().db.countMessageAfterSeq(messageSeq);
145
+ const total = yield getImManager().db.countMessageAfterSeq(messageSeq);
152
146
  console.log('total', total);
153
147
  this.total = total;
154
148
  // 没有需要备份的消息
@@ -169,11 +163,10 @@ class MessageBackupUtils extends BaseUtils {
169
163
  });
170
164
  return __awaiter(this, void 0, void 0, function* () {
171
165
  _super.cancel.call(this);
172
- yield (0, backup_1.cancelBackupMessage)(this.batchId);
166
+ yield cancelBackupMessage(this.batchId);
173
167
  });
174
168
  }
175
169
  }
176
- exports.MessageBackupUtils = MessageBackupUtils;
177
170
  class RestoreTaskItem extends TaskItem {
178
171
  constructor(pageNum, pageSize) {
179
172
  super(pageNum, pageSize);
@@ -182,8 +175,8 @@ class RestoreTaskItem extends TaskItem {
182
175
  }
183
176
  execute(callback) {
184
177
  return __awaiter(this, void 0, void 0, function* () {
185
- const { data: { records: [messages] } } = yield (0, backup_1.queryMyBackMessage)({ pageNum: this.pageNum, pageSize: this.pageSize }, { cancelToken: this.cancelToken.token });
186
- const imManager = (0, init_1.getImManager)();
178
+ const { data: { records: [messages] } } = yield queryMyBackMessage({ pageNum: this.pageNum, pageSize: this.pageSize }, { cancelToken: this.cancelToken.token });
179
+ const imManager = getImManager();
187
180
  yield Promise.all(messages.map(item => {
188
181
  return (() => __awaiter(this, void 0, void 0, function* () {
189
182
  const message = JSON.parse(item);
@@ -207,7 +200,7 @@ class RestoreTaskItem extends TaskItem {
207
200
  });
208
201
  }
209
202
  }
210
- class MessageRestoreUtils extends BaseUtils {
203
+ export class MessageRestoreUtils extends BaseUtils {
211
204
  constructor(callback) {
212
205
  super(callback);
213
206
  // 默认每页1个批次的多条数据,按批次处理进度
@@ -223,7 +216,7 @@ class MessageRestoreUtils extends BaseUtils {
223
216
  start() {
224
217
  return __awaiter(this, void 0, void 0, function* () {
225
218
  this.state = 'running';
226
- const { data: { total, } } = yield (0, backup_1.queryMyBackMessage)({ pageNum: 1, pageSize: 1 });
219
+ const { data: { total, } } = yield queryMyBackMessage({ pageNum: 1, pageSize: 1 });
227
220
  console.log('total: ', total);
228
221
  this.total = total;
229
222
  const length = Math.ceil(this.total / this.pageSize);
@@ -236,4 +229,3 @@ class MessageRestoreUtils extends BaseUtils {
236
229
  });
237
230
  }
238
231
  }
239
- exports.MessageRestoreUtils = MessageRestoreUtils;
@@ -1,94 +1,68 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const im_base_1 = require("@smart-link/im-base");
30
- const rn_ui_1 = require("@smart-link/rn-ui");
31
- const react_1 = __importStar(require("react"));
32
- const react_native_1 = require("react-native");
33
- const FontAwesome5_1 = __importDefault(require("react-native-vector-icons/FontAwesome5"));
34
- const useImSelector_1 = require("../../hooks/useImSelector");
35
- const useTranslation_1 = __importDefault(require("../../hooks/useTranslation"));
36
- const init_1 = require("../../init");
37
- const MessageBar_1 = __importDefault(require("./components/messageBar/MessageBar"));
38
- const MessageItem_1 = __importDefault(require("./components/MessageItem"));
39
- const MessageOption_1 = __importDefault(require("./components/MessageOption"));
40
- const VideoPlayer_1 = __importDefault(require("../../components/VideoPlayer"));
41
- const MessageItemQuote_1 = __importDefault(require("../../pages/message/components/MessageItemQuote"));
42
- const MessagePictureAlbum_1 = __importDefault(require("./components/MessagePictureAlbum"));
43
- const MultipleBar_1 = __importDefault(require("./components/MultipleBar"));
44
- const ChatBg_1 = __importDefault(require("./components/ChatBg"));
45
- const ahooks_1 = require("ahooks");
46
- const MessageItemTips_1 = __importDefault(require("./components/MessageItemTips"));
1
+ import { ConversationType, MessageActions, MessagePanelActions, PayloadType, TipsType, showTimeLine, } from '@smart-link/im-base';
2
+ import { dp, HeaderBackButton, Input, NavigationPage } from '@smart-link/rn-ui';
3
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { View, Text, FlatList, TouchableOpacity, Keyboard, InteractionManager, StyleSheet, ActivityIndicator, TouchableWithoutFeedback } from 'react-native';
5
+ import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
6
+ import { useAuth, useConversation, useMessage } from '../../hooks/useImSelector';
7
+ import useTranslation from '../../hooks/useTranslation';
8
+ import { getImManager } from '../../init';
9
+ import MessageBar from './components/messageBar/MessageBar';
10
+ import MessageItem from './components/MessageItem';
11
+ import MessageOption from './components/MessageOption';
12
+ import MessageItemQuote from './components/MessageItemQuote';
13
+ import MessagePictureAlbum from './components/MessagePictureAlbum';
14
+ import MultipleBar from './components/MultipleBar';
15
+ import ChatBg from './components/ChatBg';
16
+ import { useMemoizedFn } from "ahooks";
17
+ import MessageItemTips from './components/MessageItemTips';
18
+ import FastImage from "react-native-fast-image";
19
+ import { noMessageImg } from "../../default-assets";
47
20
  const MessageList = ({ navigation }) => {
48
- const { t } = (0, useTranslation_1.default)();
49
- const messageListRef = (0, react_1.useRef)(null);
50
- const { currentConversation } = (0, useImSelector_1.useConversation)();
51
- const { messages, rangeList, quote, tips, isMultiple, multipleSelect, isSearch } = (0, useImSelector_1.useMessage)();
52
- const { user } = (0, useImSelector_1.useAuth)();
53
- const bar = (0, react_1.useRef)(null);
54
- const [showAlbum, setShowAlbum] = (0, react_1.useState)(false);
55
- const [targetMessageSeq, setTargetMessageSeq] = (0, react_1.useState)('');
56
- const [selectMessage, setSelectMessage] = (0, react_1.useState)();
57
- const [nativeEvent, setNativeEvent] = (0, react_1.useState)();
58
- const [loading, setLoading] = (0, react_1.useState)(false);
59
- const isB2C = (currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === im_base_1.ConversationType.B2C;
60
- (0, react_1.useEffect)(() => {
21
+ const { t } = useTranslation();
22
+ const messageListRef = useRef(null);
23
+ const { currentConversation } = useConversation();
24
+ const { messages, rangeList, quote, tips, isMultiple, multipleSelect, isSearch } = useMessage();
25
+ const { user } = useAuth();
26
+ const bar = useRef(null);
27
+ const [showAlbum, setShowAlbum] = useState(false);
28
+ const [targetMessageSeq, setTargetMessageSeq] = useState('');
29
+ const [selectMessage, setSelectMessage] = useState();
30
+ const [nativeEvent, setNativeEvent] = useState();
31
+ const [loading, setLoading] = useState(false);
32
+ const itemLayout = useRef({});
33
+ const isB2C = (currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === ConversationType.B2C;
34
+ useEffect(() => {
61
35
  console.log('[进入会话]: ', currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.name);
62
36
  if (currentConversation) {
63
37
  navigation.setOptions({
64
38
  headerLeft: isMultiple
65
- ? () => (<react_native_1.TouchableOpacity onPress={() => {
66
- (0, init_1.getImManager)().store.dispatch(im_base_1.MessagePanelActions.cancelMultipleSelect());
39
+ ? () => (<TouchableOpacity onPress={() => {
40
+ getImManager().store.dispatch(MessagePanelActions.cancelMultipleSelect());
67
41
  }}>
68
- <react_native_1.Text style={{ color: '#fff' }}>{t('cancel')}</react_native_1.Text>
69
- </react_native_1.TouchableOpacity>)
70
- : rn_ui_1.HeaderBackButton,
71
- headerTitle: ({ tintColor }) => (<react_native_1.View style={{ width: (0, rn_ui_1.dp)(220) }}>
72
- <react_native_1.Text numberOfLines={1} style={{ color: tintColor, fontSize: (0, rn_ui_1.dp)(18), textAlign: 'center' }}>{currentConversation.name}</react_native_1.Text>
73
- </react_native_1.View>),
74
- headerRight: ({ tintColor }) => (<react_native_1.TouchableOpacity onPress={() => {
42
+ <Text style={{ color: '#fff' }}>{t('cancel')}</Text>
43
+ </TouchableOpacity>)
44
+ : HeaderBackButton,
45
+ headerTitle: ({ tintColor }) => (<View style={{ width: dp(220) }}>
46
+ <Text numberOfLines={1} style={{ color: tintColor, fontSize: dp(18), textAlign: 'center' }}>{currentConversation.name}</Text>
47
+ </View>),
48
+ headerRight: ({ tintColor }) => (<TouchableOpacity onPress={() => {
75
49
  navigation.navigate('ConversationSetting');
76
- }} style={{ width: (0, rn_ui_1.dp)(40), justifyContent: 'center', alignItems: 'center' }}>
77
- <FontAwesome5_1.default name="ellipsis-h" color={tintColor} size={(0, rn_ui_1.dp)(18)}/>
78
- </react_native_1.TouchableOpacity>),
50
+ }} style={{ width: dp(40), justifyContent: 'center', alignItems: 'center' }}>
51
+ <FontAwesome5 name="ellipsis-h" color={tintColor} size={dp(18)}/>
52
+ </TouchableOpacity>),
79
53
  });
80
54
  }
81
55
  let remover = navigation.addListener('beforeRemove', e => {
82
- const imManager = (0, init_1.getImManager)();
56
+ const imManager = getImManager();
83
57
  if (isMultiple) {
84
58
  e.preventDefault();
85
- imManager.store.dispatch(im_base_1.MessagePanelActions.cancelMultipleSelect());
59
+ imManager.store.dispatch(MessagePanelActions.cancelMultipleSelect());
86
60
  }
87
61
  else {
88
- console.log('[离开会话]: ');
89
- imManager.store.dispatch(im_base_1.MessagePanelActions.saveDraftText(imManager));
90
- react_native_1.InteractionManager.runAfterInteractions(() => {
62
+ InteractionManager.runAfterInteractions(() => {
63
+ imManager.store.dispatch(MessagePanelActions.saveDraftText(imManager));
91
64
  imManager.leaveConversation();
65
+ imManager.store.dispatch(MessageActions.resetState());
92
66
  });
93
67
  }
94
68
  });
@@ -96,97 +70,130 @@ const MessageList = ({ navigation }) => {
96
70
  remover();
97
71
  };
98
72
  }, [isMultiple, navigation, currentConversation]);
99
- (0, react_1.useEffect)(() => {
100
- (0, init_1.getImManager)().setFlatListRef(messageListRef);
101
- (0, init_1.getImManager)().setInputRef(bar);
73
+ useEffect(() => {
74
+ getImManager().setFlatListRef(messageListRef);
75
+ getImManager().setInputRef(bar);
102
76
  }, []);
103
- (0, react_1.useEffect)(() => {
77
+ useEffect(() => {
104
78
  var _a;
105
79
  if (isSearch) {
106
80
  (_a = messageListRef.current) === null || _a === void 0 ? void 0 : _a.scrollToOffset({ animated: false, offset: 0 });
107
- (0, init_1.getImManager)().store.dispatch(im_base_1.MessageActions.setIsSearch(false));
81
+ getImManager().store.dispatch(MessageActions.setIsSearch(false));
108
82
  }
109
83
  }, [isSearch]);
110
- const onLongPressPopover = (0, react_1.useCallback)((message, nativeEvent) => {
84
+ const onLongPressPopover = useCallback((message, nativeEvent) => {
111
85
  setNativeEvent(nativeEvent);
112
86
  setSelectMessage(message);
113
87
  }, []);
114
- const onLayoutItem = (0, ahooks_1.useMemoizedFn)((message, e) => {
88
+ const onLayoutItem = useMemoizedFn((message, e) => {
89
+ itemLayout.current[message.messageSeq] = e.nativeEvent.layout.height;
115
90
  if (rangeList.length > 0 && message.messageSeq === (tips === null || tips === void 0 ? void 0 : tips.messageSeq)) {
116
- const imManager = (0, init_1.getImManager)();
117
- imManager.store.dispatch(im_base_1.MessagePanelActions.onRangeLayout(imManager));
91
+ const imManager = getImManager();
92
+ imManager.store.dispatch(MessagePanelActions.onRangeLayout(imManager));
118
93
  }
119
94
  });
120
- const onPressPopover = (0, react_1.useCallback)((message, nativeEvent) => {
121
- if (message.payloadType === im_base_1.PayloadType.PICTURE) {
95
+ const onLoadBefore = useMemoizedFn(() => {
96
+ getImManager()
97
+ .loadBeforeMessages(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id, { limit: 15 })
98
+ .then(() => {
99
+ console.log('loaded');
100
+ });
101
+ });
102
+ const onLoadAfter = useMemoizedFn(() => {
103
+ getImManager()
104
+ .loadAfterMessages(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id, { limit: 15 })
105
+ .then(() => {
106
+ console.log('loaded');
107
+ });
108
+ });
109
+ const renderItem = useMemoizedFn(({ item, index }) => {
110
+ return (<MessageItem message={item} conversation={currentConversation} mine={item.messageFrom === user.userId} showTimeLine={showTimeLine(item, index, messages)} isMultiple={isMultiple} multipleSelect={multipleSelect} onLongPressPopover={onLongPressPopover} onPressPopover={onPressPopover} onLayoutItem={onLayoutItem}/>);
111
+ });
112
+ const onTouchStart = useCallback(() => {
113
+ var _a;
114
+ (_a = bar.current) === null || _a === void 0 ? void 0 : _a.reset();
115
+ }, []);
116
+ const onPressPopover = useCallback((message, nativeEvent) => {
117
+ if (message.payloadType === PayloadType.PICTURE) {
122
118
  setNativeEvent(nativeEvent);
123
119
  setShowAlbum(true);
124
120
  setTargetMessageSeq(message.messageSeq);
125
121
  }
126
122
  }, []);
127
123
  const onKeyboardAt = () => {
128
- if ((currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === im_base_1.ConversationType.C2G) {
129
- react_native_1.Keyboard.dismiss();
124
+ if ((currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === ConversationType.C2G) {
125
+ Keyboard.dismiss();
130
126
  navigation.navigate('ChooseMember', { atOther: true });
131
127
  }
132
128
  };
133
- return (<rn_ui_1.NavigationPage noPadding>
134
- {(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === im_base_1.ConversationType.B2C && (<react_native_1.View style={{ padding: (0, rn_ui_1.dp)(8), backgroundColor: '#f5f5f5', elevation: 1 }}>
135
- <rn_ui_1.Input shape="normal" placeholder={t('search')} wrapStyle={{ height: (0, rn_ui_1.dp)(40) }}/>
136
- </react_native_1.View>)}
137
- <ChatBg_1.default fileId={currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.imageBackground}>
129
+ return (<NavigationPage noPadding>
130
+ {(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.type) === ConversationType.B2C && (<View style={{ padding: dp(8), backgroundColor: '#f5f5f5', elevation: 1 }}>
131
+ <Input shape="normal" placeholder={t('search')} wrapStyle={{ height: dp(40) }}/>
132
+ </View>)}
133
+
134
+ {messages.length === 0 && (<TouchableWithoutFeedback onPress={onTouchStart} style={{ flex: 1 }}>
135
+ <View style={styles.empty}>
136
+ <FastImage source={noMessageImg} style={styles.noMessageImg}/>
137
+ <Text style={styles.noMessageText}>
138
+ {t('noChatMessage')}
139
+ </Text>
140
+ </View>
141
+ </TouchableWithoutFeedback>)}
142
+
143
+ {messages.length > 0 && (<ChatBg fileId={currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.imageBackground}>
138
144
  <>
139
- <react_native_1.FlatList ref={messageListRef} inverted contentContainerStyle={{
140
- paddingVertical: (0, rn_ui_1.dp)(20),
141
- justifyContent: 'flex-end',
142
- flexGrow: 1,
143
- overflow: 'scroll',
144
- }} numColumns={1} onEndReachedThreshold={0.1} keyboardShouldPersistTaps={'handled'} keyExtractor={item => item.messageSeq} renderItem={({ item, index }) => {
145
- return (<MessageItem_1.default message={item} conversation={currentConversation} mine={item.messageFrom === user.userId} showTimeLine={(0, im_base_1.showTimeLine)(item, index, messages)} isMultiple={isMultiple} multipleSelect={multipleSelect} onLongPressPopover={onLongPressPopover} onPressPopover={onPressPopover} onLayoutItem={onLayoutItem}/>);
146
- }} data={messages} onEndReached={() => {
147
- (0, init_1.getImManager)()
148
- .loadBeforeMessages(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id, { limit: 15 })
149
- .then(() => {
150
- console.log('loaded');
151
- });
152
- }} refreshing={false} onRefresh={() => {
153
- (0, init_1.getImManager)()
154
- .loadAfterMessages(currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id, { limit: 15 })
155
- .then(() => {
156
- console.log('loaded last');
157
- });
158
- }} onTouchStart={() => {
159
- var _a;
160
- (_a = bar.current) === null || _a === void 0 ? void 0 : _a.reset();
161
- }} onLayout={() => {
162
- }}/>
163
- {quote && (<MessageItemQuote_1.default {...quote} onDeleteQuote={() => {
164
- (0, init_1.getImManager)().store.dispatch(im_base_1.MessageActions.setQuote(null));
165
- }}/>)}
145
+ <FlatList ref={messageListRef} inverted contentContainerStyle={{
146
+ paddingVertical: dp(20),
147
+ justifyContent: 'flex-end',
148
+ flexGrow: 1,
149
+ overflow: 'scroll',
150
+ }} numColumns={1} onEndReachedThreshold={0.1} keyboardShouldPersistTaps={'handled'} keyExtractor={item => item.messageSeq} renderItem={renderItem} data={messages} onEndReached={onLoadBefore} refreshing={false}
151
+ // 在头部增加数据时,保持滚动位置,0.72 以上可以使用
152
+ maintainVisibleContentPosition={{
153
+ minIndexForVisible: 0,
154
+ }} onRefresh={onLoadAfter} onTouchStart={onTouchStart}/>
155
+ {quote && (<MessageItemQuote {...quote} onDeleteQuote={() => {
156
+ getImManager().store.dispatch(MessageActions.setQuote(null));
157
+ }}/>)}
166
158
  </>
167
- </ChatBg_1.default>
159
+ </ChatBg>)}
168
160
 
169
- {!isB2C && (isMultiple ? <MultipleBar_1.default /> : <MessageBar_1.default ref={bar} onKeyboardAt={onKeyboardAt}/>)}
161
+ {!isB2C && (isMultiple ? <MultipleBar /> : <MessageBar ref={bar} onKeyboardAt={onKeyboardAt}/>)}
170
162
 
171
- {tips && tips.type === im_base_1.TipsType.AT && (<MessageItemTips_1.default {...tips}/>)}
172
- <VideoPlayer_1.default />
173
- <MessageOption_1.default visible={Boolean(selectMessage)} nativeEvent={nativeEvent} message={selectMessage} setLoading={(value) => {
163
+ {tips && tips.type !== TipsType.NONE && (<MessageItemTips {...tips}/>)}
164
+ <MessageOption visible={Boolean(selectMessage)} nativeEvent={nativeEvent} message={selectMessage} setLoading={(value) => {
174
165
  setLoading(value);
175
166
  }} onClose={() => {
176
167
  setNativeEvent(undefined);
177
168
  setSelectMessage(undefined);
178
169
  }}/>
179
170
 
180
- <MessagePictureAlbum_1.default visible={showAlbum} messages={messages} messageSeq={targetMessageSeq} onClose={() => {
171
+ <MessagePictureAlbum visible={showAlbum} messages={messages} messageSeq={targetMessageSeq} onClose={() => {
181
172
  setShowAlbum(false);
182
173
  }}/>
183
174
 
184
- {loading && (<react_native_1.View style={styles.loadingContainer}>
185
- <react_native_1.ActivityIndicator size="large" color="#FFFFFF"/>
186
- </react_native_1.View>)}
187
- </rn_ui_1.NavigationPage>);
175
+ {loading && (<View style={styles.loadingContainer}>
176
+ <ActivityIndicator size="large" color="#FFFFFF"/>
177
+ </View>)}
178
+ </NavigationPage>);
188
179
  };
189
- const styles = react_native_1.StyleSheet.create({
190
- loadingContainer: Object.assign(Object.assign({}, react_native_1.StyleSheet.absoluteFillObject), { backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center', alignItems: 'center', zIndex: 9999 }),
180
+ const styles = StyleSheet.create({
181
+ loadingContainer: Object.assign(Object.assign({}, StyleSheet.absoluteFillObject), { backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center', alignItems: 'center', zIndex: 9999 }),
182
+ empty: {
183
+ flex: 1,
184
+ justifyContent: 'center',
185
+ alignItems: 'center',
186
+ },
187
+ noMessageImg: {
188
+ alignSelf: 'center',
189
+ width: dp(152),
190
+ height: dp(122)
191
+ },
192
+ noMessageText: {
193
+ alignSelf: 'center',
194
+ fontSize: dp(14),
195
+ lineHeight: dp(16),
196
+ color: "#999999"
197
+ },
191
198
  });
192
- exports.default = MessageList;
199
+ export default MessageList;
@@ -1,52 +1,27 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const ChatAvatar_1 = __importDefault(require("../../components/ChatAvatar/ChatAvatar"));
30
- const FormatTimeText_1 = __importDefault(require("../../components/FormatTimeText"));
31
- const rn_ui_1 = require("@smart-link/rn-ui");
32
- const react_1 = __importStar(require("react"));
33
- const react_native_1 = require("react-native");
34
- const MessagePayload_1 = __importDefault(require("./components/MessagePayload"));
35
- const MessagePictureAlbum_1 = __importDefault(require("./components/MessagePictureAlbum"));
36
- const lodash_es_1 = require("lodash-es");
1
+ import ChatAvatar from '../../components/ChatAvatar/ChatAvatar';
2
+ import FormatTimeText from '../../components/FormatTimeText';
3
+ import { dp, NavigationPage } from '@smart-link/rn-ui';
4
+ import React, { useEffect } from 'react';
5
+ import { View, StyleSheet, FlatList, Text } from 'react-native';
6
+ import MessagePayload from './components/MessagePayload';
7
+ import MessagePictureAlbum from "./components/MessagePictureAlbum";
8
+ import { cloneDeep } from "lodash-es";
37
9
  const MessageRecord = ({ navigation, route: { params } }) => {
38
- const { messages, messageSeq, title } = params;
39
- (0, react_1.useEffect)(() => {
10
+ const { messages, title } = params;
11
+ useEffect(() => {
40
12
  navigation.setOptions({
41
13
  title,
42
14
  });
43
15
  }, [navigation, title]);
44
- const [updateMessages, setUpdateMessages] = react_1.default.useState([]);
45
- const [previewMessages, setPreviewMessages] = react_1.default.useState([]);
46
- const [showAlbum, setShowAlbum] = react_1.default.useState(false);
47
- const [targetMessageSeq, setTargetMessageSeq] = react_1.default.useState('');
48
- (0, react_1.useEffect)(() => {
49
- setUpdateMessages((0, lodash_es_1.cloneDeep)(messages));
16
+ const listRef = React.useRef(null);
17
+ const [updateMessages, setUpdateMessages] = React.useState([]);
18
+ const [previewMessages, setPreviewMessages] = React.useState([]);
19
+ const [showAlbum, setShowAlbum] = React.useState(false);
20
+ const [targetMessageSeq, setTargetMessageSeq] = React.useState('');
21
+ useEffect(() => {
22
+ var _a;
23
+ setUpdateMessages(cloneDeep(messages));
24
+ (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.scrollToOffset({ animated: false, offset: 0 });
50
25
  }, [messages]);
51
26
  const onPress = (item) => {
52
27
  var _a;
@@ -63,19 +38,20 @@ const MessageRecord = ({ navigation, route: { params } }) => {
63
38
  setPreviewMessages(updateMessages);
64
39
  }
65
40
  };
66
- return (<rn_ui_1.NavigationPage noPadding>
67
- <react_native_1.FlatList contentContainerStyle={styles.list} data={updateMessages} renderItem={({ item, index }) => {
68
- const isSamePerson = index > 0 && messages[index - 1].messageFrom === item.messageFrom;
69
- return (<react_native_1.View style={styles.messageItem}>
70
- <react_native_1.View style={styles.avatar}>
71
- {!isSamePerson && (<ChatAvatar_1.default id={item.messageFrom} url={item.payload.avatars} size={(0, rn_ui_1.dp)(40)} name={item.messageFromName}/>)}
72
- </react_native_1.View>
73
- <react_native_1.View style={styles.content}>
74
- <react_native_1.View style={styles.info}>
75
- <react_native_1.Text style={styles.usernameText}>{item.messageFromName}</react_native_1.Text>
76
- <FormatTimeText_1.default style={styles.timeText} time={item.messageTime}></FormatTimeText_1.default>
77
- </react_native_1.View>
78
- <MessagePayload_1.default {...item} isRecord direction="left" showArrow={false} onPress={() => {
41
+ return (<NavigationPage noPadding>
42
+ <FlatList ref={listRef} contentContainerStyle={styles.list} data={updateMessages} renderItem={({ item, index }) => {
43
+ console.log('index: ', index);
44
+ const isSamePerson = index > 0 && updateMessages.length > 1 && updateMessages[index - 1].messageFrom === item.messageFrom;
45
+ return (<View style={styles.messageItem}>
46
+ <View style={styles.avatar}>
47
+ {!isSamePerson && (<ChatAvatar id={item.messageFrom} url={item.payload.avatars} size={dp(40)} name={item.messageFromName}/>)}
48
+ </View>
49
+ <View style={styles.content}>
50
+ <View style={styles.info}>
51
+ <Text style={styles.usernameText}>{item.messageFromName}</Text>
52
+ <FormatTimeText style={styles.timeText} time={item.messageTime}></FormatTimeText>
53
+ </View>
54
+ <MessagePayload {...item} isRecord direction="left" showArrow={false} onPress={() => {
79
55
  onPress(item);
80
56
  }} onLoad={(localPath) => {
81
57
  console.log('localPath: ', localPath);
@@ -83,49 +59,49 @@ const MessageRecord = ({ navigation, route: { params } }) => {
83
59
  item.payload.localPath = localPath;
84
60
  }
85
61
  }}/>
86
- </react_native_1.View>
87
- </react_native_1.View>);
62
+ </View>
63
+ </View>);
88
64
  }}/>
89
- <MessagePictureAlbum_1.default visible={showAlbum} messages={previewMessages} messageSeq={targetMessageSeq} onClose={() => {
65
+ <MessagePictureAlbum visible={showAlbum} messages={previewMessages} messageSeq={targetMessageSeq} onClose={() => {
90
66
  setShowAlbum(false);
91
67
  }}/>
92
- </rn_ui_1.NavigationPage>);
68
+ </NavigationPage>);
93
69
  };
94
- const styles = react_native_1.StyleSheet.create({
70
+ const styles = StyleSheet.create({
95
71
  list: {
96
- padding: (0, rn_ui_1.dp)(12),
72
+ padding: dp(12),
97
73
  },
98
74
  titleText: {
99
- fontSize: (0, rn_ui_1.dp)(16),
75
+ fontSize: dp(16),
100
76
  color: '#fff',
101
77
  },
102
78
  messageItem: {
103
79
  flexDirection: 'row',
104
- marginBottom: (0, rn_ui_1.dp)(10),
80
+ marginBottom: dp(10),
105
81
  },
106
82
  avatar: {
107
- width: (0, rn_ui_1.dp)(40),
83
+ width: dp(40),
108
84
  },
109
85
  content: {
110
86
  flex: 1,
111
- marginHorizontal: (0, rn_ui_1.dp)(6),
112
- paddingVertical: (0, rn_ui_1.dp)(4),
113
- borderBottomWidth: (0, rn_ui_1.dp)(1),
87
+ marginHorizontal: dp(6),
88
+ paddingVertical: dp(4),
89
+ borderBottomWidth: dp(1),
114
90
  borderStyle: 'solid',
115
91
  borderColor: '#eee',
116
92
  },
117
93
  info: {
118
94
  flexDirection: 'row',
119
95
  justifyContent: 'space-between',
120
- marginBottom: (0, rn_ui_1.dp)(5),
96
+ marginBottom: dp(5),
121
97
  },
122
98
  usernameText: {
123
99
  color: '#999',
124
- fontSize: (0, rn_ui_1.dp)(12),
100
+ fontSize: dp(12),
125
101
  },
126
102
  timeText: {
127
103
  color: '#999',
128
- fontSize: (0, rn_ui_1.dp)(12),
104
+ fontSize: dp(12),
129
105
  },
130
106
  });
131
- exports.default = MessageRecord;
107
+ export default MessageRecord;