make persisting a message after sending it work with the new architecture

--HG--
extra : rebase_source : f36a265b89148051596e1ec80603c1944173efc8
This commit is contained in:
Myk Melez 2009-05-22 16:57:15 -07:00
Родитель 85ca2da857
Коммит 13837c96fb
3 изменённых файлов: 8 добавлений и 41 удалений

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

@ -42,6 +42,7 @@ const Cr = Components.results;
const Cu = Components.utils;
// modules that are generic
Cu.import("resource://snowl/modules/Observers.js");
Cu.import("resource://snowl/modules/URI.js");
// modules that are Snowl-specific
@ -238,6 +239,9 @@ SnowlMessage.prototype = {
if (this.summary)
this.summary.persist(this);
if (added)
Observers.notify("snowl:message:added", this);
return added;
},

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

@ -417,7 +417,6 @@ this._log.info("persist placeID:sources.id - " + this.placeID + " : " + this.id)
if (messagesChanged == false && added)
messagesChanged = true;
currentMessageIDs.push(message.id);
Observers.notify("snowl:message:added", message);
// Sleep for a bit to give other sources that are being refreshed
// at the same time the opportunity to insert messages themselves,

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

@ -485,7 +485,7 @@ SnowlTwitter.prototype = {
message.sourceID = this.id;
message.externalID = item.id;
message.timestamp = new Date(item.created_at);
message.received = received;
message.received = received || new Date();
message.author = new SnowlIdentity(null, this.id, item.user.id);
message.author.person = new SnowlPerson(null, item.user.screen_name, null, item.user.url, item.user.profile_image_url);
@ -499,43 +499,6 @@ SnowlTwitter.prototype = {
return message;
},
_addMessage: function(message, aReceived) {
let messageID;
SnowlDatastore.dbConnection.beginTransaction();
try {
// Get an existing identity or create a new one. Creating an identity
// automatically creates a person record with the provided name.
let identity = SnowlIdentity.get(this.id, message.user.id) ||
SnowlIdentity.create(this.id,
message.user.id,
message.user.screen_name,
message.user.url,
message.user.profile_image_url);
// FIXME: update the identity record with the latest info about the person.
//identity.updateProperties(this.machineURI, message.user);
let authorID = identity.personID;
// Add the message.
messageID = this.addSimpleMessage(this.id, message.id, null, authorID,
new Date(message.created_at), aReceived,
null);
// Add the message's content.
this.addPart(messageID, message.text, "text/plain");
SnowlDatastore.dbConnection.commitTransaction();
}
catch(ex) {
SnowlDatastore.dbConnection.rollbackTransaction();
this._log.error("couldn't add " + message.id + ": " + ex);
}
Observers.notify("snowl:message:added", SnowlMessage.retrieve(messageID));
return messageID;
},
// XXX Perhaps factor this out with the identical function in feed.js,
// although this function supports multiple accounts with the same server
// and doesn't allow the user to change their username, so maybe that's
@ -660,8 +623,9 @@ SnowlTwitter.prototype = {
_processSend: function(responseText) {
let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
let message = JSON.decode(responseText);
this._addMessage(message, new Date());
let item = JSON.decode(responseText);
let message = this._processItem(item);
message.persist();
},
_resetSend: function() {