* 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(
|
||||
'CREATE TABLE IF NOT EXISTS user_message_status (' +
|
||||
' user_id INTEGER NOT NULL,' +
|
||||
|
|
|
@ -8,6 +8,7 @@ var theme = require('../core/theme.js');
|
|||
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
||||
var Message = require('../core/message.js');
|
||||
var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName;
|
||||
var updateMessageAreaLastReadId = require('../core/message_area.js').updateMessageAreaLastReadId;
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
|
@ -209,6 +210,10 @@ function FullScreenEditorModule(options) {
|
|||
this.setMessage = function(message) {
|
||||
self.message = message;
|
||||
|
||||
if(!self.message.isPrivate()) {
|
||||
updateMessageAreaLastReadId(self.client.user.userId, self.messageAreaName, self.message.messageId);
|
||||
}
|
||||
|
||||
if(self.isReady) {
|
||||
self.initHeaderViewMode();
|
||||
self.initFooterViewMode();
|
||||
|
@ -864,6 +869,8 @@ require('util').inherits(FullScreenEditorModule, MenuModule);
|
|||
|
||||
FullScreenEditorModule.prototype.enter = function(client) {
|
||||
FullScreenEditorModule.super_.prototype.enter.call(this, client);
|
||||
|
||||
|
||||
};
|
||||
|
||||
FullScreenEditorModule.prototype.mciReady = function(mciData, cb) {
|
||||
|
|
|
@ -54,6 +54,10 @@ function Message(options) {
|
|||
return true;
|
||||
};
|
||||
|
||||
this.isPrivate = function() {
|
||||
return this.areaName === Message.WellKnownAreaNames.Private ? true : false;
|
||||
};
|
||||
|
||||
this.getMessageTimestampString = function(ts) {
|
||||
ts = ts || new Date();
|
||||
return ts.toISOString();
|
||||
|
|
|
@ -15,6 +15,8 @@ exports.getMessageAreaByName = getMessageAreaByName;
|
|||
exports.changeMessageArea = changeMessageArea;
|
||||
exports.getMessageListForArea = getMessageListForArea;
|
||||
exports.gotoMsgAreaFSEModuleForMessage = gotoMsgAreaFSEModuleForMessage;
|
||||
exports.getMessageAreaLastReadId = getMessageAreaLastReadId;
|
||||
exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId;
|
||||
|
||||
function getAvailableMessageAreas(options) {
|
||||
// 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) {
|
||||
var msgListView = vc.getView(MciCodesIds.MsgList);
|
||||
|
||||
// :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 dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DDD';
|
||||
var newIndicator = self.menuConfig.config.newIndicator || '*';
|
||||
|
@ -138,7 +144,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
|||
from : mle.fromUserName,
|
||||
to : mle.toUserName,
|
||||
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