summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIzhar Firdaus <izhar@inigo-tech.com>2011-04-27 02:39:26 +0800
committerIzhar Firdaus <izhar@inigo-tech.com>2011-04-27 02:39:26 +0800
commit735f046b28d28bc4f54cf1076150163e929eeee2 (patch)
treeb2a163f043b6238ecf9a4d7bedaef199b8e3fb0d
parentdad53d605330cbf0485e209da29201420ab4cde1 (diff)
downloadhack-patches-735f046b28d28bc4f54cf1076150163e929eeee2.tar.gz
hack-patches-735f046b28d28bc4f54cf1076150163e929eeee2.tar.xz
hack-patches-735f046b28d28bc4f54cf1076150163e929eeee2.zip
gnomeshell-pidgin: use DisplayImMsg instead of ReceivedImMsg/SentImMsg
-rw-r--r--gnomeshell@pidgin.im/extension.js128
1 files changed, 35 insertions, 93 deletions
diff --git a/gnomeshell@pidgin.im/extension.js b/gnomeshell@pidgin.im/extension.js
index 398570e..19cede5 100644
--- a/gnomeshell@pidgin.im/extension.js
+++ b/gnomeshell@pidgin.im/extension.js
@@ -24,8 +24,6 @@ const TelepathyClient = imports.ui.telepathyClient;
const _ = Gettext.gettext;
-const DEBUG=true;
-
function wrappedText(text, sender, timestamp, direction) {
return {
messageType: Tp.ChannelTextMessageType.NORMAL,
@@ -54,31 +52,22 @@ PidginNotification.prototype = {
let messageBody = _fixText(message.text);
styles = styles || [];
styles.push(message.direction);
-
- if (message.messageType == Tp.ChannelTextMessageType.ACTION) {
- let senderAlias = GLib.markup_escape_text(message.sender, -1);
- messageBody = '<i>%s</i> %s'.format(senderAlias, messageBody);
- styles.push('chat-action');
- }
-
this.update(this.source.title, messageBody, { customContent: true, bannerMarkup: true });
this._append(messageBody, styles, message.timestamp, noTimestamp);
}
}
-function Source(client, conversation, initialMessage) {
- this._init(client, conversation, initialMessage);
+function Source(client, account, author, initialMessage, conversation, flag) {
+ this._init(client, account, author, initialMessage, conversation, flag);
}
Source.prototype = {
__proto__: MessageTray.Source.prototype,
- _init: function(client, conversation, initialMessage) {
+ _init: function(client, account, author, initialMessage, conversation, flag) {
let proxy = client.proxy();
- let account = proxy.PurpleConversationGetAccountSync(conversation);
- let author = proxy.PurpleConversationGetNameSync(conversation);
let author_buddy = proxy.PurpleFindBuddySync(account, author);
MessageTray.Source.prototype._init.call(this, author);
@@ -90,21 +79,11 @@ Source.prototype = {
this._account = account;
this._conversation = conversation;
this._initialMessage = initialMessage;
- this._iconUri = 'file:///usr/share/icons/hicolor/48x48/apps/pidgin.png'; // use this icon as default
+ this._iconUri = null;
this._presence = 'online';
-// this._notification = new TelepathyClient.Notification(this);
this._notification = new PidginNotification(this);
this._notification.setUrgency(MessageTray.Urgency.HIGH);
-
- if (!this._initialMessage) {
- let history = proxy.PurpleConversationGetMessageHistorySync(this._conversation);
- let messageobj = history[history.length - 1];
- if (messageobj) {
- this._initialMessage = proxy.PurpleConversationMessageGetMessageSync(messageobj);
- }
- };
-
let iconobj = proxy.PurpleBuddyGetIconSync(this._author_buddy);
if (iconobj) {
@@ -118,19 +97,22 @@ Source.prototype = {
this._setSummaryIcon(this.createNotificationIcon());
- if (this._initialMessage) {
- let message = wrappedText(this._initialMessage, this._author, null, TelepathyClient.NotificationDirection.RECEIVED);
- this._notification.appendMessage(message, false);
+ Main.messageTray.add(this);
+
+ let direction = null;
+ if (flag == 1) {
+ direction = TelepathyClient.NotificationDirection.SENT;
+ } else if (flag == 2) {
+ direction = TelepathyClient.NotificationDirection.RECEIVED;
}
- if (!Main.messageTray.contains(this))
- Main.messageTray.add(this);
+ let message = wrappedText(this._initialMessage, this._author, null, direction);
+ this._notification.appendMessage(message, false);
this._buddyStatusChangeId = proxy.connect('BuddyStatusChanged', Lang.bind(this, this._onBuddyStatusChange));
this._buddySignedOffId = proxy.connect('BuddySignedOff', Lang.bind(this, this._onBuddySignedOff));
this._deleteConversationId = proxy.connect('DeletingConversation', Lang.bind(this, this._onDeleteConversation));
- this._messageSentId = proxy.connect('SentImMsg', Lang.bind(this, this._onSentImMessage));
- this._messageReceivedId = proxy.connect('ReceivedImMsg', Lang.bind(this, this._onReceivedImMessage));
+ this._messageDisplayedId = proxy.connect('DisplayedImMsg', Lang.bind(this, this._onDisplayedImMessage));
this.notify(this._notification);
},
@@ -162,31 +144,14 @@ Source.prototype = {
},
open: function(notification) {
- // Lookup for the messages window and display it. In the case where it's not o
- // opened yet fallback to the roster window.
-
- /* disable this, it doesnt quite work correctly with default pidgin
- * config anyway
- let windows = global.get_window_actors();
- for (let i = 0; i < windows.length; i++) {
- let metaWindow = windows[i].metaWindow;
- if (metaWindow.get_wm_class_instance() == "pidgin" &&
- metaWindow.get_role() == "messages") {
- Main.activateWindow(metaWindow);
- return;
- }
- }*/
-
let app = Shell.AppSystem.get_default().get_app('pidgin.desktop');
app.activate_window(null, global.get_current_time());
},
-
notify: function () {
MessageTray.Source.prototype.notify.call(this, this._notification);
},
-
respond: function(text) {
let proxy = this._client.proxy();
let _text = GLib.markup_escape_text(text, -1);
@@ -201,7 +166,6 @@ Source.prototype = {
if (buddy != this._author_buddy) return;
// XXX: this looks wrong. should get string?
- let old_status = proxy.PurpleStatusGetIdSync(old_status_id);
let new_status = proxy.PurpleStatusGetIdSync(new_status_id);
if (this._presence == new_status) return;
@@ -209,7 +173,6 @@ Source.prototype = {
if (new_status == 'dnd') new_status = 'busy';
this._notification.appendPresence('<i>' + this.title + ' is now ' + new_status + '</i>', false);
-
},
_onBuddySignedOff: function(emitter, buddy) {
@@ -225,24 +188,23 @@ Source.prototype = {
},
- _onSentImMessage: function(emitter, account, author, text) {
-
- let proxy = this._client.proxy();
- let buddy = proxy.PurpleFindBuddySync(account, author);
-
- if (text && (buddy == this._author_buddy)) {
- let message = wrappedText(text, this._author, null, TelepathyClient.NotificationDirection.SENT);
- this._notification.appendMessage(message, false);
- }
-
- },
-
- _onReceivedImMessage: function(emitter, account, author, text, conversation) {
+ _onDisplayedImMessage: function(emitter, account, author, text, conversation, flag) {
if (text && (this._conversation == conversation)) {
- let message = wrappedText(text, this._author, null, TelepathyClient.NotificationDirection.RECEIVED);
- this._notification.appendMessage(message, false);
- this.notify(this._notification);
+ let direction = null;
+ if (flag == 1) {
+ direction = TelepathyClient.NotificationDirection.SENT;
+ } else if (flag == 2) {
+ direction = TelepathyClient.NotificationDirection.RECEIVED;
+ }
+ if (direction != null) {
+ let message = wrappedText(text, this._author, null, direction);
+ this._notification.appendMessage(message, false);
+ this.notify(this._notification);
+ } else {
+ this._notification.appendPresence(message, false)
+ }
+
}
}
@@ -276,6 +238,7 @@ const PidginIface = {
],
signals: [
{name: 'ReceivedImMsg', inSignature: 'issiu'},
+ {name: 'DisplayedImMsg', inSignature: 'issiu'},
{name: 'SentImMsg', inSignature: 'iss'},
{name: 'BuddyStatusChanged', inSignature: 'iii'}, // ????
{name: 'BuddySignedOff', inSignature: 'i'},
@@ -309,11 +272,6 @@ function patchSynchronousMethods(obj, iface) {
let name = method.name + 'Sync';
obj[name] = function () {
let arg_array = Array.prototype.slice.call(arguments);
- let logmsg = 'calling ' + method.name + ' with parameters ' + arg_array + ' arguments ' + arguments;
- if (DEBUG) {
- log(logmsg);
- global.log(logmsg);
- }
return obj._dbusBus.call(
obj._dbusBusName,
obj._dbusPath,
@@ -340,38 +298,22 @@ PidginClient.prototype = {
this._sources = {};
this._proxy = new Pidgin(DBus.session, 'im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject');
patchSynchronousMethods(this._proxy, PidginIface);
- this._proxy.connect('ReceivedImMsg', Lang.bind(this, this._messageReceived));
- this._proxy.connect('ConversationCreated', Lang.bind(this, this._conversationCreated));
+ this._proxy.connect('DisplayedImMsg', Lang.bind(this, this._messageDisplayed));
},
proxy: function () {
return this._proxy;
},
- _conversationCreated: function (emitter, conversation) {
- let proxy = this.proxy();
- if (proxy.PurpleConversationGetTypeSync(conversation) != 1) {
- return
- };
-
- let source = this._sources[conversation];
- if (!source) {
- source = new Source(this, conversation);
- source.connect('destroy', Lang.bind(this,
- function () {
- delete this._sources[conversation];
- }
- ));
- };
- this._sources[conversation] = source;
- },
+ _messageDisplayed: function(emitter, account, author, message, conversation, flag) {
- _messageReceived: function(emitter, account, author, message, conversation, flags) {
+ // only trigger on message received/message sent
+ if (flag != 1 && flag != 2) return;
if (conversation) {
let source = this._sources[conversation];
if (!source) {
- source = new Source(this, conversation, message);
+ source = new Source(this, account, author, message, conversation, flag);
source.connect('destroy', Lang.bind(this,
function() {
delete this._sources[conversation];