Bug 1794185 - Fix "Get Next n Messages" for nntp-js. r=mkmelin

Update nsIDBFolderInfo.knownArtsSet based on XOVER range, doesn't matter if artciles in the range don't exist on the server.

Differential Revision: https://phabricator.services.mozilla.com/D158898
This commit is contained in:
Ping Chen 2022-10-08 06:13:43 +00:00
Родитель 020870378f
Коммит aeedf87c96
5 изменённых файлов: 56 добавлений и 2 удалений

Просмотреть файл

@ -561,6 +561,7 @@ class NntpClient {
_actionXOverResponse(res) {
if (res.status == 224) {
this._nextAction = this._actionReadXOver;
this._newsGroup.addKnownArticles(this._startArticle, this._endArticle);
this._actionReadXOver(res);
} else {
// Somehow XOVER is not supported by the server, fallback to use HEAD to

Просмотреть файл

@ -152,7 +152,13 @@ class NntpNewsGroup {
msgHdr.messageSize = bytes;
msgHdr.lineCount = lines;
this._msgHdrs.push(msgHdr);
this._knownKeySet.add(articleNumber);
}
/**
* Add a range (usually XOVER range) to the known key set.
*/
addKnownArticles(start, end) {
this._knownKeySet.addRange(start, end);
}
/**

Просмотреть файл

@ -0,0 +1,42 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let daemon = setupNNTPDaemon();
let server = makeServer(NNTP_RFC2980_handler, daemon);
server.start();
registerCleanupFunction(() => {
server.stop();
});
let incomingServer = setupLocalServer(server.port);
/**
* Test nsIDBFolderInfo.knownArtsSet is correctly updated after XOVER response.
* knownArtsSet depends on the XOVER range requested, it doesn't matter if
* articles in that range don't exist on the server.
*/
add_task(function test_updateKnownKeySetAfterXOver() {
// setupNNTPDaemon inited test.filter with 8 messages, delete the 5th, 6th here.
daemon.removeArticleFromGroup("test.filter", 5);
daemon.removeArticleFromGroup("test.filter", 6);
// Trigger a get new messages request.
let prefix = "news://localhost:" + server.port + "/";
setupProtocolTest(server.port, prefix + "test.filter", incomingServer);
server.performTest();
let transaction = server.playTransaction();
// Test XOVER was sent correctly.
do_check_transaction(transaction, [
"MODE READER",
"GROUP test.filter",
"XOVER 1-8",
]);
// Test knownArtsSet was updated correctly.
let folder = incomingServer.rootFolder.getChildNamed("test.filter");
let groupInfo = folder.msgDatabase.dBFolderInfo;
// knownArtsSet should be "1-8", not "1-4,7-8".
equal(groupInfo.knownArtsSet, "1-8");
});

Просмотреть файл

@ -2,7 +2,6 @@
head = head_server_setup.js
tail =
support-files = postings/*
dupe-manifest =
[test_biff.js]
[test_bug37465.js]
@ -33,3 +32,4 @@ skip-if = true # realhostname and realuserName don't exist anymore
[test_server.js]
run-sequentially = Uses fixed NNTP_PORT
[test_uriParser.js]
[test_xover.js]

Просмотреть файл

@ -49,6 +49,11 @@ class NntpDaemon {
this._groups[group].nextKey = key + 1;
}
}
removeArticleFromGroup(groupName, key) {
let group = this._groups[groupName];
delete group[key];
group.keys = group.keys.filter(x => x != key);
}
getGroup(group) {
if (this._groups.hasOwnProperty(group)) {
return this._groups[group];