Skip to content

Commit

Permalink
don't detect own edits as edit conflict (#355)
Browse files Browse the repository at this point in the history
* don't detect own edits as edit conflict

fixes #353

* fix

* fix

* comments, variable names

* refactor
  • Loading branch information
NovemLinguae committed May 4, 2024
1 parent e513900 commit 1bb0b91
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2686,26 +2686,38 @@
}

function checkForEditConflict() {
// Get all revisions since the page was loaded, starting with the revision of the loaded page
var request = {
// Get timestamp of the revision currently loaded in the browser
return AFCH.api.get( {
action: 'query',
format: 'json',
prop: 'revisions',
titles: [ mw.config.get( 'wgPageName' ) ],
formatversion: 2,
rvstartid: mw.config.get( 'wgRevisionId' ),
rvdir: 'newer'
};
var promise = AFCH.api.postWithEditToken( request )
.then( function ( data ) {
var revisions = data.query.pages[ 0 ].revisions;
// 1 revision = no edit conflict, 2+ revisions = edit conflict.
if ( revisions && revisions.length > 1 ) {
revids: mw.config.get( 'wgCurRevisionId' ),
formatversion: 2
} ).then( function ( data ) {
// convert timestamp format from 2024-05-03T09:40:20Z to 1714729221
var currentRevisionTimestampTZ = data.query.pages[ 0 ].revisions[ 0 ].timestamp;
var currentRevisionSeconds = ( new Date( currentRevisionTimestampTZ ).getTime() ) / 1000;

// add one second. we don't want the current revision to be in our list of revisions
currentRevisionSeconds++;

// Then get all revisions since that timestamp
return AFCH.api.get( {
action: 'query',
format: 'json',
prop: 'revisions',
titles: [ mw.config.get( 'wgPageName' ) ],
formatversion: 2,
rvstart: currentRevisionSeconds,
rvdir: 'newer'
} ).then( function ( data ) {
var revisionsSinceTimestamp = data.query.pages[ 0 ].revisions;
if ( revisionsSinceTimestamp && revisionsSinceTimestamp.length > 0 ) {
return true;
}
return false;
} );
return promise;
} );
}

function showEditConflictMessage() {
Expand Down

0 comments on commit 1bb0b91

Please sign in to comment.