Newest messages first when listing msgs from Gopher

This commit is contained in:
Bryan Ashby 2018-11-21 17:55:31 -07:00
parent 3af5b6f509
commit ebc70907d4
2 changed files with 22 additions and 9 deletions

View File

@ -353,13 +353,19 @@ function getNewMessagesInAreaForUser(userId, areaTag, cb) {
}); });
} }
function getMessageListForArea(client, areaTag, cb) { function getMessageListForArea(client, areaTag, filter, cb)
const filter = { {
areaTag, if(!cb && _.isFunction(filter)) {
resultType : 'messageList', cb = filter;
sort : 'messageId', filter = {
order : 'ascending', areaTag,
}; resultType : 'messageList',
sort : 'messageId',
order : 'ascending'
};
} else {
Object.assign(filter, { areaTag } );
}
if(Message.isPrivateAreaTag(areaTag)) { if(Message.isPrivateAreaTag(areaTag)) {
filter.privateTagUserId = client.user.userId; filter.privateTagUserId = client.user.userId;

View File

@ -249,7 +249,7 @@ exports.getModule = class GopherModule extends ServerModule {
return message.load( { uuid : msgUuid }, err => { return message.load( { uuid : msgUuid }, err => {
if(err) { if(err) {
this.log.debug( { uuid : msgUuid }, 'Attempted access to non-existant message UUID!'); this.log.debug( { uuid : msgUuid }, 'Attempted access to non-existent message UUID!');
return this.notFoundGenerator(selectorMatch, cb); return this.notFoundGenerator(selectorMatch, cb);
} }
@ -292,10 +292,17 @@ ${msgBody}
return this.notFoundGenerator(selectorMatch, cb); return this.notFoundGenerator(selectorMatch, cb);
} }
return getMessageListForArea(null, areaTag, (err, msgList) => { const filter = {
resultType : 'messageList',
sort : 'messageId',
order : 'descending', // we want newest messages first for Gopher
};
return getMessageListForArea(null, areaTag, filter, (err, msgList) => {
const response = [ const response = [
this.makeItem(ItemTypes.InfoMessage, '-'.repeat(70)), this.makeItem(ItemTypes.InfoMessage, '-'.repeat(70)),
this.makeItem(ItemTypes.InfoMessage, `Messages in ${area.name}`), this.makeItem(ItemTypes.InfoMessage, `Messages in ${area.name}`),
this.makeItem(ItemTypes.InfoMessage, '(newest first)'),
this.makeItem(ItemTypes.InfoMessage, '-'.repeat(70)), this.makeItem(ItemTypes.InfoMessage, '-'.repeat(70)),
...msgList.map(msg => this.makeItem( ...msgList.map(msg => this.makeItem(
ItemTypes.TextFile, ItemTypes.TextFile,