Debian Codegraph @

extensions/VisualEditor/lib/ve/rebaser/src/dm/ve.dm.RebaseDocState.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel rebase document state class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 'use strict';
8
9 /**
10 * DataModel rebase document state
11 *
12 * @class
13 *
14 * @constructor
15 */
16 ve.dm.RebaseDocState = function VeDmRebaseDocState() {
17 /**
18 * @property {ve.dm.Change} history History as one big change
19 */
20 this.history = new ve.dm.Change();
21
22 /**
23 * @property {Map.<number, Object>} authors Information about each author
24 */
25 this.authors = new Map();
26 };
27
28 /* Inheritance */
29
30 OO.initClass( ve.dm.RebaseDocState );
31
32 /* Static Methods */
33
34 /**
35 * @typedef {Object} AuthorData
36 * @memberof ve.dm.RebaseDocState
37 * @property {string} name
38 * @property {string} color
39 * @property {number} rejections Number of unacknowledged rejections
40 * @property {ve.dm.Change|null} continueBase Continue base
41 * @property {string} token Secret token for usurping sessions
42 * @property {boolean} active Whether the author is active
43 */
44
45 /**
46 * Get new empty author data object
47 *
48 * @return {ve.dm.RebaseDocState.AuthorData} New empty author data object
49 */
50 ve.dm.RebaseDocState.static.newAuthorData = function () {
51 return {
52 name: '',
53 color: '',
54 rejections: 0,
55 continueBase: null,
56 // TODO use cryptographic randomness here and convert to hex
57 token: Math.random().toString(),
58 active: true
59 };
60 };
61
62 /* Methods */
63
64 ve.dm.RebaseDocState.prototype.getActiveAuthors = function () {
65 const result = {};
66 this.authors.forEach( ( authorData, authorId ) => {
67 if ( authorData.active ) {
68 result[ authorId ] = {
69 name: authorData.name,
70 color: authorData.color
71 };
72 }
73 } );
74 return result;
75 };
76
77 ve.dm.RebaseDocState.prototype.clearHistory = function () {
78 this.history = new ve.dm.Change();
79 this.authors.forEach( ( authorData ) => {
80 authorData.continueBase = null;
81 } );
82 };