Advertisement
Guest User

Untitled

a guest
Nov 29th, 2010
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /****************************************************************************
  2.  *
  3.  *  This file is part of qutIM
  4.  *
  5.  *  Copyright (c) 2010 by Nigmatullin Ruslan <euroelessar@gmail.com>
  6.  *
  7.  ***************************************************************************
  8.  *                                                                         *
  9.  *   This file is part of free software; you can redistribute it and/or    *
  10.  *   modify it under the terms of the GNU General Public License as        *
  11.  *   published by the Free Software Foundation; either version 2 of the    *
  12.  *   License, or (at your option) any later version.                       *
  13.  *                                                                         *
  14.  ***************************************************************************
  15.  ****************************************************************************/
  16.  
  17. Array.prototype.contains = function (element) {
  18.   for (var i = 0; i < this.length; i++) {
  19.     if (this[i] == element)
  20.       return true;
  21.   }
  22.   return false;
  23. }
  24.  
  25. var plugin = {
  26.   name: QT_TRANSLATE_NOOP("Plugin", "Ignorer"),
  27.   description: QT_TRANSLATE_NOOP("Plugin", "Ignores messages from certain persons"),
  28.   authors: [
  29.     {
  30.       name: QT_TRANSLATE_NOOP("Author", "Ruslan Nigmatullin"),
  31.       task: QT_TRANSLATE_NOOP("Task", "Developer"),
  32.       email: "euroelessar@ya.ru"
  33.     }
  34.   ],
  35.   personsId: [],
  36.   load: function() {
  37.     client.settings.register({
  38.       type: client.settings.Plugin,
  39.       text: QT_TRANSLATE_NOOP("Plugin", "Ignorer"),
  40.       entries: [
  41.     {
  42.       type: "PlainTextEdit",
  43.       name: "persons",
  44.       text: QT_TRANSLATE_NOOP("Ignorer", "Evil ids")
  45.     }
  46.       ],
  47.       onSaved: plugin.loadSettings
  48.     });
  49.     this.loadSettings();
  50.     client.debug("You want to ignore this persons:", this.personsId);
  51.     client.chatLayer.sessionCreated.connect(this.onSessionCreated);
  52.     return true;
  53.   },
  54.   unload: function() {
  55.     client.chatLayer.sessionCreated.disconnect(this.onSessionCreated);
  56.     return true;
  57.   },
  58.   loadSettings: function() {
  59.     var cfg = client.settings.value;
  60.     plugin.personsId = (cfg.persons + "").split('\n');
  61.   },
  62.   onSessionCreated: function (session) {
  63.     session.messageReceived.connect(plugin.onMessageReceived);
  64.   },
  65.   onMessageReceived: function (message) {
  66.     if (plugin.personsId.contains(message.chatUnit.id)
  67.       || plugin.personsId.contains(message.senderId)) {
  68.       message.hide = true;
  69.     }
  70.   }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement