20 public static function add($dialogId, $userId =
null)
22 $userId = \Bitrix\Im\Common::getUserId($userId);
28 if (!$dialogId || $dialogId ==
'chat0')
40 $chatId = \Bitrix\Im\Dialog::getChatId($dialogId);
42 if (!$relations[$userId])
47 $relationId = $relations[$userId][
'ID'];
51 $relations = \Bitrix\Im\Dialog::getRelation($userId, $dialogId, [
'WITHOUT_COUNTERS' =>
'Y']);
52 if (!$relations[$userId])
57 $chatId = $relations[$userId][
'CHAT_ID'];
58 $relationId = $relations[$userId][
'ID'];
61 $orm = \Bitrix\Im\Model\LastSearchTable::getList(Array(
62 'filter' => Array(
'USER_ID' => $userId,
'DIALOG_ID' => $dialogId),
63 'order' => Array(
'ID' =>
'DESC')
70 $result = \Bitrix\Im\Model\LastSearchTable::add(Array(
72 'DIALOG_ID' => $dialogId,
73 'ITEM_CID' => $chatId,
74 'ITEM_RID' => $relationId,
77 if (!$result->isSuccess())
83 $orm = \Bitrix\Im\Model\LastSearchTable::getList(Array(
84 'filter' => Array(
'USER_ID' => $userId),
85 'order' => Array(
'ID' =>
'DESC')
87 while ($row = $orm->fetch())
91 if ($count > self::LIMIT)
93 $delete[] = $row[
'ID'];
97 foreach ($delete as $id)
99 \Bitrix\Im\Model\LastSearchTable::delete($id);
104 return $result->getId();
144 public static function get($userId =
null, $options = array())
146 $userId = \Bitrix\Im\Common::getUserId($userId);
155 $cachePath = self::CACHE_PATH.\Bitrix\Im\Common::getCacheUserPostfix($userId);
157 $cache = \Bitrix\Main\Application::getInstance()->getCache();
158 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
159 if($cache->initCache(self::CACHE_TTL, $cacheId, $cachePath))
161 $result = $cache->getVars();
165 $generalChatId = \CIMChat::GetGeneralChatId();
169 'RELATION_USER_ID' =>
'RELATION.USER_ID',
170 'RELATION_NOTIFY_BLOCK' =>
'RELATION.NOTIFY_BLOCK',
171 'CHAT_TITLE' =>
'CHAT.TITLE',
172 'CHAT_TYPE' =>
'CHAT.TYPE',
173 'CHAT_AVATAR' =>
'CHAT.AVATAR',
174 'CHAT_LAST_MESSAGE_STATUS' =>
'CHAT.LAST_MESSAGE_STATUS',
176 'CHAT_AUTHOR_ID' =>
'CHAT.AUTHOR_ID',
177 'CHAT_EXTRANET' =>
'CHAT.EXTRANET',
178 'CHAT_COLOR' =>
'CHAT.COLOR',
179 'CHAT_ENTITY_TYPE' =>
'CHAT.ENTITY_TYPE',
180 'CHAT_ENTITY_ID' =>
'CHAT.ENTITY_ID',
181 'CHAT_ENTITY_DATA_1' =>
'CHAT.ENTITY_DATA_1',
182 'CHAT_ENTITY_DATA_2' =>
'CHAT.ENTITY_DATA_2',
183 'CHAT_ENTITY_DATA_3' =>
'CHAT.ENTITY_DATA_3',
184 'CHAT_DATE_CREATE' =>
'CHAT.DATE_CREATE',
187 $orm = \Bitrix\Im\Model\LastSearchTable::getList(Array(
189 'filter' => Array(
'=USER_ID' => $userId),
190 'order' => Array(
'ID' =>
'DESC')
192 while ($row = $orm->fetch())
194 $isUser = mb_strpos($row[
'DIALOG_ID'],
'chat') !== 0;
195 $id = $row[
'DIALOG_ID'];
198 'ID' => $isUser? (
int)$id: $id,
199 'TYPE' => $isUser?
'user':
'chat',
206 $item[
'USER'] = Array(
207 'ID' => (
int)$row[
'DIALOG_ID'],
212 $avatar = \CIMChat::GetAvatarImage($row[
'CHAT_AVATAR'], 200,
false);
214 $chatType = \Bitrix\Im\Chat::getType($row);
216 if ($generalChatId == $row[
'ITEM_ID'])
218 $row[
"CHAT_ENTITY_TYPE"] =
'GENERAL';
222 if ($row[
'RELATION_NOTIFY_BLOCK'] ==
'Y')
224 $muteList = Array($row[
'RELATION_USER_ID'] =>
true);
227 $item[
'AVATAR'] = Array(
231 $item[
'TITLE'] = $row[
'CHAT_TITLE'];
232 $item[
'CHAT'] = Array(
233 'ID' => (
int)$row[
'ITEM_CID'],
234 'NAME' => $row[
'CHAT_TITLE'],
235 'OWNER' => (
int)$row[
'CHAT_AUTHOR_ID'],
236 'EXTRANET' => $row[
'CHAT_EXTRANET'] ==
'Y',
240 'ENTITY_TYPE' => (
string)$row[
'CHAT_ENTITY_TYPE'],
241 'ENTITY_ID' => (
string)$row[
'CHAT_ENTITY_ID'],
242 'ENTITY_DATA_1' => (
string)$row[
'CHAT_ENTITY_DATA_1'],
243 'ENTITY_DATA_2' => (
string)$row[
'CHAT_ENTITY_DATA_2'],
244 'ENTITY_DATA_3' => (
string)$row[
'CHAT_ENTITY_DATA_3'],
245 'MUTE_LIST' => $muteList,
246 'DATE_CREATE' => $row[
'CHAT_DATE_CREATE'],
247 'MESSAGE_TYPE' => $row[
"CHAT_TYPE"],
251 $result[$id] = $item;
254 $taggedCache->startTagCache($cachePath);
255 $taggedCache->registerTag(
"USER_NAME");
256 $taggedCache->endTagCache();
258 $cache->startDataCache();
259 $cache->endDataCache($result);
262 foreach ($result as $id => $item)
264 if ($options[
'SKIP_OPENLINES'] ==
'Y')
266 if ($item[
'TYPE'] ==
'chat' && $item[
'CHAT'][
'TYPE'] ==
'lines')
272 if ($options[
'SKIP_CHAT'] ==
'Y')
274 if ($item[
'TYPE'] ==
'chat' && $item[
'CHAT'][
'TYPE'] !=
'lines')
280 if ($options[
'SKIP_DIALOG'] ==
'Y')
282 if ($item[
'TYPE'] ==
'user')
289 if ($item[
'USER'][
'ID'] > 0)
294 $user = Array(
'ID' => 0);
296 else if ($item[
'TYPE'] ==
'user')
298 $item[
'AVATAR'] = Array(
299 'URL' => $user[
'AVATAR'],
300 'COLOR' => $user[
'COLOR']
302 $item[
'TITLE'] = $user[
'NAME'];
305 $item[
'USER'] = $user;
307 $result[$id] = $item;
311 $result = array_values($result);
313 if ($options[
'JSON'])
315 foreach ($result as $index => $item)
317 foreach ($item as $key => $value)
321 $item[$key] = date(
'c', $value->getTimestamp());
323 else if (is_array($value))
325 foreach ($value as $subKey => $subValue)
329 $value[$subKey] = date(
'c', $subValue->getTimestamp());
331 else if (is_string($subValue) && $subValue && in_array($subKey, Array(
'URL',
'AVATAR')) && mb_strpos($subValue,
'http') !== 0)
333 $value[$subKey] = \Bitrix\Im\Common::getPublicDomain().$subValue;
335 else if (is_array($subValue))
337 $value[$subKey] = array_change_key_case($subValue, CASE_LOWER);
340 $item[$key] = array_change_key_case($value, CASE_LOWER);
343 $result[$index] = array_change_key_case($item, CASE_LOWER);