PageContainer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. import { Container } from 'unstated';
  2. import * as entities from 'entities';
  3. import * as toastr from 'toastr';
  4. import { pagePathUtils } from '@growi/core';
  5. import { apiPost } from '../util/apiv1-client';
  6. import loggerFactory from '~/utils/logger';
  7. import { toastError } from '../util/apiNotification';
  8. import {
  9. DetachCodeBlockInterceptor,
  10. RestoreCodeBlockInterceptor,
  11. } from '../util/interceptor/detach-code-blocks';
  12. import {
  13. DrawioInterceptor,
  14. } from '../util/interceptor/drawio-interceptor';
  15. const { isTrashPage } = pagePathUtils;
  16. const logger = loggerFactory('growi:services:PageContainer');
  17. /**
  18. * Service container related to Page
  19. * @extends {Container} unstated Container
  20. */
  21. export default class PageContainer extends Container {
  22. constructor(appContainer) {
  23. super();
  24. this.appContainer = appContainer;
  25. this.appContainer.registerContainer(this);
  26. this.state = {};
  27. const mainContent = document.querySelector('#content-main');
  28. if (mainContent == null) {
  29. logger.debug('#content-main element is not exists');
  30. return;
  31. }
  32. const revisionId = mainContent.getAttribute('data-page-revision-id');
  33. const path = decodeURI(mainContent.getAttribute('data-path'));
  34. this.state = {
  35. // local page data
  36. markdown: null, // will be initialized after initStateMarkdown()
  37. pageId: mainContent.getAttribute('data-page-id'),
  38. revisionId,
  39. revisionCreatedAt: +mainContent.getAttribute('data-page-revision-created'),
  40. path,
  41. tocHtml: '',
  42. isBookmarked: false,
  43. sumOfBookmarks: 0,
  44. seenUsers: [],
  45. seenUserIds: [],
  46. sumOfSeenUsers: [],
  47. isLiked: false,
  48. likers: [],
  49. likerIds: [],
  50. sumOfLikers: 0,
  51. createdAt: mainContent.getAttribute('data-page-created-at'),
  52. // please use useCurrentUpdatedAt instead
  53. updatedAt: mainContent.getAttribute('data-page-updated-at'),
  54. deletedAt: mainContent.getAttribute('data-page-deleted-at') || null,
  55. isUserPage: JSON.parse(mainContent.getAttribute('data-page-user')) != null,
  56. isTrashPage: isTrashPage(path),
  57. isDeleted: JSON.parse(mainContent.getAttribute('data-page-is-deleted')),
  58. isDeletable: JSON.parse(mainContent.getAttribute('data-page-is-deletable')),
  59. isNotCreatable: JSON.parse(mainContent.getAttribute('data-page-is-not-creatable')),
  60. isAbleToDeleteCompletely: JSON.parse(mainContent.getAttribute('data-page-is-able-to-delete-completely')),
  61. isPageExist: mainContent.getAttribute('data-page-id') != null,
  62. pageUser: JSON.parse(mainContent.getAttribute('data-page-user')),
  63. tags: null,
  64. hasChildren: JSON.parse(mainContent.getAttribute('data-page-has-children')),
  65. templateTagData: mainContent.getAttribute('data-template-tags') || null,
  66. shareLinksNumber: mainContent.getAttribute('data-share-links-number'),
  67. shareLinkId: JSON.parse(mainContent.getAttribute('data-share-link-id') || null),
  68. // latest(on remote) information
  69. remoteRevisionId: revisionId,
  70. remoteRevisionBody: null,
  71. remoteRevisionUpdateAt: null,
  72. revisionIdHackmdSynced: mainContent.getAttribute('data-page-revision-id-hackmd-synced') || null,
  73. lastUpdateUsername: mainContent.getAttribute('data-page-last-update-username') || null,
  74. deleteUsername: mainContent.getAttribute('data-page-delete-username') || null,
  75. pageIdOnHackmd: mainContent.getAttribute('data-page-id-on-hackmd') || null,
  76. hasDraftOnHackmd: !!mainContent.getAttribute('data-page-has-draft-on-hackmd'),
  77. isHackmdDraftUpdatingInRealtime: false,
  78. isConflictDiffModalOpen: false,
  79. };
  80. // parse creator, lastUpdateUser and revisionAuthor
  81. try {
  82. this.state.creator = JSON.parse(mainContent.getAttribute('data-page-creator'));
  83. }
  84. catch (e) {
  85. logger.warn('The data of \'data-page-creator\' is invalid', e);
  86. }
  87. try {
  88. this.state.revisionAuthor = JSON.parse(mainContent.getAttribute('data-page-revision-author'));
  89. this.state.lastUpdateUser = JSON.parse(mainContent.getAttribute('data-page-revision-author'));
  90. }
  91. catch (e) {
  92. logger.warn('The data of \'data-page-revision-author\' is invalid', e);
  93. }
  94. const { interceptorManager } = this.appContainer;
  95. interceptorManager.addInterceptor(new DetachCodeBlockInterceptor(appContainer), 10); // process as soon as possible
  96. interceptorManager.addInterceptor(new DrawioInterceptor(appContainer), 20);
  97. interceptorManager.addInterceptor(new RestoreCodeBlockInterceptor(appContainer), 900); // process as late as possible
  98. this.initStateMarkdown();
  99. this.checkAndUpdateImageUrlCached(this.state.likers);
  100. const { isSharedUser } = this.appContainer;
  101. // see https://dev.growi.org/5fabddf8bbeb1a0048bcb9e9
  102. const isAbleToGetAttachedInformationAboutPages = this.state.isPageExist && !isSharedUser;
  103. if (isAbleToGetAttachedInformationAboutPages) {
  104. // We don't retrieve bookmarks in the initial page load
  105. // as it is stored in a separate collection to like and seen user
  106. // data so it has a separate api endpoint.
  107. this.initialPageLoad();
  108. this.retrieveBookmarkInfo();
  109. }
  110. this.setTocHtml = this.setTocHtml.bind(this);
  111. this.save = this.save.bind(this);
  112. this.checkAndUpdateImageUrlCached = this.checkAndUpdateImageUrlCached.bind(this);
  113. this.emitJoinPageRoomRequest = this.emitJoinPageRoomRequest.bind(this);
  114. this.emitJoinPageRoomRequest();
  115. this.addWebSocketEventHandlers = this.addWebSocketEventHandlers.bind(this);
  116. this.addWebSocketEventHandlers();
  117. const unlinkPageButton = document.getElementById('unlink-page-button');
  118. if (unlinkPageButton != null) {
  119. unlinkPageButton.addEventListener('click', async() => {
  120. try {
  121. const res = await this.appContainer.apiPost('/pages.unlink', { path });
  122. window.location.href = encodeURI(`${res.path}?unlinked=true`);
  123. }
  124. catch (err) {
  125. toastError(err);
  126. }
  127. });
  128. }
  129. }
  130. /**
  131. * Workaround for the mangling in production build to break constructor.name
  132. */
  133. static getClassName() {
  134. return 'PageContainer';
  135. }
  136. /**
  137. * whether to display reaction buttons
  138. * ex.) like, bookmark
  139. */
  140. get isAbleToShowPageReactionButtons() {
  141. const { isTrashPage, isPageExist } = this.state;
  142. const { isSharedUser } = this.appContainer;
  143. return (!isTrashPage && isPageExist && !isSharedUser);
  144. }
  145. /**
  146. * whether to display tag labels
  147. */
  148. get isAbleToShowTagLabel() {
  149. const { isUserPage } = this.state;
  150. const { isSharedUser } = this.appContainer;
  151. return (!isUserPage && !isSharedUser);
  152. }
  153. /**
  154. * whether to display page management
  155. * ex.) duplicate, rename
  156. */
  157. get isAbleToShowPageManagement() {
  158. const { isPageExist, isTrashPage } = this.state;
  159. const { isSharedUser } = this.appContainer;
  160. return (isPageExist && !isTrashPage && !isSharedUser);
  161. }
  162. /**
  163. * whether to display pageEditorModeManager
  164. * ex.) view, edit, hackmd
  165. */
  166. get isAbleToShowPageEditorModeManager() {
  167. const { isNotCreatable, isTrashPage } = this.state;
  168. const { isSharedUser } = this.appContainer;
  169. return (!isNotCreatable && !isTrashPage && !isSharedUser);
  170. }
  171. /**
  172. * whether to display pageAuthors
  173. * ex.) creator, lastUpdateUser
  174. */
  175. get isAbleToShowPageAuthors() {
  176. const { isPageExist, isUserPage } = this.state;
  177. return (isPageExist && !isUserPage);
  178. }
  179. /**
  180. * whether to like button
  181. * not displayed on user page
  182. */
  183. get isAbleToShowLikeButtons() {
  184. const { isUserPage } = this.state;
  185. const { isSharedUser } = this.appContainer;
  186. return (!isUserPage && !isSharedUser);
  187. }
  188. /**
  189. * whether to Empty Trash Page
  190. * not displayed when guest user and not on trash page
  191. */
  192. get isAbleToShowEmptyTrashButton() {
  193. const { currentUser } = this.appContainer;
  194. const { path, hasChildren } = this.state;
  195. return (currentUser != null && currentUser.admin && path === '/trash' && hasChildren);
  196. }
  197. /**
  198. * whether to display trash management buttons
  199. * ex.) undo, delete completly
  200. * not displayed when guest user
  201. */
  202. get isAbleToShowTrashPageManagementButtons() {
  203. const { currentUser } = this.appContainer;
  204. const { isDeleted } = this.state;
  205. return (isDeleted && currentUser != null);
  206. }
  207. /**
  208. * initialize state for markdown data
  209. */
  210. initStateMarkdown() {
  211. let pageContent = '';
  212. const rawText = document.getElementById('raw-text-original');
  213. if (rawText) {
  214. pageContent = rawText.innerHTML;
  215. }
  216. const markdown = entities.decodeHTML(pageContent);
  217. this.state.markdown = markdown;
  218. }
  219. async initialPageLoad() {
  220. {
  221. const {
  222. data: {
  223. likerIds, sumOfLikers, isLiked, seenUserIds, sumOfSeenUsers, isSeen,
  224. },
  225. } = await this.appContainer.apiv3Get('/page/info', { pageId: this.state.pageId });
  226. await this.setState({
  227. sumOfLikers,
  228. isLiked,
  229. likerIds,
  230. seenUserIds,
  231. sumOfSeenUsers,
  232. isSeen,
  233. });
  234. }
  235. await this.retrieveLikersAndSeenUsers();
  236. }
  237. async toggleLike() {
  238. {
  239. const toggledIsLiked = !this.state.isLiked;
  240. await this.appContainer.apiv3Put('/page/likes', { pageId: this.state.pageId, bool: toggledIsLiked });
  241. await this.setState(state => ({
  242. isLiked: toggledIsLiked,
  243. sumOfLikers: toggledIsLiked ? state.sumOfLikers + 1 : state.sumOfLikers - 1,
  244. likerIds: toggledIsLiked
  245. ? [...this.state.likerIds, this.appContainer.currentUserId]
  246. : state.likerIds.filter(id => id !== this.appContainer.currentUserId),
  247. }));
  248. }
  249. await this.retrieveLikersAndSeenUsers();
  250. }
  251. async retrieveLikersAndSeenUsers() {
  252. const { users } = await this.appContainer.apiGet('/users.list', { user_ids: [...this.state.likerIds, ...this.state.seenUserIds].join(',') });
  253. await this.setState({
  254. likers: users.filter(({ id }) => this.state.likerIds.includes(id)).slice(0, 15),
  255. seenUsers: users.filter(({ id }) => this.state.seenUserIds.includes(id)).slice(0, 15),
  256. });
  257. this.checkAndUpdateImageUrlCached(users);
  258. }
  259. async retrieveBookmarkInfo() {
  260. const response = await this.appContainer.apiv3Get('/bookmarks/info', { pageId: this.state.pageId });
  261. this.setState({
  262. sumOfBookmarks: response.data.sumOfBookmarks,
  263. isBookmarked: response.data.isBookmarked,
  264. });
  265. }
  266. async toggleBookmark() {
  267. const bool = !this.state.isBookmarked;
  268. await this.appContainer.apiv3Put('/bookmarks', { pageId: this.state.pageId, bool });
  269. return this.retrieveBookmarkInfo();
  270. }
  271. async checkAndUpdateImageUrlCached(users) {
  272. const noImageCacheUsers = users.filter((user) => { return user.imageUrlCached == null });
  273. if (noImageCacheUsers.length === 0) {
  274. return;
  275. }
  276. const noImageCacheUserIds = noImageCacheUsers.map((user) => { return user.id });
  277. try {
  278. await this.appContainer.apiv3Put('/users/update.imageUrlCache', { userIds: noImageCacheUserIds });
  279. }
  280. catch (err) {
  281. // Error alert doesn't apear, because user don't need to notice this error.
  282. logger.error(err);
  283. }
  284. }
  285. setLatestRemotePageData(s2cMessagePageUpdated) {
  286. const newState = {
  287. remoteRevisionId: s2cMessagePageUpdated.revisionId,
  288. remoteRevisionBody: s2cMessagePageUpdated.revisionBody,
  289. remoteRevisionUpdateAt: s2cMessagePageUpdated.revisionUpdateAt,
  290. revisionIdHackmdSynced: s2cMessagePageUpdated.revisionIdHackmdSynced,
  291. // TODO // TODO remove lastUpdateUsername and refactor parts that lastUpdateUsername is used
  292. lastUpdateUsername: s2cMessagePageUpdated.lastUpdateUsername,
  293. lastUpdateUser: s2cMessagePageUpdated.remoteLastUpdateUser,
  294. };
  295. if (s2cMessagePageUpdated.hasDraftOnHackmd != null) {
  296. newState.hasDraftOnHackmd = s2cMessagePageUpdated.hasDraftOnHackmd;
  297. }
  298. this.setState(newState);
  299. }
  300. setTocHtml(tocHtml) {
  301. if (this.state.tocHtml !== tocHtml) {
  302. this.setState({ tocHtml });
  303. }
  304. }
  305. /**
  306. * save success handler
  307. * @param {object} page Page instance
  308. * @param {Array[Tag]} tags Array of Tag
  309. * @param {object} revision Revision instance
  310. */
  311. updateStateAfterSave(page, tags, revision, editorMode) {
  312. // update state of PageContainer
  313. const newState = {
  314. pageId: page._id,
  315. revisionId: revision._id,
  316. revisionCreatedAt: new Date(revision.createdAt).getTime() / 1000,
  317. remoteRevisionId: revision._id,
  318. revisionAuthor: revision.author,
  319. revisionIdHackmdSynced: page.revisionHackmdSynced,
  320. hasDraftOnHackmd: page.hasDraftOnHackmd,
  321. markdown: revision.body,
  322. createdAt: page.createdAt,
  323. updatedAt: page.updatedAt,
  324. };
  325. if (tags != null) {
  326. newState.tags = tags;
  327. }
  328. this.setState(newState);
  329. // PageEditor component
  330. const pageEditor = this.appContainer.getComponentInstance('PageEditor');
  331. if (pageEditor != null) {
  332. if (editorMode !== 'edit') {
  333. pageEditor.updateEditorValue(newState.markdown);
  334. }
  335. }
  336. // PageEditorByHackmd component
  337. const pageEditorByHackmd = this.appContainer.getComponentInstance('PageEditorByHackmd');
  338. if (pageEditorByHackmd != null) {
  339. // reset
  340. if (editorMode !== 'hackmd') {
  341. pageEditorByHackmd.reset();
  342. }
  343. }
  344. }
  345. /**
  346. * update page meta data
  347. * @param {object} page Page instance
  348. * @param {object} revision Revision instance
  349. * @param {String[]} tags Array of Tag
  350. */
  351. updatePageMetaData(page, revision, tags) {
  352. const newState = {
  353. revisionId: revision._id,
  354. revisionCreatedAt: new Date(revision.createdAt).getTime() / 1000,
  355. remoteRevisionId: revision._id,
  356. revisionAuthor: revision.author,
  357. revisionIdHackmdSynced: page.revisionHackmdSynced,
  358. hasDraftOnHackmd: page.hasDraftOnHackmd,
  359. updatedAt: page.updatedAt,
  360. };
  361. if (tags != null) {
  362. newState.tags = tags;
  363. }
  364. this.setState(newState);
  365. }
  366. /**
  367. * Save page
  368. * @param {string} markdown
  369. * @param {object} optionsToSave
  370. * @return {object} { page: Page, tags: Tag[] }
  371. */
  372. async save(markdown, editorMode, optionsToSave = {}) {
  373. const { pageId, path } = this.state;
  374. let { revisionId } = this.state;
  375. const options = Object.assign({}, optionsToSave);
  376. if (editorMode === 'hackmd') {
  377. // set option to sync
  378. options.isSyncRevisionToHackmd = true;
  379. revisionId = this.state.revisionIdHackmdSynced;
  380. }
  381. let res;
  382. if (pageId == null) {
  383. res = await this.createPage(path, markdown, options);
  384. }
  385. else {
  386. res = await this.updatePage(pageId, revisionId, markdown, options);
  387. }
  388. this.updateStateAfterSave(res.page, res.tags, res.revision, editorMode);
  389. return res;
  390. }
  391. async saveAndReload(optionsToSave, editorMode) {
  392. if (optionsToSave == null) {
  393. const msg = '\'saveAndReload\' requires the \'optionsToSave\' param';
  394. throw new Error(msg);
  395. }
  396. if (editorMode == null) {
  397. logger.warn('\'saveAndReload\' requires the \'editorMode\' param');
  398. return;
  399. }
  400. const { pageId, path } = this.state;
  401. let { revisionId } = this.state;
  402. const options = Object.assign({}, optionsToSave);
  403. let markdown;
  404. if (editorMode === 'hackmd') {
  405. const pageEditorByHackmd = this.appContainer.getComponentInstance('PageEditorByHackmd');
  406. markdown = await pageEditorByHackmd.getMarkdown();
  407. // set option to sync
  408. options.isSyncRevisionToHackmd = true;
  409. revisionId = this.state.revisionIdHackmdSynced;
  410. }
  411. else {
  412. const pageEditor = this.appContainer.getComponentInstance('PageEditor');
  413. markdown = pageEditor.getMarkdown();
  414. }
  415. let res;
  416. if (pageId == null) {
  417. res = await this.createPage(path, markdown, options);
  418. }
  419. else {
  420. res = await this.updatePage(pageId, revisionId, markdown, options);
  421. }
  422. const editorContainer = this.appContainer.getContainer('EditorContainer');
  423. editorContainer.clearDraft(path);
  424. window.location.href = path;
  425. return res;
  426. }
  427. async createPage(pagePath, markdown, tmpParams) {
  428. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  429. // clone
  430. const params = Object.assign(tmpParams, {
  431. path: pagePath,
  432. body: markdown,
  433. });
  434. const res = await this.appContainer.apiv3Post('/pages/', params);
  435. const { page, tags, revision } = res.data;
  436. return { page, tags, revision };
  437. }
  438. async updatePage(pageId, revisionId, markdown, tmpParams) {
  439. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  440. // clone
  441. const params = Object.assign(tmpParams, {
  442. page_id: pageId,
  443. revision_id: revisionId,
  444. body: markdown,
  445. });
  446. const res = await this.appContainer.apiPost('/pages.update', params);
  447. if (!res.ok) {
  448. throw new Error(res.error);
  449. }
  450. return res;
  451. }
  452. deletePage(isRecursively, isCompletely) {
  453. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  454. // control flag
  455. const completely = isCompletely ? true : null;
  456. const recursively = isRecursively ? true : null;
  457. return this.appContainer.apiPost('/pages.remove', {
  458. recursively,
  459. completely,
  460. page_id: this.state.pageId,
  461. revision_id: this.state.revisionId,
  462. });
  463. }
  464. revertRemove(isRecursively) {
  465. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  466. // control flag
  467. const recursively = isRecursively ? true : null;
  468. return this.appContainer.apiPost('/pages.revertRemove', {
  469. recursively,
  470. page_id: this.state.pageId,
  471. });
  472. }
  473. rename(newPagePath, isRecursively, isRenameRedirect, isRemainMetadata) {
  474. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  475. const { pageId, revisionId, path } = this.state;
  476. return this.appContainer.apiv3Put('/pages/rename', {
  477. revisionId,
  478. pageId,
  479. isRecursively,
  480. isRenameRedirect,
  481. isRemainMetadata,
  482. newPagePath,
  483. path,
  484. });
  485. }
  486. showSuccessToastr() {
  487. toastr.success(undefined, 'Saved successfully', {
  488. closeButton: true,
  489. progressBar: true,
  490. newestOnTop: false,
  491. showDuration: '100',
  492. hideDuration: '100',
  493. timeOut: '1200',
  494. extendedTimeOut: '150',
  495. });
  496. }
  497. showErrorToastr(error) {
  498. toastr.error(error.message, 'Error occured', {
  499. closeButton: true,
  500. progressBar: true,
  501. newestOnTop: false,
  502. showDuration: '100',
  503. hideDuration: '100',
  504. timeOut: '3000',
  505. });
  506. }
  507. // request to server so the client to join a room for each page
  508. emitJoinPageRoomRequest() {
  509. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  510. const socket = socketIoContainer.getSocket();
  511. socket.emit('join:page', { socketId: socket.id, pageId: this.state.pageId });
  512. }
  513. addWebSocketEventHandlers() {
  514. // eslint-disable-next-line @typescript-eslint/no-this-alias
  515. const pageContainer = this;
  516. const socketIoContainer = this.appContainer.getContainer('SocketIoContainer');
  517. const socket = socketIoContainer.getSocket();
  518. socket.on('page:create', (data) => {
  519. logger.debug({ obj: data }, `websocket on 'page:create'`); // eslint-disable-line quotes
  520. // update remote page data
  521. const { s2cMessagePageUpdated } = data;
  522. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  523. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  524. }
  525. });
  526. socket.on('page:update', (data) => {
  527. logger.debug({ obj: data }, `websocket on 'page:update'`); // eslint-disable-line quotes
  528. // update remote page data
  529. const { s2cMessagePageUpdated } = data;
  530. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  531. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  532. }
  533. });
  534. socket.on('page:delete', (data) => {
  535. logger.debug({ obj: data }, `websocket on 'page:delete'`); // eslint-disable-line quotes
  536. // update remote page data
  537. const { s2cMessagePageUpdated } = data;
  538. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  539. pageContainer.setLatestRemotePageData(s2cMessagePageUpdated);
  540. }
  541. });
  542. socket.on('page:editingWithHackmd', (data) => {
  543. logger.debug({ obj: data }, `websocket on 'page:editingWithHackmd'`); // eslint-disable-line quotes
  544. // update isHackmdDraftUpdatingInRealtime
  545. const { s2cMessagePageUpdated } = data;
  546. if (s2cMessagePageUpdated.pageId === pageContainer.state.pageId) {
  547. pageContainer.setState({ isHackmdDraftUpdatingInRealtime: true });
  548. }
  549. });
  550. }
  551. /* TODO GW-325 */
  552. retrieveMyBookmarkList() {
  553. }
  554. async resolveConflict(markdown, editorMode) {
  555. const { pageId, remoteRevisionId, path } = this.state;
  556. const editorContainer = this.appContainer.getContainer('EditorContainer');
  557. const options = editorContainer.getCurrentOptionsToSave();
  558. const optionsToSave = Object.assign({}, options);
  559. const res = await this.updatePage(pageId, remoteRevisionId, markdown, optionsToSave);
  560. editorContainer.clearDraft(path);
  561. this.updateStateAfterSave(res.page, res.tags, res.revision, editorMode);
  562. editorContainer.setState({ tags: res.tags });
  563. return res;
  564. }
  565. }