* WIP on message last read - not fully functional yet
This commit is contained in:
parent
4988559569
commit
4a386d649e
|
@ -148,6 +148,15 @@ function createMessageBaseTables() {
|
||||||
');'
|
');'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dbs.message.run(
|
||||||
|
'CREATE TABLE IF NOT EXISTS user_message_area_last_read (' +
|
||||||
|
' user_id INTEGER NOT NULL,' +
|
||||||
|
' area_name VARCHAR NOT NULL,' +
|
||||||
|
' message_id INTEGER NOT NULL,' +
|
||||||
|
' UNIQUE(user_id, area_name)' +
|
||||||
|
');'
|
||||||
|
);
|
||||||
|
|
||||||
dbs.message.run(
|
dbs.message.run(
|
||||||
'CREATE TABLE IF NOT EXISTS user_message_status (' +
|
'CREATE TABLE IF NOT EXISTS user_message_status (' +
|
||||||
' user_id INTEGER NOT NULL,' +
|
' user_id INTEGER NOT NULL,' +
|
||||||
|
|
21
core/fse.js
21
core/fse.js
|
@ -1,13 +1,14 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var MenuModule = require('../core/menu_module.js').MenuModule;
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
var ViewController = require('../core/view_controller.js').ViewController;
|
var ViewController = require('../core/view_controller.js').ViewController;
|
||||||
var ansi = require('../core/ansi_term.js');
|
var ansi = require('../core/ansi_term.js');
|
||||||
var theme = require('../core/theme.js');
|
var theme = require('../core/theme.js');
|
||||||
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
||||||
var Message = require('../core/message.js');
|
var Message = require('../core/message.js');
|
||||||
var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName;
|
var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName;
|
||||||
|
var updateMessageAreaLastReadId = require('../core/message_area.js').updateMessageAreaLastReadId;
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
@ -209,6 +210,10 @@ function FullScreenEditorModule(options) {
|
||||||
this.setMessage = function(message) {
|
this.setMessage = function(message) {
|
||||||
self.message = message;
|
self.message = message;
|
||||||
|
|
||||||
|
if(!self.message.isPrivate()) {
|
||||||
|
updateMessageAreaLastReadId(self.client.user.userId, self.messageAreaName, self.message.messageId);
|
||||||
|
}
|
||||||
|
|
||||||
if(self.isReady) {
|
if(self.isReady) {
|
||||||
self.initHeaderViewMode();
|
self.initHeaderViewMode();
|
||||||
self.initFooterViewMode();
|
self.initFooterViewMode();
|
||||||
|
@ -864,6 +869,8 @@ require('util').inherits(FullScreenEditorModule, MenuModule);
|
||||||
|
|
||||||
FullScreenEditorModule.prototype.enter = function(client) {
|
FullScreenEditorModule.prototype.enter = function(client) {
|
||||||
FullScreenEditorModule.super_.prototype.enter.call(this, client);
|
FullScreenEditorModule.super_.prototype.enter.call(this, client);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FullScreenEditorModule.prototype.mciReady = function(mciData, cb) {
|
FullScreenEditorModule.prototype.mciReady = function(mciData, cb) {
|
||||||
|
|
|
@ -54,6 +54,10 @@ function Message(options) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.isPrivate = function() {
|
||||||
|
return this.areaName === Message.WellKnownAreaNames.Private ? true : false;
|
||||||
|
};
|
||||||
|
|
||||||
this.getMessageTimestampString = function(ts) {
|
this.getMessageTimestampString = function(ts) {
|
||||||
ts = ts || new Date();
|
ts = ts || new Date();
|
||||||
return ts.toISOString();
|
return ts.toISOString();
|
||||||
|
|
|
@ -15,6 +15,8 @@ exports.getMessageAreaByName = getMessageAreaByName;
|
||||||
exports.changeMessageArea = changeMessageArea;
|
exports.changeMessageArea = changeMessageArea;
|
||||||
exports.getMessageListForArea = getMessageListForArea;
|
exports.getMessageListForArea = getMessageListForArea;
|
||||||
exports.gotoMsgAreaFSEModuleForMessage = gotoMsgAreaFSEModuleForMessage;
|
exports.gotoMsgAreaFSEModuleForMessage = gotoMsgAreaFSEModuleForMessage;
|
||||||
|
exports.getMessageAreaLastReadId = getMessageAreaLastReadId;
|
||||||
|
exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId;
|
||||||
|
|
||||||
function getAvailableMessageAreas(options) {
|
function getAvailableMessageAreas(options) {
|
||||||
// example: [ { "name" : "local_music", "desc" : "Music Discussion", "groups" : ["somegroup"] }, ... ]
|
// example: [ { "name" : "local_music", "desc" : "Music Discussion", "groups" : ["somegroup"] }, ... ]
|
||||||
|
@ -183,3 +185,36 @@ function gotoMsgAreaFSEModuleForMessage(options, cb) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMessageAreaLastReadId(userId, areaName, cb) {
|
||||||
|
msgDb.get(
|
||||||
|
'SELECT message_id ' +
|
||||||
|
'FROM user_message_area_last_read ' +
|
||||||
|
'WHERE user_id = ? AND area_name = ?;',
|
||||||
|
[ userId, areaName ],
|
||||||
|
cb // (err, lastId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMessageAreaLastReadId(userId, areaName, messageId) {
|
||||||
|
// :TODO: likely a better way to do this...
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function getCurrent(callback) {
|
||||||
|
getMessageAreaLastReadId(userId, areaName, function result(err, lastId) {
|
||||||
|
lastId = lastId || 0;
|
||||||
|
callback(null, lastId); // ignore errors as we default to 0
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function update(lastId, callback) {
|
||||||
|
if(messageId > lastId) {
|
||||||
|
msgDb.run(
|
||||||
|
'REPLACE INTO user_message_area_last_read (user_id, area_name, message_id) ' +
|
||||||
|
'VALUES (?, ?, ?);',
|
||||||
|
[ userId, areaName, messageId ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -120,11 +120,17 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
function getLastReadMesageId(callback) {
|
||||||
|
messageArea.getMessageAreaLastReadId(self.client.user.userId, self.messageAreaName, function lastRead(err, lastReadId) {
|
||||||
|
self.lastReadId = lastReadId || 0;
|
||||||
|
callback(null); // ignore any errors, e.g. missing value
|
||||||
|
});
|
||||||
|
},
|
||||||
function populateList(callback) {
|
function populateList(callback) {
|
||||||
var msgListView = vc.getView(MciCodesIds.MsgList);
|
var msgListView = vc.getView(MciCodesIds.MsgList);
|
||||||
|
|
||||||
// :TODO: fix default format
|
// :TODO: fix default format
|
||||||
var listFormat = self.menuConfig.config.listFormat || '{msgNum} - {subj} |{to}';
|
var listFormat = self.menuConfig.config.listFormat || '{msgNum} - {subj} - {to}';
|
||||||
var focusListFormat = self.menuConfig.config.focusListFormat || listFormat; // :TODO: default change color here
|
var focusListFormat = self.menuConfig.config.focusListFormat || listFormat; // :TODO: default change color here
|
||||||
var dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DDD';
|
var dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DDD';
|
||||||
var newIndicator = self.menuConfig.config.newIndicator || '*';
|
var newIndicator = self.menuConfig.config.newIndicator || '*';
|
||||||
|
@ -138,7 +144,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
||||||
from : mle.fromUserName,
|
from : mle.fromUserName,
|
||||||
to : mle.toUserName,
|
to : mle.toUserName,
|
||||||
ts : moment(mle.modTimestamp).format(dateTimeFormat),
|
ts : moment(mle.modTimestamp).format(dateTimeFormat),
|
||||||
newIndicator : newIndicator, // :TODO: These should only be for actual new messages!
|
newIndicator : mle.messageId > self.lastReadId ? newIndicator : '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue