Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't detect own edits as edit conflict #355

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2687,26 +2687,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
Loading