Skip to content

Instantly share code, notes, and snippets.

@siraj
Created August 30, 2011 23:18
Show Gist options
  • Save siraj/1182374 to your computer and use it in GitHub Desktop.
Save siraj/1182374 to your computer and use it in GitHub Desktop.
text handler
const Tp = imports.gi.TelepathyGLib;
function message_received_cb(channel, msg)
{
print ("message recived : " + msg.to_text());
channel.ack_message_async(msg, function fake (a, b, c){});
var buble = document.getElementById("chatbox");
buble.innerHTML = buble.innerHTML + String("<p class=\"lemon\">" + msg.to_text() + "</p>");
}
function observe_channels(handler, account, connection, channels, requests,
user_action_time, context)
{
print("account = " + account.get_object_path());
print("connection = " + connection.get_object_path());
for (var i = 0 ; i < channels.length ; i++) {
var channel = channels[i];
if (! (channel instanceof Tp.TextChannel)) {
continue;
}
// print("channel = " + channel.get_object_path());
//print ("Handling text channel with " + channel.get_identifier());
channel.signal.connect('message-received', message_received_cb);
}
context.accept();
}
function removed_cb(val)
{
}
Tp.debug_set_flags("all");
var dbus = Tp.DBusDaemon.dup();
var observer = new Tp.SimpleHandler.c_new(dbus, false, false, "WebkKitChat", false,
observe_channels, dbus, removed_cb);
print(observer);
var hash = {"org.freedesktop.Telepathy.Channel.ChannelType": Tp.IFACE_CHANNEL_TYPE_TEXT,
"org.freedesktop.Telepathy.Channel.TargetHandleType" : 1,
"org.freedesktop.Telepathy.Channel.Requested": false};
observer.add_handler_filter(hash);
try {
observer.register();
} catch (e) {
print("ERROR: " + e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment