Bug 1877390 - Rework sortController.convertSortTypeToColumnID() to sortControler.getCurrentSortColumnId(). r=freaktechnik

The function convertSortTypeToColumnID() uses dbView.curCustomColumn to
convert the "byCustom" sort type to a columnID. This however only works
for the current custom sort column, and not for any custom column. It is
also only used with the primarySortType (and not with any sort type) as
input.

To improve readability of this code, this patch reworks this function to
always return to columnID of the current sort column.

Differential Revision: https://phabricator.services.mozilla.com/D200212

--HG--
extra : rebase_source : 219d43da8faa064fdd95bc14388c1bc185aceb23
This commit is contained in:
John Bieling 2024-03-27 09:06:08 +02:00
Родитель 0ee16d11de
Коммит ff677d05c9
1 изменённых файлов: 16 добавлений и 24 удалений

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

@ -4775,9 +4775,7 @@ var threadPane = {
if (!gDBView) {
return;
}
this.updateSortIndicator(
sortController.convertSortTypeToColumnID(gViewWrapper.primarySortType)
);
this.updateSortIndicator(sortController.getCurrentSortColumnId());
},
/**
@ -5081,9 +5079,7 @@ var threadPane = {
* @param {object} data - The detail of the custom event.
*/
onSortChanged(data) {
const curSortColumnId = sortController.convertSortTypeToColumnID(
gViewWrapper.primarySortType
);
const curSortColumnId = sortController.getCurrentSortColumnId();
const newSortColumnId = data.column;
// A click happened on the column that is already used to sort the list.
@ -6212,13 +6208,10 @@ var sortController = {
threadPane.ensureThreadStateForQuickSearchView();
threadTree.style.scrollBehavior = null;
},
convertSortTypeToColumnID(sortKey) {
getCurrentSortColumnId() {
const sortKey = gViewWrapper.primarySortType;
let columnID;
// Hack to turn this into an integer, if it was a string.
// It would be a string if it came from XULStore.json.
sortKey = sortKey - 0;
switch (sortKey) {
// In the case of None, we default to the date column. This appears to be
// the case in such instances as Global search, so don't complain about
@ -6276,20 +6269,19 @@ var sortController = {
columnID = "attachmentCol";
break;
case Ci.nsMsgViewSortType.byCustom:
// TODO: either change try() catch to if (property exists) or restore
// the ThreadPaneColumns.getColumnHandler() check.
try {
// ThreadPaneColumns.getColumnHandler throws an error when the ID is not handled
columnID = gDBView.curCustomColumn;
} catch (e) {
// error - means no handler
{
const curCustomColumn = gDBView.curCustomColumn;
if (threadPane.columns.some(c => c.id == curCustomColumn)) {
columnID = curCustomColumn;
} else {
dump(
"ConvertSortTypeToColumnID: custom sort key but no handler for column '" +
"getCurrentSortColumnId: custom sort key but no handler for column '" +
columnID +
"'\n"
);
columnID = "dateCol";
}
}
break;
case Ci.nsMsgViewSortType.byCorrespondent:
columnID = "correspondentCol";