Advertisement
freaktechnik

instantbird incoming tags diff

Jun 30th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.08 KB | None | 0 0
  1. diff -r 63a96ee6f193 chat/protocols/irc/irc.js
  2. --- a/chat/protocols/irc/irc.js Mon Jun 29 22:00:54 2015 +0100
  3. +++ b/chat/protocols/irc/irc.js Tue Jun 30 23:28:32 2015 +0200
  4. @@ -46,9 +46,10 @@
  5.    let message = {rawMessage: aData};
  6.    let temp;
  7.  
  8. -  // Splits the raw string into four parts (the second is required), the command
  9. +  // Splits the raw string into five parts (the third is required), the command
  10.    // is required. A raw string looks like:
  11. -  //   [":" <prefix> " "] <command> [" " <parameter>]* [":" <last parameter>]
  12. +  //   [ "@" <tags> " " ] [":" <prefix> " "] <command> [" " <parameter>]* [":" <last parameter>]
  13. +  //     <tags>: /[^ ]+/
  14.    //     <prefix>: :(<server name> | <nickname> [["!" <user>] "@" <host>])
  15.    //     <command>: /[^ ]+/
  16.    //     <parameter>: /[^ ]+/
  17. @@ -60,26 +61,49 @@
  18.    // (This is for compatibility with Unreal's 432 response, which returns an
  19.    // empty first parameter.) It also allows a trailing space after the
  20.    // <parameter>s when no <last parameter> is present (also occurs with Unreal).
  21. -  if (!(temp = aData.match(/^(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? *(?::([\s\S]*))?$/)))
  22. +  if (!(temp = aData.match(/^(?:@([^ ]+) )?(?::([^ ]+) )?([^ ]+)((?: +[^: ][^ ]*)*)? *(?::([\s\S]*))?$/)))
  23.      throw "Couldn't parse message: \"" + aData + "\"";
  24.  
  25. -  message.command = temp[2];
  26. +  message.command = temp[3];
  27.    // Space separated parameters. Since we expect a space as the first thing
  28.    // here, we want to ignore the first value (which is empty).
  29. -  message.params = temp[3] ? temp[3].split(" ").slice(1) : [];
  30. +  message.params = temp[4] ? temp[4].split(" ").slice(1) : [];
  31.    // Last parameter can contain spaces or be an empty string.
  32. -  if (temp[4] != undefined)
  33. -    message.params.push(temp[4]);
  34. +  if (temp[5] != undefined)
  35. +    message.params.push(temp[5]);
  36.  
  37.    // Handle the prefix part of the message per RFC 2812 Section 2.3.
  38.  
  39.    // If no prefix is given, assume the current server is the origin.
  40. -  if (!temp[1])
  41. -    temp[1] = aOrigin;
  42. +  if (!temp[2])
  43. +    temp[2] = aOrigin;
  44.  
  45.    // Split the prefix into separate nickname, username and hostname fields as:
  46.    //   :(servername|(nickname[[!user]@host]))
  47. -  [message.origin, message.user, message.host] = temp[1].split(/[!@]/);
  48. +  [message.origin, message.user, message.host] = temp[2].split(/[!@]/);
  49. +
  50. +  // Store the tags in a Map, if there are tags
  51. +  // For the tags spec, see IRCv3.2 Message Tags
  52. +  message.tags = new Map();
  53. +  if(temp[1]) {
  54. +    let tags = temp[1].split(";");
  55. +    tags.forEach((tag) => {
  56. +      tag = tag.split("=");
  57. +      if(tag.length > 1) {
  58. +        message.tags.set(
  59. +            tag[0],
  60. +            tag[1].replace(/(?:[^\\]|^)\\:/g, ";")
  61. +                  .replace(/(?:[^\\]|^)\\s/g, " ")
  62. +                  .replace(/(?:[^\\]|^)\\r/g, "\r")
  63. +                  .replace(/(?:[^\\]|^)\\n/g, "\n")
  64. +                  .replace(/\\/g, "\")
  65. +        );
  66. +      }
  67. +      else {
  68. +        message.tags.set(tag[0], null);
  69. +      }
  70. +    });
  71. +  }
  72.  
  73.    // It is occasionally useful to have a "source" which is a combination of
  74.    // user@host.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement