[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-messenger-build/master] Add support for Twitter DMs
commit 4ed24f63821f911de9711db8265d76c404e30d14
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date: Tue Feb 23 18:57:11 2016 -0800
Add support for Twitter DMs
* trac 13312
---
ChangeLog | 1 +
projects/ctypes-otr/config | 2 +-
projects/instantbird/config | 1 +
projects/instantbird/trac-13312.patch | 1828 +++++++++++++++++++++++++++++++++
4 files changed, 1831 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index e03f7fd..d50f962 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ Tor Messenger 0.1.0b5 --
* Bug 18235: Disable Facebook as they no longer support XMPP
* Bug 17494: Better error reporting for failed outgoing messages
* Bug 17749: Show version information in the "About" window
+ * Bug 13312: OTR over Twitter DMs
* Mac
* Bug 17896: Add Edit menu to the conversation window on OS X
* Windows
diff --git a/projects/ctypes-otr/config b/projects/ctypes-otr/config
index f7227ec..299300c 100644
--- a/projects/ctypes-otr/config
+++ b/projects/ctypes-otr/config
@@ -1,7 +1,7 @@
# vim: filetype=yaml sw=2
version: '[% c("abbrev") %]'
git_url: https://github.com/arlolra/ctypes-otr
-git_hash: 2a8f2c07d7f56e020d7c7c6806baab734471f6ca
+git_hash: 61a6472c732dc4a03b5b315c645c9f265a67b9c6
filename: 'ctypes-otr-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.gz'
var:
lib_glob: 'lib/*.so*'
diff --git a/projects/instantbird/config b/projects/instantbird/config
index 3412ab9..8fb173e 100644
--- a/projects/instantbird/config
+++ b/projects/instantbird/config
@@ -75,6 +75,7 @@ input_files:
- filename: trac-16489.patch
- filename: trac-17896.patch
- filename: trac-17494.patch
+ - filename: trac-13312.patch
- filename: version.patch
- filename: search-context-menu.patch
- filename: search-preferences-xul.patch
diff --git a/projects/instantbird/trac-13312.patch b/projects/instantbird/trac-13312.patch
new file mode 100644
index 0000000..37a81a7
--- /dev/null
+++ b/projects/instantbird/trac-13312.patch
@@ -0,0 +1,1828 @@
+# HG changeset patch
+# User Arlo Breault <arlolra@xxxxxxxxx>
+# Date 1456281485 28800
+# Tue Feb 23 18:38:05 2016 -0800
+# Branch THUNDERBIRD420b2_2015101216_RELBRANCH
+# Node ID 9d547deb66802e3068767b5df2e687f6a56c5099
+# Parent a23c99d5fced84533a9a764bb63bbd67d874f62c
+Update twitter.js to HEAD to ease applying dm patch
+
+diff --git a/chat/protocols/twitter/twitter.js b/chat/protocols/twitter/twitter.js
+--- a/chat/protocols/twitter/twitter.js
++++ b/chat/protocols/twitter/twitter.js
+@@ -1,35 +1,48 @@
+ /* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+-const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
++var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+ Cu.import("resource://gre/modules/Http.jsm");
+ Cu.import("resource:///modules/imServices.jsm");
+ Cu.import("resource:///modules/imXPCOMUtils.jsm");
+ Cu.import("resource:///modules/jsProtoHelper.jsm");
+ Cu.import("resource:///modules/twitter-text.jsm");
+
+-const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
+-const kMaxMessageLength = 140;
++var NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
++var kMaxMessageLength = 140;
+
+-XPCOMUtils.defineLazyGetter(this, "_", function()
++XPCOMUtils.defineLazyGetter(this, "_", () =>
+ l10nHelper("chrome://chat/locale/twitter.properties")
+ );
+-XPCOMUtils.defineLazyGetter(this, "_lang", function()
++XPCOMUtils.defineLazyGetter(this, "_lang", () =>
+ l10nHelper("chrome://global/locale/languageNames.properties")
+ );
+ initLogModule("twitter", this);
+
+-function ChatBuddy(aName) {
++function ChatBuddy(aName, aAccount) {
+ this._name = aName;
++ this._account = aAccount;
+ }
+-ChatBuddy.prototype = GenericConvChatBuddyPrototype;
++ChatBuddy.prototype = {
++ __proto__: GenericConvChatBuddyPrototype,
++ get buddyIconFilename() {
++ let userInfo = this._account._userInfo.get(this.name);
++ if (userInfo)
++ return userInfo.profile_image_url;
++ return undefined;
++ },
++ set buddyIconFilename(aName) {
++ // Prevent accidental removal of the getter.
++ throw("Don't set chatBuddy.buddyIconFilename directly for Twitter.");
++ }
++}
+
+ function Tweet(aTweet, aWho, aMessage, aObject)
+ {
+ this._tweet = aTweet;
+ this._init(aWho, aMessage, aObject);
+ }
+ Tweet.prototype = {
+ __proto__: GenericMessagePrototype,
+@@ -102,26 +115,30 @@ Tweet.prototype = {
+ function Action(aLabel, aAction, aTweet)
+ {
+ this.label = aLabel;
+ this._action = aAction;
+ this._tweet = aTweet;
+ }
+ Action.prototype = {
+ __proto__: ClassInfo("prplIMessageAction", "generic message action object"),
+- get run() this._action.bind(this._tweet)
++ get run() { return this._action.bind(this._tweet); }
+ };
+
+ function Conversation(aAccount)
+ {
+ this._init(aAccount);
+ this._ensureParticipantExists(aAccount.name);
+ // We need the screen names for the IDs in _friends, but _userInfo is
+ // indexed by name, so we build an ID -> name map.
+- let names = new Map([userInfo.id_str, name] for ([name, userInfo] of aAccount._userInfo));
++ let entries = [];
++ for (let [name, userInfo] of aAccount._userInfo) {
++ entries.push([userInfo.id_str, name]);
++ }
++ let names = new Map(entries);
+ for (let id_str of aAccount._friends)
+ this._ensureParticipantExists(names.get(id_str));
+
+ // If the user's info has already been received, update the timeline topic.
+ if (aAccount._userInfo.has(aAccount.name)) {
+ let userInfo = aAccount._userInfo.get(aAccount.name);
+ if ("description" in userInfo)
+ this.setTopic(userInfo.description, aAccount.name, true);
+@@ -137,24 +154,24 @@ Conversation.prototype = {
+ startReply: function(aTweet) {
+ this.inReplyToStatusId = aTweet.id_str;
+ let entities = aTweet.entities;
+
+ // Twitter replies go to all the users mentioned in the tweet.
+ let nicks = [aTweet.user.screen_name];
+ if ("user_mentions" in entities && Array.isArray(entities.user_mentions)) {
+ nicks = nicks.concat(entities.user_mentions
+- .map(function(um) um.screen_name));
++ .map(um => um.screen_name));
+ }
+ // Ignore duplicates and the user's nick.
+ let prompt =
+ nicks.filter(function(aNick, aPos) {
+ return nicks.indexOf(aNick) == aPos && aNick != this._account.name;
+ }, this)
+- .map(function(aNick) "@" + aNick)
++ .map(aNick => "@" + aNick)
+ .join(" ") + " ";
+
+ this.notifyObservers(null, "replying-to-prompt", prompt);
+ this.notifyObservers(null, "status-text-changed",
+ _("replyingToStatusText", aTweet.text));
+ },
+ reTweet: function(aTweet) {
+ this._account.reTweet(aTweet, this.onSentCallback,
+@@ -232,17 +249,17 @@ Conversation.prototype = {
+ let offset = text.indexOf(": ") + 2;
+ text = text.slice(0, offset) + retweet.text;
+
+ // Keep any entities that refer to the prefix (we can refer directly to
+ // aTweet for these since they are not edited).
+ if ("entities" in aTweet) {
+ for (let type in aTweet.entities) {
+ let filteredEntities =
+- aTweet.entities[type].filter(function(e) e.indices[0] < offset);
++ aTweet.entities[type].filter(e => e.indices[0] < offset);
+ if (filteredEntities.length)
+ entities[type] = filteredEntities;
+ }
+ }
+
+ // Add the entities from the retweet (a copy of these must be made since
+ // they will be edited and we do not wish to change aTweet).
+ if ("entities" in retweet) {
+@@ -250,17 +267,17 @@ Conversation.prototype = {
+ if (!(type in entities))
+ entities[type] = [];
+
+ // Append the entities from the original status.
+ entities[type] = entities[type].concat(
+ retweet.entities[type].map(function(aEntity) {
+ let entity = Object.create(aEntity);
+ // Add the offset to the indices to account for the prefix.
+- entity.indices = entity.indices.map(function(i) i + offset);
++ entity.indices = entity.indices.map(i => i + offset);
+ return entity;
+ })
+ );
+ }
+ }
+ } else {
+ // For non-retweets, we just want to use the entities that are given.
+ if ("entities" in aTweet)
+@@ -275,42 +292,43 @@ Conversation.prototype = {
+ * - str: the string that should be replaced inside the tweet,
+ * - href: the url (href attribute) of the created link tag,
+ * - [optional] text: the text to display for the link,
+ * The original string (str) will be used if this is not set.
+ * - [optional] title: the title attribute for the link.
+ */
+ let entArray = [];
+ if ("hashtags" in entities && Array.isArray(entities.hashtags)) {
+- entArray = entArray.concat(entities.hashtags.map(function(h) ({
++ entArray = entArray.concat(entities.hashtags.map(h => ({
+ start: h.indices[0],
+ end: h.indices[1],
+ str: "#" + h.text,
+ href: "https://twitter.com/#!/search?q=%23" + h.text})));
+ }
+ if ("urls" in entities && Array.isArray(entities.urls)) {
+- entArray = entArray.concat(entities.urls.map(function(u) ({
++ entArray = entArray.concat(entities.urls.map(u => ({
+ start: u.indices[0],
+ end: u.indices[1],
+ str: u.url,
+ text: u.display_url || u.url,
+ href: u.expanded_url || u.url})));
+ }
+ if ("user_mentions" in entities &&
+ Array.isArray(entities.user_mentions)) {
+- entArray = entArray.concat(entities.user_mentions.map(function(um) ({
++ entArray = entArray.concat(entities.user_mentions.map(um => ({
+ start: um.indices[0],
+ end: um.indices[1],
+ str: "@" + um.screen_name,
++ text: '@<span class="ib-person">' + um.screen_name + "</span>",
+ title: um.name,
+ href: "https://twitter.com/" + um.screen_name})));
+ }
+- entArray.sort(function(a, b) a.start - b.start);
++ entArray.sort((a, b) => a.start - b.start);
+ let offset = 0;
+- for each (let entity in entArray) {
++ for (let entity of entArray) {
+ let str = text.substring(offset + entity.start, offset + entity.end);
+ if (str[0] == "\uFF20") // ï¼ - unicode character similar to @
+ str = "@" + str.substring(1);
+ if (str[0] == "\uFF03") // ï¼? - unicode character similar to #
+ str = "#" + str.substring(1);
+ if (str.toLowerCase() != entity.str.toLowerCase())
+ continue;
+
+@@ -332,36 +350,38 @@ Conversation.prototype = {
+ let text = this.parseTweet(aTweet);
+
+ let flags =
+ name == this._account.name ? {outgoing: true} : {incoming: true};
+ flags.time = Math.round(new Date(aTweet.created_at) / 1000);
+ flags._iconURL = aTweet.user.profile_image_url;
+ if (aTweet.delayed)
+ flags.delayed = true;
+- if (text.includes("@" + this.nick))
++ if (aTweet.entities && aTweet.entities.user_mentions &&
++ Array.isArray(aTweet.entities.user_mentions) &&
++ aTweet.entities.user_mentions.some(mention => mention.screen_name == this.nick))
+ flags.containsNick = true;
+
+ (new Tweet(aTweet, name, text, flags)).conversation = this;
+ },
+ _ensureParticipantExists: function(aNick) {
+ if (this._participants.has(aNick))
+ return;
+
+- let chatBuddy = new ChatBuddy(aNick);
++ let chatBuddy = new ChatBuddy(aNick, this._account);
+ this._participants.set(aNick, chatBuddy);
+ this.notifyObservers(new nsSimpleEnumerator([chatBuddy]),
+ "chat-buddy-add");
+ },
+- get name() this.nick + " timeline",
+- get title() _("timeline", this.nick),
+- get nick() this._account.name,
++ get name() { return this.nick + " timeline"; },
++ get title() { return _("timeline", this.nick); },
++ get nick() { return this._account.name; },
+ set nick(aNick) {},
+- get topicSettable() this.nick == this._account.name,
+- get topic() this._topic, // can't add a setter without redefining the getter
++ get topicSettable() { return this.nick == this._account.name; },
++ get topic() { return this._topic; }, // can't add a setter without redefining the getter
+ set topic(aTopic) {
+ if (this.topicSettable)
+ this._account.setUserDescription(aTopic);
+ }
+ };
+
+ function Account(aProtocol, aImAccount)
+ {
+@@ -371,17 +391,17 @@ function Account(aProtocol, aImAccount)
+ this._friends = new Set();
+ }
+ Account.prototype = {
+ __proto__: GenericAccountPrototype,
+
+ // The correct normalization for twitter would be just toLowerCase().
+ // Unfortunately, for backwards compatibility we retain this normalization,
+ // which can cause edge cases for usernames with underscores.
+- normalize: function(aString) aString.replace(/[^a-z0-9]/gi, "").toLowerCase(),
++ normalize: aString => aString.replace(/[^a-z0-9]/gi, "").toLowerCase(),
+
+ consumerKey: Services.prefs.getCharPref("chat.twitter.consumerKey"),
+ consumerSecret: Services.prefs.getCharPref("chat.twitter.consumerSecret"),
+ completionURI: "http://oauthcallback.local/",
+ baseURI: "https://api.twitter.com/",
+ _lastMsgId: "",
+
+ // Use this to keep track of the pending timeline requests. We attempt to fetch
+@@ -466,49 +486,49 @@ Account.prototype = {
+
+ let dataParams = [];
+ let url = /^https?:/.test(aUrl) ? aUrl : this.baseURI + aUrl;
+ let urlSpec = url;
+ let queryIndex = url.indexOf("?");
+ if (queryIndex != -1) {
+ urlSpec = url.slice(0, queryIndex);
+ dataParams = url.slice(queryIndex + 1).split("&")
+- .map(function(p) p.split("=").map(percentEncode));
++ .map(p => p.split("=").map(percentEncode));
+ }
+ let method = "GET";
+ if (aPOSTData) {
+ method = "POST";
+ aPOSTData.forEach(function (p) {
+ dataParams.push(p.map(percentEncode));
+ });
+ }
+
+ let signatureKey = this.consumerSecret + "&" + this.tokenSecret;
+ let signatureBase =
+ method + "&" + encodeURIComponent(urlSpec) + "&" +
+ params.concat(dataParams)
+- .sort(function(a,b) (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0)
+- .map(function(p) p.map(encodeURIComponent).join("%3D"))
++ .sort((a, b) => (a[0] < b[0]) ? -1 : (a[0] > b[0]) ? 1 : 0)
++ .map(p => p.map(encodeURIComponent).join("%3D"))
+ .join("%26");
+
+ let keyFactory = Cc["@mozilla.org/security/keyobjectfactory;1"]
+ .getService(Ci.nsIKeyObjectFactory);
+ let hmac =
+ Cc["@mozilla.org/security/hmac;1"].createInstance(Ci.nsICryptoHMAC);
+ hmac.init(hmac.SHA1,
+ keyFactory.keyFromString(Ci.nsIKeyObject.HMAC, signatureKey));
+ // No UTF-8 encoding, special chars are already escaped.
+- let bytes = [b.charCodeAt() for each (b in signatureBase)];
++ let bytes = [...signatureBase].map(b => b.charCodeAt());
+ hmac.update(bytes, bytes.length);
+ let signature = hmac.finish(true);
+
+ params.push(["oauth_signature", encodeURIComponent(signature)]);
+
+ let authorization =
+- "OAuth " + params.map(function (p) p[0] + "=\"" + p[1] + "\"").join(", ");
++ "OAuth " + params.map(p => p[0] + "=\"" + p[1] + "\"").join(", ");
+
+ let options = {
+ headers: (aHeaders || []).concat([["Authorization", authorization]]),
+ postData: aPOSTData,
+ onLoad: aOnLoad ? aOnLoad.bind(aThis) : null,
+ onError: aOnError ? aOnError.bind(aThis) : null,
+ logger: {log: this.LOG.bind(this),
+ debug: this.DEBUG.bind(this)}
+@@ -595,20 +615,20 @@ Account.prototype = {
+ getParams = "?q=" + trackQuery + lastMsgParam + "&count=100";
+ let url = "1.1/search/tweets.json" + getParams;
+ this._pendingRequests.push(
+ this.signAndSend(url, null, null, this.onTimelineReceived,
+ this.onTimelineError, this, null));
+ }
+ },
+
+- get timeline() this._timeline || (this._timeline = new Conversation(this)),
++ get timeline() { return this._timeline || (this._timeline = new Conversation(this)); },
+ displayMessages: function(aMessages) {
+ let lastMsgId = this._lastMsgId;
+- for each (let tweet in aMessages) {
++ for (let tweet of aMessages) {
+ if (!("user" in tweet) || !("text" in tweet) || !("id_str" in tweet) ||
+ this._knownMessageIds.has(tweet.id_str))
+ continue;
+ let id = tweet.id_str;
+ // Update the last known message.
+ // Compare the length of the ids first, and then the text.
+ // This avoids converting tweet ids into rounded numbers.
+ if (id.length > lastMsgId.length ||
+@@ -633,17 +653,17 @@ Account.prototype = {
+
+ onTimelineReceived: function(aData, aRequest) {
+ this._timelineBuffer = this._timelineBuffer.concat(JSON.parse(aData));
+ this._doneWithTimelineRequest(aRequest);
+ },
+
+ _doneWithTimelineRequest: function(aRequest) {
+ this._pendingRequests =
+- this._pendingRequests.filter(function (r) r !== aRequest);
++ this._pendingRequests.filter(r => r !== aRequest);
+
+ // If we are still waiting for more data, return early
+ if (this._pendingRequests.length != 0)
+ return;
+
+ if (this._timelineAuthError >= 2) {
+ // 2 out of the 3 timeline requests are authenticated.
+ // With at least 2 '401 - Unauthorized' errors, we are sure
+@@ -678,17 +698,17 @@ Account.prototype = {
+ // Reset in case we get disconnected
+ delete this._timelineBuffer;
+ delete this._pendingRequests;
+
+ // Open the streams to get the live data.
+ this.openStream();
+ },
+
+- sortByDate: function(a, b)
++ sortByDate: (a, b) =>
+ (new Date(a["created_at"])) - (new Date(b["created_at"])),
+
+ _streamingRequest: null,
+ _pendingData: "",
+ openStream: function() {
+ let track = this.getString("track");
+ this._streamingRequest =
+ this.signAndSend("https://userstream.twitter.com/1.1/user.json", null,
+@@ -717,48 +737,48 @@ Account.prototype = {
+ this.gotDisconnected(Ci.prplIAccount.ERROR_NETWORK_ERROR, "timeout");
+ },
+ onDataAvailable: function(aRequest) {
+ this.resetStreamTimeout();
+ let newText = this._pendingData + aRequest.target.response;
+ this.DEBUG("Received data: " + newText);
+ let messages = newText.split(/\r\n?/);
+ this._pendingData = messages.pop();
+- for each (let message in messages) {
++ for (let message of messages) {
+ if (!message.trim())
+ continue;
+ let msg;
+ try {
+ msg = JSON.parse(message);
+ } catch (e) {
+ this.ERROR(e + " while parsing " + message);
+ continue;
+ }
+ if ("text" in msg)
+ this.displayMessages([msg]);
+ else if ("friends" in msg) {
+ // Filter out the IDs that info has already been received from (e.g. a
+ // tweet has been received as part of the timeline request).
+ let userInfoIds = new Set();
+- for each (let userInfo in this._userInfo)
++ for (let userInfo of this._userInfo.values())
+ userInfoIds.add(userInfo.id_str);
+ let ids = msg.friends.filter(
+- function(aId) !userInfoIds.has(aId.toString()), this);
++ aId => !userInfoIds.has(aId.toString()));
+
+ while (ids.length) {
+ // Take the first 100 elements, turn them into a comma separated list.
+ this.signAndSend("1.1/users/lookup.json", null,
+ [["user_id", ids.slice(0, 99).join(",")]],
+ this.onLookupReceived, null, this);
+ // Remove the first 100 elements.
+ ids = ids.slice(100);
+ }
+
+ // Overwrite the existing _friends list (if any).
+- this._friends = new Set(msg.friends.map(function(aId) aId.toString()));
++ this._friends = new Set(msg.friends.map(aId => aId.toString()));
+ }
+ else if ("event" in msg) {
+ let user, event;
+ switch(msg.event) {
+ case "follow":
+ if (msg.source.screen_name == this.name) {
+ this._friends.add(msg.target.id_str);
+ user = msg.target;
+@@ -806,17 +826,17 @@ Account.prototype = {
+ },
+ requestAuthorization: function() {
+ this.reportConnecting(_("connection.requestAuth"));
+ let url = this.baseURI + "oauth/authorize?" +
+ "force_login=true&" + // ignore cookies
+ "screen_name=" + this.name + "&" + // prefill the user name input box
+ "oauth_token=" + this.token;
+ this._browserRequest = {
+- get promptText() _("authPrompt"),
++ get promptText() { return _("authPrompt"); },
+ account: this,
+ url: url,
+ _active: true,
+ cancelled: function() {
+ if (!this._active)
+ return;
+
+ this.account
+@@ -920,24 +940,24 @@ Account.prototype = {
+
+ if (aAuthResult.screen_name.toLowerCase() != this.name.toLowerCase()) {
+ this.onError(_("connection.error.userMismatch"));
+ return false;
+ }
+
+ this.LOG("Fixing the case of the account name: " +
+ this.name + " -> " + aAuthResult.screen_name);
+- this.__defineGetter__("name", function() aAuthResult.screen_name);
++ this.__defineGetter__("name", () => aAuthResult.screen_name);
+ return true;
+ },
+
+ cleanUp: function() {
+ this.finishAuthorizationRequest();
+ if (this._pendingRequests.length != 0) {
+- for each (let request in this._pendingRequests)
++ for (let request of this._pendingRequests)
+ request.abort();
+ delete this._pendingRequests;
+ }
+ if (this._streamTimeout) {
+ clearTimeout(this._streamTimeout);
+ delete this._streamTimeout;
+ // Remove the preference observer that is added when the user stream is
+ // opened. (This needs to be removed even if an error occurs, in which
+@@ -1019,117 +1039,119 @@ Account.prototype = {
+ this.signAndSend("1.1/users/show.json?screen_name=" + aBuddyName, null,
+ null, this.onRequestedInfoReceived, null, this);
+ return;
+ }
+
+ // List of the names of the info to actually show in the tooltip and
+ // optionally a transform function to apply to the value.
+ // See https://dev.twitter.com/docs/api/1/get/users/show for the options.
+- let normalizeBool = function(isFollowing) _(isFollowing ? "yes" : "no");
++ let normalizeBool = isFollowing => _(isFollowing ? "yes" : "no");
+ const kFields = {
+ name: null,
+ following: normalizeBool,
+ description: null,
+ url: null,
+ location: null,
+ lang: function(aLang) {
+ try {
+ return _lang(aLang);
+ }
+ catch(e) {
+ return aLang;
+ }
+ },
+ time_zone: null,
+ protected: normalizeBool,
+- created_at: function(aDate) (new Date(aDate)).toLocaleDateString(),
++ created_at: aDate => (new Date(aDate)).toLocaleDateString(),
+ statuses_count: null,
+ friends_count: null,
+ followers_count: null,
+ listed_count: null
+ };
+
+ let tooltipInfo = [];
+ for (let field in kFields) {
+ if (Object.prototype.hasOwnProperty.call(userInfo, field) &&
+ userInfo[field]) {
+ let value = userInfo[field];
+ if (kFields[field])
+ value = kFields[field](value);
+ tooltipInfo.push(new TooltipInfo(_("tooltip." + field), value));
+ }
+ }
++ tooltipInfo.push(new TooltipInfo(null, userInfo.profile_image_url,
++ Ci.prplITooltipInfo.icon));
+
+ Services.obs.notifyObservers(new nsSimpleEnumerator(tooltipInfo),
+ "user-info-received", aBuddyName);
+ },
+
+ // Handle the full user info for each received friend. Set the user info and
+ // create the participant.
+ onLookupReceived: function(aData) {
+ let users = JSON.parse(aData);
+- for each (let user in users) {
++ for (let user of users) {
+ this.setUserInfo(user);
+ this.timeline._ensureParticipantExists(user.screen_name);
+ }
+ },
+
+ onConfigReceived: function(aData) {
+ this.config = JSON.parse(aData);
+ },
+
+ // Allow us to reopen the timeline via the join chat menu.
+- get canJoinChat() true,
++ get canJoinChat() { return true; },
+ joinChat: function(aComponents) {
+ // The 'timeline' getter opens a timeline conversation if none exists.
+ this.timeline;
+ }
+ };
+
+ // Shortcut to get the JavaScript account object.
+-function getAccount(aConv) aConv.wrappedJSObject._account;
++function getAccount(aConv) { return aConv.wrappedJSObject._account; }
+
+ function TwitterProtocol() {
+ this.registerCommands();
+ }
+ TwitterProtocol.prototype = {
+ __proto__: GenericProtocolPrototype,
+- get normalizedName() "twitter",
+- get name() _("twitter.protocolName"),
+- get iconBaseURI() "chrome://prpl-twitter/skin/",
+- get noPassword() true,
++ get normalizedName() { return "twitter"; },
++ get name() { return _("twitter.protocolName"); },
++ get iconBaseURI() { return "chrome://prpl-twitter/skin/"; },
++ get noPassword() { return true; },
+ options: {
+- "track": {get label() _("options.track"), default: ""}
++ "track": {get label() { return _("options.track"); }, default: ""}
+ },
+ // Replace the command name in the help string so translators do not attempt
+ // to translate it.
+ commands: [
+ {
+ name: "follow",
+- get helpString() _("command.follow", "follow"),
++ get helpString() { return _("command.follow", "follow"); },
+ run: function(aMsg, aConv) {
+ aMsg = aMsg.trim();
+ if (!aMsg)
+ return false;
+ let account = getAccount(aConv);
+ aMsg.split(" ").forEach(account.follow, account);
+ return true;
+ }
+ },
+ {
+ name: "unfollow",
+- get helpString() _("command.unfollow", "unfollow"),
++ get helpString() { return _("command.unfollow", "unfollow"); },
+ run: function(aMsg, aConv) {
+ aMsg = aMsg.trim();
+ if (!aMsg)
+ return false;
+ let account = getAccount(aConv);
+ aMsg.split(" ").forEach(account.stopFollowing, account);
+ return true;
+ }
+ }
+ ],
+- getAccount: function(aImAccount) new Account(this, aImAccount),
++ getAccount: function(aImAccount) { return new Account(this, aImAccount); },
+ classID: Components.ID("{31082ff6-1de8-422b-ab60-ca0ac0b2af13}")
+ };
+
+-const NSGetFactory = XPCOMUtils.generateNSGetFactory([TwitterProtocol]);
++var NSGetFactory = XPCOMUtils.generateNSGetFactory([TwitterProtocol]);
+# HG changeset patch
+# User Arlo Breault <arlolra@xxxxxxxxx>
+# Date 1456282265 28800
+# Tue Feb 23 18:51:05 2016 -0800
+# Branch THUNDERBIRD420b2_2015101216_RELBRANCH
+# Node ID 01edd1bf5e56e382611823a8f0ab604743c78b02
+# Parent 9d547deb66802e3068767b5df2e687f6a56c5099
+Bug 955642 - Handle Twitter direct messages (DMs)
+
+diff --git a/chat/components/src/imConversations.js b/chat/components/src/imConversations.js
+--- a/chat/components/src/imConversations.js
++++ b/chat/components/src/imConversations.js
+@@ -25,16 +25,17 @@ OutgoingMessage.prototype = {
+ action: false
+ };
+
+ function imMessage(aPrplMessage) {
+ this.prplMessage = aPrplMessage;
+ }
+ imMessage.prototype = {
+ __proto__: ClassInfo(["imIMessage", "prplIMessage"], "IM Message"),
++ get wrappedJSObject() { return this; },
+ cancelled: false,
+ color: "",
+ _displayMessage: null,
+
+ get displayMessage() {
+ // Explicitly test for null so that blank messages don't fall back to
+ // the original. Especially problematic in encryption extensions like OTR.
+ return this._displayMessage !== null ?
+@@ -409,17 +410,18 @@ UIConversation.prototype = {
+ this._observers = this._observers.filter(function(o) o !== aObserver);
+ },
+ notifyObservers: function(aSubject, aTopic, aData) {
+ if (aTopic == "new-text") {
+ aSubject = new imMessage(aSubject);
+ this.notifyObservers(aSubject, "received-message");
+ if (aSubject.cancelled)
+ return;
+- aSubject.conversation.prepareForDisplaying(aSubject);
++ if (!aSubject.system)
++ aSubject.conversation.prepareForDisplaying(aSubject);
+
+ this._messages.push(aSubject);
+ ++this._unreadMessageCount;
+ if (aSubject.incoming && !aSubject.system) {
+ ++this._unreadIncomingMessageCount;
+ if (!this.isChat || aSubject.containsNick)
+ ++this._unreadTargetedMessageCount;
+ }
+diff --git a/chat/modules/jsProtoHelper.jsm b/chat/modules/jsProtoHelper.jsm
+--- a/chat/modules/jsProtoHelper.jsm
++++ b/chat/modules/jsProtoHelper.jsm
+@@ -373,16 +373,17 @@ const GenericAccountBuddyPrototype = {
+ // aUserName is required only if aBuddy is null, i.e., we are adding a buddy.
+ function AccountBuddy(aAccount, aBuddy, aTag, aUserName) {
+ this._init(aAccount, aBuddy, aTag, aUserName);
+ }
+ AccountBuddy.prototype = GenericAccountBuddyPrototype;
+
+ const GenericMessagePrototype = {
+ __proto__: ClassInfo("prplIMessage", "generic message object"),
++ get wrappedJSObject() { return this; },
+
+ _lastId: 0,
+ _init: function (aWho, aMessage, aObject) {
+ this.id = ++GenericMessagePrototype._lastId;
+ this.time = Math.round(new Date() / 1000);
+ this.who = aWho;
+ this.message = aMessage;
+ this.originalMessage = aMessage;
+diff --git a/chat/protocols/twitter/twitter-text.jsm b/chat/protocols/twitter/twitter-text.jsm
+--- a/chat/protocols/twitter/twitter-text.jsm
++++ b/chat/protocols/twitter/twitter-text.jsm
+@@ -14,17 +14,17 @@
+ */
+
+ const EXPORTED_SYMBOLS = ["twttr"];
+
+ var window = {};
+
+ // The code below is imported from Twitter's JavaScript utility for parsing
+ // tweets. The original version of this file can be found at
+-// https://github.com/twitter/twitter-text-js/blob/master/twitter-text.js
++// https://github.com/twitter/twitter-text/blob/master/js/twitter-text.js
+
+ (function() {
+ if (typeof twttr === "undefined" || twttr === null) {
+ var twttr = {};
+ }
+
+ twttr.txt = {};
+ twttr.txt.regexen = {};
+@@ -120,90 +120,16 @@ var window = {};
+
+ twttr.txt.regexen.spaces_group = regexSupplant(UNICODE_SPACES.join(""));
+ twttr.txt.regexen.spaces = regexSupplant("[" + UNICODE_SPACES.join("") + "]");
+ twttr.txt.regexen.invalid_chars_group = regexSupplant(INVALID_CHARS.join(""));
+ twttr.txt.regexen.punct = /\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/;
+ twttr.txt.regexen.rtl_chars = /[\u0600-\u06FF]|[\u0750-\u077F]|[\u0590-\u05FF]|[\uFE70-\uFEFF]/mg;
+ twttr.txt.regexen.non_bmp_code_pairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/mg;
+
+- var nonLatinHashtagChars = [];
+- // Cyrillic
+- addCharsToCharClass(nonLatinHashtagChars, 0x0400, 0x04ff); // Cyrillic
+- addCharsToCharClass(nonLatinHashtagChars, 0x0500, 0x0527); // Cyrillic Supplement
+- addCharsToCharClass(nonLatinHashtagChars, 0x2de0, 0x2dff); // Cyrillic Extended A
+- addCharsToCharClass(nonLatinHashtagChars, 0xa640, 0xa69f); // Cyrillic Extended B
+- // Hebrew
+- addCharsToCharClass(nonLatinHashtagChars, 0x0591, 0x05bf); // Hebrew
+- addCharsToCharClass(nonLatinHashtagChars, 0x05c1, 0x05c2);
+- addCharsToCharClass(nonLatinHashtagChars, 0x05c4, 0x05c5);
+- addCharsToCharClass(nonLatinHashtagChars, 0x05c7, 0x05c7);
+- addCharsToCharClass(nonLatinHashtagChars, 0x05d0, 0x05ea);
+- addCharsToCharClass(nonLatinHashtagChars, 0x05f0, 0x05f4);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb12, 0xfb28); // Hebrew Presentation Forms
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb2a, 0xfb36);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb38, 0xfb3c);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb3e, 0xfb3e);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb40, 0xfb41);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb43, 0xfb44);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb46, 0xfb4f);
+- // Arabic
+- addCharsToCharClass(nonLatinHashtagChars, 0x0610, 0x061a); // Arabic
+- addCharsToCharClass(nonLatinHashtagChars, 0x0620, 0x065f);
+- addCharsToCharClass(nonLatinHashtagChars, 0x066e, 0x06d3);
+- addCharsToCharClass(nonLatinHashtagChars, 0x06d5, 0x06dc);
+- addCharsToCharClass(nonLatinHashtagChars, 0x06de, 0x06e8);
+- addCharsToCharClass(nonLatinHashtagChars, 0x06ea, 0x06ef);
+- addCharsToCharClass(nonLatinHashtagChars, 0x06fa, 0x06fc);
+- addCharsToCharClass(nonLatinHashtagChars, 0x06ff, 0x06ff);
+- addCharsToCharClass(nonLatinHashtagChars, 0x0750, 0x077f); // Arabic Supplement
+- addCharsToCharClass(nonLatinHashtagChars, 0x08a0, 0x08a0); // Arabic Extended A
+- addCharsToCharClass(nonLatinHashtagChars, 0x08a2, 0x08ac);
+- addCharsToCharClass(nonLatinHashtagChars, 0x08e4, 0x08fe);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfb50, 0xfbb1); // Arabic Pres. Forms A
+- addCharsToCharClass(nonLatinHashtagChars, 0xfbd3, 0xfd3d);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfd50, 0xfd8f);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfd92, 0xfdc7);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfdf0, 0xfdfb);
+- addCharsToCharClass(nonLatinHashtagChars, 0xfe70, 0xfe74); // Arabic Pres. Forms B
+- addCharsToCharClass(nonLatinHashtagChars, 0xfe76, 0xfefc);
+- addCharsToCharClass(nonLatinHashtagChars, 0x200c, 0x200c); // Zero-Width Non-Joiner
+- // Thai
+- addCharsToCharClass(nonLatinHashtagChars, 0x0e01, 0x0e3a);
+- addCharsToCharClass(nonLatinHashtagChars, 0x0e40, 0x0e4e);
+- // Hangul (Korean)
+- addCharsToCharClass(nonLatinHashtagChars, 0x1100, 0x11ff); // Hangul Jamo
+- addCharsToCharClass(nonLatinHashtagChars, 0x3130, 0x3185); // Hangul Compatibility Jamo
+- addCharsToCharClass(nonLatinHashtagChars, 0xA960, 0xA97F); // Hangul Jamo Extended-A
+- addCharsToCharClass(nonLatinHashtagChars, 0xAC00, 0xD7AF); // Hangul Syllables
+- addCharsToCharClass(nonLatinHashtagChars, 0xD7B0, 0xD7FF); // Hangul Jamo Extended-B
+- addCharsToCharClass(nonLatinHashtagChars, 0xFFA1, 0xFFDC); // half-width Hangul
+- // Japanese and Chinese
+- addCharsToCharClass(nonLatinHashtagChars, 0x30A1, 0x30FA); // Katakana (full-width)
+- addCharsToCharClass(nonLatinHashtagChars, 0x30FC, 0x30FE); // Katakana Chouon and iteration marks (full-width)
+- addCharsToCharClass(nonLatinHashtagChars, 0xFF66, 0xFF9F); // Katakana (half-width)
+- addCharsToCharClass(nonLatinHashtagChars, 0xFF70, 0xFF70); // Katakana Chouon (half-width)
+- addCharsToCharClass(nonLatinHashtagChars, 0xFF10, 0xFF19); // \
+- addCharsToCharClass(nonLatinHashtagChars, 0xFF21, 0xFF3A); // - Latin (full-width)
+- addCharsToCharClass(nonLatinHashtagChars, 0xFF41, 0xFF5A); // /
+- addCharsToCharClass(nonLatinHashtagChars, 0x3041, 0x3096); // Hiragana
+- addCharsToCharClass(nonLatinHashtagChars, 0x3099, 0x309E); // Hiragana voicing and iteration mark
+- addCharsToCharClass(nonLatinHashtagChars, 0x3400, 0x4DBF); // Kanji (CJK Extension A)
+- addCharsToCharClass(nonLatinHashtagChars, 0x4E00, 0x9FFF); // Kanji (Unified)
+- // -- Disabled as it breaks the Regex.
+- //addCharsToCharClass(nonLatinHashtagChars, 0x20000, 0x2A6DF); // Kanji (CJK Extension B)
+- addCharsToCharClass(nonLatinHashtagChars, 0x2A700, 0x2B73F); // Kanji (CJK Extension C)
+- addCharsToCharClass(nonLatinHashtagChars, 0x2B740, 0x2B81F); // Kanji (CJK Extension D)
+- addCharsToCharClass(nonLatinHashtagChars, 0x2F800, 0x2FA1F); // Kanji (CJK supplement)
+- addCharsToCharClass(nonLatinHashtagChars, 0x3003, 0x3003); // Kanji iteration mark
+- addCharsToCharClass(nonLatinHashtagChars, 0x3005, 0x3005); // Kanji iteration mark
+- addCharsToCharClass(nonLatinHashtagChars, 0x303B, 0x303B); // Han iteration mark
+-
+- twttr.txt.regexen.nonLatinHashtagChars = regexSupplant(nonLatinHashtagChars.join(""));
+-
+ var latinAccentChars = [];
+ // Latin accented characters (subtracted 0xD7 from the range, it's a confusable multiplication sign. Looks like "x")
+ addCharsToCharClass(latinAccentChars, 0x00c0, 0x00d6);
+ addCharsToCharClass(latinAccentChars, 0x00d8, 0x00f6);
+ addCharsToCharClass(latinAccentChars, 0x00f8, 0x00ff);
+ // Latin Extended A and B
+ addCharsToCharClass(latinAccentChars, 0x0100, 0x024f);
+ // assorted IPA Extensions
+@@ -220,26 +146,30 @@ var window = {};
+ // Okina for Hawaiian (it *is* a letter character)
+ addCharsToCharClass(latinAccentChars, 0x02bb, 0x02bb);
+ // Combining diacritics
+ addCharsToCharClass(latinAccentChars, 0x0300, 0x036f);
+ // Latin Extended Additional
+ addCharsToCharClass(latinAccentChars, 0x1e00, 0x1eff);
+ twttr.txt.regexen.latinAccentChars = regexSupplant(latinAccentChars.join(""));
+
+- // A hashtag must contain characters, numbers and underscores, but not all numbers.
++ var unicodeLettersAndMarks = "A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0
B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8
-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u
2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\u
FB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C03\u0C3E-\u0C44
\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D01-\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8\u19C9\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFC-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099
\u309A\uA66F-\uA672\uA674-\uA67D\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2D";
++ var unicodeNumbers = "0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19";
++ var hashtagSpecialChars = "_\u200c\u200d\ua67e\u05be\u05f3\u05f4\uff5e\u301c\u309b\u309c\u30a0\u30fb\u3003\u0f0b\u0f0c\u00b7";
++
++ // A hashtag must contain at least one unicode letter or mark, as well as numbers, underscores, and select special characters.
+ twttr.txt.regexen.hashSigns = /[#ï¼?]/;
+- twttr.txt.regexen.hashtagAlpha = regexSupplant(/[a-z_#{latinAccentChars}#{nonLatinHashtagChars}]/i);
+- twttr.txt.regexen.hashtagAlphaNumeric = regexSupplant(/[a-z0-9_#{latinAccentChars}#{nonLatinHashtagChars}]/i);
++ twttr.txt.regexen.hashtagAlpha = new RegExp("[" + unicodeLettersAndMarks + "]");
++ twttr.txt.regexen.hashtagAlphaNumeric = new RegExp("[" + unicodeLettersAndMarks + unicodeNumbers + hashtagSpecialChars + "]");
+ twttr.txt.regexen.endHashtagMatch = regexSupplant(/^(?:#{hashSigns}|:\/\/)/);
+- twttr.txt.regexen.hashtagBoundary = regexSupplant(/(?:^|$|[^&a-z0-9_#{latinAccentChars}#{nonLatinHashtagChars}])/);
+- twttr.txt.regexen.validHashtag = regexSupplant(/(#{hashtagBoundary})(#{hashSigns})(#{hashtagAlphaNumeric}*#{hashtagAlpha}#{hashtagAlphaNumeric}*)/gi);
++ twttr.txt.regexen.hashtagBoundary = new RegExp("(?:^|$|[^&" + unicodeLettersAndMarks + unicodeNumbers + hashtagSpecialChars + "])");
++ twttr.txt.regexen.validHashtag = regexSupplant(/(#{hashtagBoundary})(#{hashSigns})(?!\ufe0f|\u20e3)(#{hashtagAlphaNumeric}*#{hashtagAlpha}#{hashtagAlphaNumeric}*)/gi);
+
+ // Mention related regex collection
+- twttr.txt.regexen.validMentionPrecedingChars = /(?:^|[^a-zA-Z0-9_!#$%&*@ï¼ ]|RT:?)/;
++ twttr.txt.regexen.validMentionPrecedingChars = /(?:^|[^a-zA-Z0-9_!#$%&*@ï¼ ]|(?:^|[^a-zA-Z0-9_+~.-])(?:rt|RT|rT|Rt):?)/;
+ twttr.txt.regexen.atSigns = /[@ï¼ ]/;
+ twttr.txt.regexen.validMentionOrList = regexSupplant(
+ '(#{validMentionPrecedingChars})' + // $1: Preceding character
+ '(#{atSigns})' + // $2: At mark
+ '([a-zA-Z0-9_]{1,20})' + // $3: Screen name
+ '(\/[a-zA-Z][a-zA-Z0-9_\-]{0,24})?' // $4: List (optional)
+ , 'g');
+ twttr.txt.regexen.validReply = regexSupplant(/^(?:#{spaces})*#{atSigns}([a-zA-Z0-9_]{1,20})/);
+@@ -247,40 +177,120 @@ var window = {};
+
+ // URL related regex collection
+ twttr.txt.regexen.validUrlPrecedingChars = regexSupplant(/(?:[^A-Za-z0-9@ï¼ $#ï¼?#{invalid_chars_group}]|^)/);
+ twttr.txt.regexen.invalidUrlWithoutProtocolPrecedingChars = /[-_.\/]$/;
+ twttr.txt.regexen.invalidDomainChars = stringSupplant("#{punct}#{spaces_group}#{invalid_chars_group}", twttr.txt.regexen);
+ twttr.txt.regexen.validDomainChars = regexSupplant(/[^#{invalidDomainChars}]/);
+ twttr.txt.regexen.validSubdomain = regexSupplant(/(?:(?:#{validDomainChars}(?:[_-]|#{validDomainChars})*)?#{validDomainChars}\.)/);
+ twttr.txt.regexen.validDomainName = regexSupplant(/(?:(?:#{validDomainChars}(?:-|#{validDomainChars})*)?#{validDomainChars}\.)/);
+- twttr.txt.regexen.validGTLD = regexSupplant(/(?:(?:aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|xxx)(?=[^0-9a-zA-Z]|$))/);
++ twttr.txt.regexen.validGTLD = regexSupplant(RegExp(
++ '(?:(?:' +
++ 'abb|abbott|abogado|academy|accenture|accountant|accountants|aco|active|actor|ads|adult|aeg|aero|' +
++ 'afl|agency|aig|airforce|airtel|allfinanz|alsace|amsterdam|android|apartments|app|aquarelle|' +
++ 'archi|army|arpa|asia|associates|attorney|auction|audio|auto|autos|axa|azure|band|bank|bar|' +
++ 'barcelona|barclaycard|barclays|bargains|bauhaus|bayern|bbc|bbva|bcn|beer|bentley|berlin|best|' +
++ 'bet|bharti|bible|bid|bike|bing|bingo|bio|biz|black|blackfriday|bloomberg|blue|bmw|bnl|' +
++ 'bnpparibas|boats|bond|boo|boots|boutique|bradesco|bridgestone|broker|brother|brussels|budapest|' +
++ 'build|builders|business|buzz|bzh|cab|cafe|cal|camera|camp|cancerresearch|canon|capetown|capital|' +
++ 'caravan|cards|care|career|careers|cars|cartier|casa|cash|casino|cat|catering|cba|cbn|ceb|center|' +
++ 'ceo|cern|cfa|cfd|chanel|channel|chat|cheap|chloe|christmas|chrome|church|cisco|citic|city|' +
++ 'claims|cleaning|click|clinic|clothing|cloud|club|coach|codes|coffee|college|cologne|com|' +
++ 'commbank|community|company|computer|condos|construction|consulting|contractors|cooking|cool|' +
++ 'coop|corsica|country|coupons|courses|credit|creditcard|cricket|crown|crs|cruises|cuisinella|' +
++ 'cymru|cyou|dabur|dad|dance|date|dating|datsun|day|dclk|deals|degree|delivery|delta|democrat|' +
++ 'dental|dentist|desi|design|dev|diamonds|diet|digital|direct|directory|discount|dnp|docs|dog|' +
++ 'doha|domains|doosan|download|drive|durban|dvag|earth|eat|edu|education|email|emerck|energy|' +
++ 'engineer|engineering|enterprises|epson|equipment|erni|esq|estate|eurovision|eus|events|everbank|' +
++ 'exchange|expert|exposed|express|fage|fail|faith|family|fan|fans|farm|fashion|feedback|film|' +
++ 'finance|financial|firmdale|fish|fishing|fit|fitness|flights|florist|flowers|flsmidth|fly|foo|' +
++ 'football|forex|forsale|forum|foundation|frl|frogans|fund|furniture|futbol|fyi|gal|gallery|game|' +
++ 'garden|gbiz|gdn|gent|genting|ggee|gift|gifts|gives|giving|glass|gle|global|globo|gmail|gmo|gmx|' +
++ 'gold|goldpoint|golf|goo|goog|google|gop|gov|graphics|gratis|green|gripe|group|guge|guide|' +
++ 'guitars|guru|hamburg|hangout|haus|healthcare|help|here|hermes|hiphop|hitachi|hiv|hockey|' +
++ 'holdings|holiday|homedepot|homes|honda|horse|host|hosting|hoteles|hotmail|house|how|hsbc|ibm|' +
++ 'icbc|ice|icu|ifm|iinet|immo|immobilien|industries|infiniti|info|ing|ink|institute|insure|int|' +
++ 'international|investments|ipiranga|irish|ist|istanbul|itau|iwc|java|jcb|jetzt|jewelry|jlc|jll|' +
++ 'jobs|joburg|jprs|juegos|kaufen|kddi|kim|kitchen|kiwi|koeln|komatsu|krd|kred|kyoto|lacaixa|' +
++ 'lancaster|land|lasalle|lat|latrobe|law|lawyer|lds|lease|leclerc|legal|lexus|lgbt|liaison|lidl|' +
++ 'life|lighting|limited|limo|link|live|lixil|loan|loans|lol|london|lotte|lotto|love|ltda|lupin|' +
++ 'luxe|luxury|madrid|maif|maison|man|management|mango|market|marketing|markets|marriott|mba|media|' +
++ 'meet|melbourne|meme|memorial|men|menu|miami|microsoft|mil|mini|mma|mobi|moda|moe|mom|monash|' +
++ 'money|montblanc|mormon|mortgage|moscow|motorcycles|mov|movie|movistar|mtn|mtpc|museum|nadex|' +
++ 'nagoya|name|navy|nec|net|netbank|network|neustar|new|news|nexus|ngo|nhk|nico|ninja|nissan|nokia|' +
++ 'nra|nrw|ntt|nyc|office|okinawa|omega|one|ong|onl|online|ooo|oracle|orange|org|organic|osaka|' +
++ 'otsuka|ovh|page|panerai|paris|partners|parts|party|pet|pharmacy|philips|photo|photography|' +
++ 'photos|physio|piaget|pics|pictet|pictures|pink|pizza|place|play|plumbing|plus|pohl|poker|porn|' +
++ 'post|praxi|press|pro|prod|productions|prof|properties|property|pub|qpon|quebec|racing|realtor|' +
++ 'realty|recipes|red|redstone|rehab|reise|reisen|reit|ren|rent|rentals|repair|report|republican|' +
++ 'rest|restaurant|review|reviews|rich|ricoh|rio|rip|rocks|rodeo|rsvp|ruhr|run|ryukyu|saarland|' +
++ 'sakura|sale|samsung|sandvik|sandvikcoromant|sanofi|sap|sarl|saxo|sca|scb|schmidt|scholarships|' +
++ 'school|schule|schwarz|science|scor|scot|seat|seek|sener|services|sew|sex|sexy|shiksha|shoes|' +
++ 'show|shriram|singles|site|ski|sky|skype|sncf|soccer|social|software|sohu|solar|solutions|sony|' +
++ 'soy|space|spiegel|spreadbetting|srl|starhub|statoil|studio|study|style|sucks|supplies|supply|' +
++ 'support|surf|surgery|suzuki|swatch|swiss|sydney|systems|taipei|tatamotors|tatar|tattoo|tax|taxi|' +
++ 'team|tech|technology|tel|telefonica|temasek|tennis|thd|theater|tickets|tienda|tips|tires|tirol|' +
++ 'today|tokyo|tools|top|toray|toshiba|tours|town|toyota|toys|trade|trading|training|travel|trust|' +
++ 'tui|ubs|university|uno|uol|vacations|vegas|ventures|vermögensberater|vermögensberatung|' +
++ 'versicherung|vet|viajes|video|villas|vin|vision|vista|vistaprint|vlaanderen|vodka|vote|voting|' +
++ 'voto|voyage|wales|walter|wang|watch|webcam|website|wed|wedding|weir|whoswho|wien|wiki|' +
++ 'williamhill|win|windows|wine|wme|work|works|world|wtc|wtf|xbox|xerox|xin|xperia|xxx|xyz|yachts|' +
++ 'yandex|yodobashi|yoga|yokohama|youtube|zip|zone|zuerich|деÑ?и|ком|моÑ?ква|онлайн|оÑ?г|Ñ?Ñ?Ñ?|Ñ?айÑ?|ק×?×?|' +
++ 'بازار|شبÙ?Ø©|Ù?Ù?Ù?|Ù?Ù?Ù?ع|à¤?à¥?म|नà¥?à¤?|सà¤?à¤?ठन|à¸?à¸à¸¡|ã?¿ã??ã?ª|ã?°ã?¼ã?°ã?«|ã?³ã? |ä¸?ç??|ä¸ä¿¡|ä¸æ??ç½?|ä¼?ä¸?|ä½?å±±|ä¿¡æ?¯|å?¥åº·|å?«å?¦|å?¬å?¸|å?¬ç??|å??å??|å??åº?|å??æ ?|å?¨çº¿|大æ?¿|' +
++ '娱ä¹?|å·¥è¡?|广ä¸?|æ??å??|æ??ç?±ä½ |æ??æ?º|æ?¿å?¡|æ?¿åº?|æ?°é?»|æ?¶å°?|æ?ºæ??|淡马é?¡|游æ??|ç?¹ç??|移å?¨|ç»?ç»?æ?ºæ??|ç½?å??|ç½?åº?|ç½?ç»?|è°·æ?|é??å?¢|é£?å?©æµ¦|é¤?å??|ë?·ë?·|ë?·ì»´|ì?¼ì?±|onion' +
++ ')(?=[^0-9a-zA-Z@]|$))'));
+ twttr.txt.regexen.validCCTLD = regexSupplant(RegExp(
+- "(?:(?:ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|" +
+- "ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|" +
+- "ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|" +
+- "ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|" +
+- "na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|" +
+- "sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|" +
+- "ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)(?=[^0-9a-zA-Z]|$))"));
++ '(?:(?:' +
++ 'ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bl|bm|bn|bo|bq|' +
++ 'br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|' +
++ 'ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|' +
++ 'gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|' +
++ 'la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mf|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|' +
++ 'my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|' +
++ 'rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|' +
++ 'tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw|ελ|' +
++ 'бел|мкд|мон|Ñ?Ñ?|Ñ?Ñ?б|Ñ?кÑ?|Ò?аз|Õ°Õ¡Õµ|اÙ?اردÙ?|اÙ?جزائر|اÙ?سعÙ?دÙ?Ø©|اÙ?Ù?غرب|اÙ?ارات|اÛ?راÙ?|بھارت|تÙ?Ù?س|سÙ?داÙ?|' +
++ 'سÙ?رÙ?Ø©|عراÙ?|عÙ?اÙ?|Ù?Ù?سطÙ?Ù?|Ù?طر|Ù?صر|Ù?Ù?Ù?سÙ?ا|پاکستاÙ?|à¤à¤¾à¤°à¤¤|বাà¦?লা|à¦à¦¾à¦°à¦¤|à¨à¨¾à¨°à¨¤|àªàª¾àª°àª¤|à®?நà¯?தியா|à®?லà®?à¯?à®?à¯?|' +
++ 'à®?ிà®?à¯?à®?பà¯?பà¯?à®°à¯?|à°à°¾à°°à°¤à±?|ලà¶?à¶?à·?|à¹?à¸?ย|á??á??|ä¸å?½|ä¸å??|å?°æ¹¾|å?°ç?£|æ?°å? å?¡|æ¾³é??|é¦?港|í??êµ' +
++ ')(?=[^0-9a-zA-Z@]|$))'));
+ twttr.txt.regexen.validPunycode = regexSupplant(/(?:xn--[0-9a-z]+)/);
++ twttr.txt.regexen.validSpecialCCTLD = regexSupplant(RegExp(
++ '(?:(?:co|tv)(?=[^0-9a-zA-Z@]|$))'));
+ twttr.txt.regexen.validDomain = regexSupplant(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/);
+ twttr.txt.regexen.validAsciiDomain = regexSupplant(/(?:(?:[\-a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi);
+- twttr.txt.regexen.invalidShortDomain = regexSupplant(/^#{validDomainName}#{validCCTLD}$/);
++ twttr.txt.regexen.invalidShortDomain = regexSupplant(/^#{validDomainName}#{validCCTLD}$/i);
++ twttr.txt.regexen.validSpecialShortDomain = regexSupplant(/^#{validDomainName}#{validSpecialCCTLD}$/i);
+
+ twttr.txt.regexen.validPortNumber = regexSupplant(/[0-9]+/);
+
+- twttr.txt.regexen.validGeneralUrlPathChars = regexSupplant(/[a-z0-9!\*';:=\+,\.\$\/%#\[\]\-_~@|&#{latinAccentChars}]/i);
+- // Allow URL paths to contain balanced parens
++ twttr.txt.regexen.cyrillicLettersAndMarks = regexSupplant("\u0400-\u04FF");
++ twttr.txt.regexen.validGeneralUrlPathChars = regexSupplant(/[a-z#{cyrillicLettersAndMarks}0-9!\*';:=\+,\.\$\/%#\[\]\-_~@\|&#{latinAccentChars}]/i);
++ // Allow URL paths to contain up to two nested levels of balanced parens
+ // 1. Used in Wikipedia URLs like /Primer_(film)
+ // 2. Used in IIS sessions like /S(dfd346)/
+- twttr.txt.regexen.validUrlBalancedParens = regexSupplant(/\(#{validGeneralUrlPathChars}+\)/i);
++ // 3. Used in Rdio URLs like /track/We_Up_(Album_Version_(Edited))/
++ twttr.txt.regexen.validUrlBalancedParens = regexSupplant(
++ '\\(' +
++ '(?:' +
++ '#{validGeneralUrlPathChars}+' +
++ '|' +
++ // allow one nested level of balanced parentheses
++ '(?:' +
++ '#{validGeneralUrlPathChars}*' +
++ '\\(' +
++ '#{validGeneralUrlPathChars}+' +
++ '\\)' +
++ '#{validGeneralUrlPathChars}*' +
++ ')' +
++ ')' +
++ '\\)'
++ , 'i');
+ // Valid end-of-path chracters (so /foo. does not gobble the period).
+ // 1. Allow =&# for empty URL parameters and other URL-join artifacts
+- twttr.txt.regexen.validUrlPathEndingChars = regexSupplant(/[\+\-a-z0-9=_#\/#{latinAccentChars}]|(?:#{validUrlBalancedParens})/i);
++ twttr.txt.regexen.validUrlPathEndingChars = regexSupplant(/[\+\-a-z#{cyrillicLettersAndMarks}0-9=_#\/#{latinAccentChars}]|(?:#{validUrlBalancedParens})/i);
+ // Allow @ in a url, but only in the middle. Catch things like http://example.com/@user/
+ twttr.txt.regexen.validUrlPath = regexSupplant('(?:' +
+ '(?:' +
+ '#{validGeneralUrlPathChars}*' +
+ '(?:#{validUrlBalancedParens}#{validGeneralUrlPathChars}*)*' +
+ '#{validUrlPathEndingChars}'+
+ ')|(?:@#{validGeneralUrlPathChars}+\/)'+
+ ')', 'i');
+@@ -304,17 +314,17 @@ var window = {};
+ twttr.txt.regexen.urlHasProtocol = /^https?:\/\//i;
+ twttr.txt.regexen.urlHasHttps = /^https:\/\//i;
+
+ // cashtag related regex
+ twttr.txt.regexen.cashtag = /[a-z]{1,6}(?:[._][a-z]{1,2})?/i;
+ twttr.txt.regexen.validCashtag = regexSupplant('(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}])', 'gi');
+
+ // These URL validation pattern strings are based on the ABNF from RFC 3986
+- twttr.txt.regexen.validateUrlUnreserved = /[a-z0-9\-._~]/i;
++ twttr.txt.regexen.validateUrlUnreserved = /[a-z\u0400-\u04FF0-9\-._~]/i;
+ twttr.txt.regexen.validateUrlPctEncoded = /(?:%[0-9a-f]{2})/i;
+ twttr.txt.regexen.validateUrlSubDelims = /[!$&'()*+,;=]/i;
+ twttr.txt.regexen.validateUrlPchar = regexSupplant('(?:' +
+ '#{validateUrlUnreserved}|' +
+ '#{validateUrlPctEncoded}|' +
+ '#{validateUrlSubDelims}|' +
+ '[:|@]' +
+ ')', 'i');
+@@ -473,17 +483,17 @@ var window = {};
+
+ twttr.txt.linkToHashtag = function(entity, text, options) {
+ var hash = text.substring(entity.indices[0], entity.indices[0] + 1);
+ var hashtag = twttr.txt.htmlEscape(entity.hashtag);
+ var attrs = clone(options.htmlAttrs || {});
+ attrs.href = options.hashtagUrlBase + hashtag;
+ attrs.title = "#" + hashtag;
+ attrs["class"] = options.hashtagClass;
+- if (hashtag[0].match(twttr.txt.regexen.rtl_chars)){
++ if (hashtag.charAt(0).match(twttr.txt.regexen.rtl_chars)){
+ attrs["class"] += " rtl";
+ }
+ if (options.targetBlank) {
+ attrs.target = '_blank';
+ }
+
+ return twttr.txt.linkToTextWithSymbol(entity, hash, hashtag, attrs, options);
+ };
+@@ -678,32 +688,44 @@ var window = {};
+ }
+ beginIndex = entity.indices[1];
+ }
+ result += nonEntity(text.substring(beginIndex, text.length));
+ return result;
+ };
+
+ twttr.txt.autoLinkWithJSON = function(text, json, options) {
++ // map JSON entity to twitter-text entity
++ if (json.user_mentions) {
++ for (var i = 0; i < json.user_mentions.length; i++) {
++ // this is a @mention
++ json.user_mentions[i].screenName = json.user_mentions[i].screen_name;
++ }
++ }
++
++ if (json.hashtags) {
++ for (var i = 0; i < json.hashtags.length; i++) {
++ // this is a #hashtag
++ json.hashtags[i].hashtag = json.hashtags[i].text;
++ }
++ }
++
++ if (json.symbols) {
++ for (var i = 0; i < json.symbols.length; i++) {
++ // this is a $CASH tag
++ json.symbols[i].cashtag = json.symbols[i].text;
++ }
++ }
++
+ // concatenate all entities
+ var entities = [];
+ for (var key in json) {
+ entities = entities.concat(json[key]);
+ }
+- // map JSON entity to twitter-text entity
+- for (var i = 0; i < entities.length; i++) {
+- entity = entities[i];
+- if (entity.screen_name) {
+- // this is @mention
+- entity.screenName = entity.screen_name;
+- } else if (entity.text) {
+- // this is #hashtag
+- entity.hashtag = entity.text;
+- }
+- }
++
+ // modify indices to UTF-16
+ twttr.txt.modifyIndicesFromUnicodeToUTF16(text, entities);
+
+ return twttr.txt.autoLinkEntities(text, entities, options);
+ };
+
+ twttr.txt.extractHtmlAttrsFromOptions = function(options) {
+ var htmlAttrs = {};
+@@ -856,17 +878,16 @@ var window = {};
+
+ return urlsOnly;
+ };
+
+ twttr.txt.extractUrlsWithIndices = function(text, options) {
+ if (!options) {
+ options = {extractUrlsWithoutProtocol: true};
+ }
+-
+ if (!text || (options.extractUrlsWithoutProtocol ? !text.match(/\./) : !text.match(/:/))) {
+ return [];
+ }
+
+ var urls = [];
+
+ while (twttr.txt.regexen.extractUrl.exec(text)) {
+ var before = RegExp.$2, url = RegExp.$3, protocol = RegExp.$4, domain = RegExp.$5, path = RegExp.$7;
+@@ -876,41 +897,38 @@ var window = {};
+ // if protocol is missing and domain contains non-ASCII characters,
+ // extract ASCII-only domains.
+ if (!protocol) {
+ if (!options.extractUrlsWithoutProtocol
+ || before.match(twttr.txt.regexen.invalidUrlWithoutProtocolPrecedingChars)) {
+ continue;
+ }
+ var lastUrl = null,
+- lastUrlInvalidMatch = false,
+ asciiEndPosition = 0;
+ domain.replace(twttr.txt.regexen.validAsciiDomain, function(asciiDomain) {
+ var asciiStartPosition = domain.indexOf(asciiDomain, asciiEndPosition);
+ asciiEndPosition = asciiStartPosition + asciiDomain.length;
+ lastUrl = {
+ url: asciiDomain,
+ indices: [startPosition + asciiStartPosition, startPosition + asciiEndPosition]
+ };
+- lastUrlInvalidMatch = asciiDomain.match(twttr.txt.regexen.invalidShortDomain);
+- if (!lastUrlInvalidMatch) {
++ if (path
++ || asciiDomain.match(twttr.txt.regexen.validSpecialShortDomain)
++ || !asciiDomain.match(twttr.txt.regexen.invalidShortDomain)) {
+ urls.push(lastUrl);
+ }
+ });
+
+ // no ASCII-only domain found. Skip the entire URL.
+ if (lastUrl == null) {
+ continue;
+ }
+
+ // lastUrl only contains domain. Need to add path and query if they exist.
+ if (path) {
+- if (lastUrlInvalidMatch) {
+- urls.push(lastUrl);
+- }
+ lastUrl.url = url.replace(domain, lastUrl.url);
+ lastUrl.indices[1] = endPosition;
+ }
+ } else {
+ // In the case of t.co URLs, don't allow additional path characters.
+ if (url.match(twttr.txt.regexen.validTcoUrl)) {
+ url = RegExp.lastMatch;
+ endPosition = startPosition + url.length;
+@@ -1194,30 +1212,30 @@ var window = {};
+
+ // Returns the length of Tweet text with consideration to t.co URL replacement
+ // and chars outside the basic multilingual plane that use 2 UTF16 code points
+ twttr.txt.getTweetLength = function(text, options) {
+ if (!options) {
+ options = {
+ // These come from https://api.twitter.com/1/help/configuration.json
+ // described by https://dev.twitter.com/docs/api/1/get/help/configuration
+- short_url_length: 22,
++ short_url_length: 23,
+ short_url_length_https: 23
+ };
+ }
+ var textLength = twttr.txt.getUnicodeTextLength(text),
+ urlsWithIndices = twttr.txt.extractUrlsWithIndices(text);
+ twttr.txt.modifyIndicesFromUTF16ToUnicode(text, urlsWithIndices);
+
+ for (var i = 0; i < urlsWithIndices.length; i++) {
+- // Subtract the length of the original URL
++ // Subtract the length of the original URL
+ textLength += urlsWithIndices[i].indices[0] - urlsWithIndices[i].indices[1];
+
+ // Add 23 characters for URL starting with https://
+- // Otherwise add 22 characters
++ // http:// URLs still use https://t.co so they are 23 characters as well
+ if (urlsWithIndices[i].url.toLowerCase().match(twttr.txt.regexen.urlHasHttps)) {
+ textLength += options.short_url_length_https;
+ } else {
+ textLength += options.short_url_length;
+ }
+ }
+
+ return textLength;
+@@ -1237,22 +1255,29 @@ var window = {};
+ return "empty";
+ }
+
+ // Determine max length independent of URL length
+ if (twttr.txt.getTweetLength(text) > MAX_LENGTH) {
+ return "too_long";
+ }
+
++ if (twttr.txt.hasInvalidCharacters(text)) {
++ return "invalid_characters";
++ }
++
++ return false;
++ };
++
++ twttr.txt.hasInvalidCharacters = function(text) {
+ for (var i = 0; i < INVALID_CHARACTERS.length; i++) {
+ if (text.indexOf(INVALID_CHARACTERS[i]) >= 0) {
+- return "invalid_characters";
++ return true;
+ }
+ }
+-
+ return false;
+ };
+
+ twttr.txt.isValidTweetText = function(text) {
+ return !twttr.txt.isInvalidTweet(text);
+ };
+
+ twttr.txt.isValidUsername = function(username) {
+@@ -1334,16 +1359,20 @@ var window = {};
+ // RegExp["$&"] is the text of the last match
+ return (!string || (string.match(regex) && RegExp["$&"] === string));
+ }
+
+ if (typeof module != 'undefined' && module.exports) {
+ module.exports = twttr.txt;
+ }
+
++ if (typeof define == 'function' && define.amd) {
++ define([], twttr.txt);
++ }
++
+ if (typeof window != 'undefined') {
+ if (window.twttr) {
+ for (var prop in twttr) {
+ window.twttr[prop] = twttr[prop];
+ }
+ } else {
+ window.twttr = twttr;
+ }
+diff --git a/chat/protocols/twitter/twitter.js b/chat/protocols/twitter/twitter.js
+--- a/chat/protocols/twitter/twitter.js
++++ b/chat/protocols/twitter/twitter.js
+@@ -31,32 +31,41 @@ ChatBuddy.prototype = {
+ let userInfo = this._account._userInfo.get(this.name);
+ if (userInfo)
+ return userInfo.profile_image_url;
+ return undefined;
+ },
+ set buddyIconFilename(aName) {
+ // Prevent accidental removal of the getter.
+ throw("Don't set chatBuddy.buddyIconFilename directly for Twitter.");
++ },
++ createConversation: function() {
++ return this._account.createConversation(this._name);
+ }
+-}
++};
+
+ function Tweet(aTweet, aWho, aMessage, aObject)
+ {
+ this._tweet = aTweet;
+ this._init(aWho, aMessage, aObject);
+ }
+ Tweet.prototype = {
+ __proto__: GenericMessagePrototype,
+ _deleted: false,
+ getActions: function(aCount) {
+ let account = this.conversation._account;
+ let actions = [];
+
+- if (account.connected) {
++ // TODO(arlolra): DirectMessageConversation actions.
++ if (!this.conversation.isChat) {
++ if (aCount)
++ aCount.value = actions.length;
++ return actions;
++ }
++ else if (account.connected) {
+ actions.push(
+ new Action(_("action.reply"), function() {
+ this.conversation.startReply(this._tweet);
+ }, this)
+ );
+ if (this.incoming) {
+ actions.push(
+ new Action(_("action.retweet"), function() {
+@@ -118,17 +127,104 @@ function Action(aLabel, aAction, aTweet)
+ this._action = aAction;
+ this._tweet = aTweet;
+ }
+ Action.prototype = {
+ __proto__: ClassInfo("prplIMessageAction", "generic message action object"),
+ get run() { return this._action.bind(this._tweet); }
+ };
+
+-function Conversation(aAccount)
++// Properties / methods shared by both DirectMessageConversation and
++// TimelineConversation.
++var GenericTwitterConversation = {
++ getTweetLength: function (aString) {
++ // Use the Twitter library to calculate the length.
++ return twttr.txt.getTweetLength(aString, this._account.config);
++ },
++ systemMessage: function(aMessage, aIsError, aDate) {
++ let flags = {system: true};
++ if (aIsError)
++ flags.error = true;
++ if (aDate)
++ flags.time = aDate;
++ this.writeMessage("twitter.com", aMessage, flags);
++ },
++ onSentCallback: function(aMsg, aData) {
++ let tweet = JSON.parse(aData);
++ // The OTR extension requires that the protocol not modify the message
++ // (see the notes at `imIOutgoingMessage`). That's the contract we made.
++ // Unfortunately, Twitter trims tweets and substitutes links.
++ tweet.text = aMsg;
++ this.displayMessages([tweet]);
++ },
++ prepareForDisplaying: function(aMsg) {
++ let text = aMsg.displayMessage;
++ let tweet = aMsg.wrappedJSObject.prplMessage.wrappedJSObject._tweet;
++
++ // Handle retweets: retweeted_status contains the object for the original
++ // tweet that is being retweeted.
++ // If the retweet prefix ("RT @<username>: ") causes the tweet to be over
++ // 140 characters, ellipses will be added. In this case, we want to get
++ // the FULL text from the original tweet and update the entities to match.
++ // Note: the truncated flag is not always set correctly by twitter, so we
++ // always make use of the original tweet.
++ if ("retweeted_status" in tweet) {
++ let retweet = tweet["retweeted_status"];
++ // We're going to take portions of the retweeted status and replace parts
++ // of the original tweet, the retweeted status prepends the original
++ // status with "RT @<username>: ", we need to keep the prefix.
++ // Note: this doesn't play nice with extensions that may have altered
++ // `text` to this point, but at least OTR doesn't act on `isChat`.
++ let offset = text.indexOf(": ") + 2;
++ text = text.slice(0, offset) + retweet.text;
++ }
++
++ // Pass in the url entities so the t.co links are replaced.
++ aMsg.displayMessage = twttr.txt.autoLink(text, {
++ urlEntities: tweet.entities.urls.map(function(u) {
++ var o = Object.assign(u);
++ // But remove the indices so they apply in the face of modifications.
++ delete o.indices;
++ return o;
++ })
++ });
++
++ GenericConversationPrototype.prepareForDisplaying.apply(this, arguments);
++ },
++ displayTweet: function(aTweet, aUser) {
++ let name = aUser.screen_name;
++
++ let flags = name == this.nick ? {outgoing: true} : {incoming: true};
++ flags.time = Math.round(new Date(aTweet.created_at) / 1000);
++ flags._iconURL = aUser.profile_image_url;
++ if (aTweet.delayed)
++ flags.delayed = true;
++ if (aTweet.entities && aTweet.entities.user_mentions &&
++ Array.isArray(aTweet.entities.user_mentions) &&
++ aTweet.entities.user_mentions.some(mention => mention.screen_name == this.nick))
++ flags.containsNick = true;
++
++ (new Tweet(aTweet, name, aTweet.text, flags)).conversation = this;
++ },
++ _parseError: function(aData) {
++ let error = "";
++ try {
++ let data = JSON.parse(aData);
++ if ("error" in data)
++ error = data.error;
++ else if ("errors" in data)
++ error = data.errors[0].message;
++ if (error)
++ error = "(" + error + ")";
++ } catch(e) {}
++ return error;
++ }
++};
++
++function TimelineConversation(aAccount)
+ {
+ this._init(aAccount);
+ this._ensureParticipantExists(aAccount.name);
+ // We need the screen names for the IDs in _friends, but _userInfo is
+ // indexed by name, so we build an ID -> name map.
+ let entries = [];
+ for (let [name, userInfo] of aAccount._userInfo) {
+ entries.push([userInfo.id_str, name]);
+@@ -139,17 +235,17 @@ function Conversation(aAccount)
+
+ // If the user's info has already been received, update the timeline topic.
+ if (aAccount._userInfo.has(aAccount.name)) {
+ let userInfo = aAccount._userInfo.get(aAccount.name);
+ if ("description" in userInfo)
+ this.setTopic(userInfo.description, aAccount.name, true);
+ }
+ }
+-Conversation.prototype = {
++TimelineConversation.prototype = {
+ __proto__: GenericConvChatPrototype,
+ unInit: function() {
+ delete this._account._timeline;
+ GenericConvChatPrototype.unInit.call(this);
+ },
+ inReplyToStatusId: null,
+ startReply: function(aTweet) {
+ this.inReplyToStatusId = aTweet.id_str;
+@@ -169,203 +265,66 @@ Conversation.prototype = {
+ .map(aNick => "@" + aNick)
+ .join(" ") + " ";
+
+ this.notifyObservers(null, "replying-to-prompt", prompt);
+ this.notifyObservers(null, "status-text-changed",
+ _("replyingToStatusText", aTweet.text));
+ },
+ reTweet: function(aTweet) {
+- this._account.reTweet(aTweet, this.onSentCallback,
+- function(aException, aData) {
++ this._account.reTweet(aTweet, null, function(aException, aData) {
+ this.systemMessage(_("error.retweet", this._parseError(aData),
+ aTweet.text), true);
+ }, this);
+ },
+- getTweetLength: function (aString) {
+- // Use the Twitter library to calculate the length.
+- return twttr.txt.getTweetLength(aString, this._account.config);
+- },
+- sendMsg: function (aMsg) {
++ sendMsg: function(aMsg) {
+ if (this.getTweetLength(aMsg) > kMaxMessageLength) {
+ this.systemMessage(_("error.tooLong"), true);
+ throw Cr.NS_ERROR_INVALID_ARG;
+ }
+- this._account.tweet(aMsg, this.inReplyToStatusId, this.onSentCallback,
++ this._account.tweet(aMsg, this.inReplyToStatusId,
++ this.onSentCallback.bind(this, aMsg),
+ function(aException, aData) {
+ let error = this._parseError(aData);
+ this.systemMessage(_("error.general", error, aMsg), true);
+ }, this);
+ this.sendTyping("");
+ },
+ sendTyping: function(aString) {
+ if (aString.length == 0 && this.inReplyToStatusId) {
+ delete this.inReplyToStatusId;
+ this.notifyObservers(null, "status-text-changed", "");
+ return kMaxMessageLength;
+ }
+ return kMaxMessageLength - this.getTweetLength(aString);
+ },
+- systemMessage: function(aMessage, aIsError, aDate) {
+- let flags = {system: true};
+- if (aIsError)
+- flags.error = true;
+- if (aDate)
+- flags.time = aDate;
+- this.writeMessage("twitter.com", aMessage, flags);
+- },
+- onSentCallback: function(aData) {
+- let tweet = JSON.parse(aData);
+- if (tweet.user.screen_name != this._account.name)
+- throw "Wrong screen_name... Uh?";
+- this._account.displayMessages([tweet]);
+- },
+- _parseError: function(aData) {
+- let error = "";
+- try {
+- let data = JSON.parse(aData);
+- if ("error" in data)
+- error = data.error;
+- else if ("errors" in data)
+- error = data.errors[0].message;
+- if (error)
+- error = "(" + error + ")";
+- } catch(e) {}
+- return error;
+- },
+- parseTweet: function(aTweet) {
+- let text = aTweet.text;
+- let entities = {};
+- // Handle retweets: retweeted_status contains the object for the original
+- // tweet that is being retweeted.
+- // If the retweet prefix ("RT @<username>: ") causes the tweet to be over
+- // 140 characters, ellipses will be added. In this case, we want to get
+- // the FULL text from the original tweet and update the entities to match.
+- // Note: the truncated flag is not always set correctly by twitter, so we
+- // always make use of the original tweet.
+- if ("retweeted_status" in aTweet) {
+- let retweet = aTweet["retweeted_status"];
+- // We're going to take portions of the retweeted status and replace parts
+- // of the original tweet, the retweeted status prepends the original
+- // status with "RT @<username>: ", we need to keep the prefix.
+- let offset = text.indexOf(": ") + 2;
+- text = text.slice(0, offset) + retweet.text;
++ displayMessages: function(aMessages) {
++ let account = this._account;
++ let lastMsgId = account._lastMsgId;
++ for (let tweet of aMessages) {
++ if (!("user" in tweet) || !("text" in tweet) || !("id_str" in tweet) ||
++ account._knownMessageIds.has(tweet.id_str))
++ continue;
++ let id = tweet.id_str;
++ // Update the last known message.
++ // Compare the length of the ids first, and then the text.
++ // This avoids converting tweet ids into rounded numbers.
++ if (id.length > lastMsgId.length ||
++ (id.length == lastMsgId.length && id > lastMsgId))
++ lastMsgId = id;
++ account._knownMessageIds.add(id);
++ account.setUserInfo(tweet.user);
+
+- // Keep any entities that refer to the prefix (we can refer directly to
+- // aTweet for these since they are not edited).
+- if ("entities" in aTweet) {
+- for (let type in aTweet.entities) {
+- let filteredEntities =
+- aTweet.entities[type].filter(e => e.indices[0] < offset);
+- if (filteredEntities.length)
+- entities[type] = filteredEntities;
+- }
+- }
+-
+- // Add the entities from the retweet (a copy of these must be made since
+- // they will be edited and we do not wish to change aTweet).
+- if ("entities" in retweet) {
+- for (let type in retweet.entities) {
+- if (!(type in entities))
+- entities[type] = [];
+-
+- // Append the entities from the original status.
+- entities[type] = entities[type].concat(
+- retweet.entities[type].map(function(aEntity) {
+- let entity = Object.create(aEntity);
+- // Add the offset to the indices to account for the prefix.
+- entity.indices = entity.indices.map(i => i + offset);
+- return entity;
+- })
+- );
+- }
+- }
+- } else {
+- // For non-retweets, we just want to use the entities that are given.
+- if ("entities" in aTweet)
+- entities = aTweet.entities;
++ this._ensureParticipantExists(tweet.user.screen_name);
++ this.displayTweet(tweet, tweet.user);
+ }
+-
+- if (Object.keys(entities).length) {
+- /* entArray is an array of entities ready to be replaced in the tweet,
+- * each entity contains:
+- * - start: the start index of the entity inside the tweet,
+- * - end: the end index of the entity inside the tweet,
+- * - str: the string that should be replaced inside the tweet,
+- * - href: the url (href attribute) of the created link tag,
+- * - [optional] text: the text to display for the link,
+- * The original string (str) will be used if this is not set.
+- * - [optional] title: the title attribute for the link.
+- */
+- let entArray = [];
+- if ("hashtags" in entities && Array.isArray(entities.hashtags)) {
+- entArray = entArray.concat(entities.hashtags.map(h => ({
+- start: h.indices[0],
+- end: h.indices[1],
+- str: "#" + h.text,
+- href: "https://twitter.com/#!/search?q=%23" + h.text})));
+- }
+- if ("urls" in entities && Array.isArray(entities.urls)) {
+- entArray = entArray.concat(entities.urls.map(u => ({
+- start: u.indices[0],
+- end: u.indices[1],
+- str: u.url,
+- text: u.display_url || u.url,
+- href: u.expanded_url || u.url})));
+- }
+- if ("user_mentions" in entities &&
+- Array.isArray(entities.user_mentions)) {
+- entArray = entArray.concat(entities.user_mentions.map(um => ({
+- start: um.indices[0],
+- end: um.indices[1],
+- str: "@" + um.screen_name,
+- text: '@<span class="ib-person">' + um.screen_name + "</span>",
+- title: um.name,
+- href: "https://twitter.com/" + um.screen_name})));
+- }
+- entArray.sort((a, b) => a.start - b.start);
+- let offset = 0;
+- for (let entity of entArray) {
+- let str = text.substring(offset + entity.start, offset + entity.end);
+- if (str[0] == "\uFF20") // ï¼ - unicode character similar to @
+- str = "@" + str.substring(1);
+- if (str[0] == "\uFF03") // ï¼? - unicode character similar to #
+- str = "#" + str.substring(1);
+- if (str.toLowerCase() != entity.str.toLowerCase())
+- continue;
+-
+- let html = "<a href=\"" + entity.href + "\"";
+- if ("title" in entity)
+- html += " title=\"" + entity.title + "\"";
+- html += ">" + ("text" in entity ? entity.text : entity.str) + "</a>";
+- text = text.slice(0, offset + entity.start) + html +
+- text.slice(offset + entity.end);
+- offset += html.length - (entity.end - entity.start);
+- }
++ if (lastMsgId != account._lastMsgId) {
++ account._lastMsgId = lastMsgId;
++ account.prefs.setCharPref("lastMessageId", account._lastMsgId);
+ }
+-
+- return text;
+- },
+- displayTweet: function(aTweet) {
+- let name = aTweet.user.screen_name;
+- this._ensureParticipantExists(name);
+- let text = this.parseTweet(aTweet);
+-
+- let flags =
+- name == this._account.name ? {outgoing: true} : {incoming: true};
+- flags.time = Math.round(new Date(aTweet.created_at) / 1000);
+- flags._iconURL = aTweet.user.profile_image_url;
+- if (aTweet.delayed)
+- flags.delayed = true;
+- if (aTweet.entities && aTweet.entities.user_mentions &&
+- Array.isArray(aTweet.entities.user_mentions) &&
+- aTweet.entities.user_mentions.some(mention => mention.screen_name == this.nick))
+- flags.containsNick = true;
+-
+- (new Tweet(aTweet, name, text, flags)).conversation = this;
+ },
+ _ensureParticipantExists: function(aNick) {
+ if (this._participants.has(aNick))
+ return;
+
+ let chatBuddy = new ChatBuddy(aNick, this._account);
+ this._participants.set(aNick, chatBuddy);
+ this.notifyObservers(new nsSimpleEnumerator([chatBuddy]),
+@@ -377,23 +336,60 @@ Conversation.prototype = {
+ set nick(aNick) {},
+ get topicSettable() { return this.nick == this._account.name; },
+ get topic() { return this._topic; }, // can't add a setter without redefining the getter
+ set topic(aTopic) {
+ if (this.topicSettable)
+ this._account.setUserDescription(aTopic);
+ }
+ };
++Object.assign(TimelineConversation.prototype, GenericTwitterConversation);
++
++function DirectMessageConversation(aAccount, aName)
++{
++ this._init(aAccount, aName);
++}
++DirectMessageConversation.prototype = {
++ __proto__: GenericConvIMPrototype,
++ sendMsg: function(aMsg) {
++ this._account.directMessage(aMsg, this.name,
++ this.onSentCallback.bind(this, aMsg),
++ function(aException, aData) {
++ let error = this._parseError(aData);
++ this.systemMessage(_("error.general", error, aMsg), true);
++ }, this);
++ },
++ displayMessages: function(aMessages) {
++ // let account = this._account;
++ for (let tweet of aMessages) {
++ if (!("sender" in tweet) || !("recipient" in tweet) ||
++ !("text" in tweet) || !("id_str" in tweet))
++ continue;
++ // account.setUserInfo(tweet.sender);
++ // account.setUserInfo(tweet.recipient);
++ this.displayTweet(tweet, tweet.sender);
++ }
++ },
++ unInit: function() {
++ this._account.removeConversation(this.name);
++ GenericConvIMPrototype.unInit.call(this);
++ },
++ get nick() { return this._account.name; },
++ set nick(aNick) {}
++}
++Object.assign(DirectMessageConversation.prototype, GenericTwitterConversation);
+
+ function Account(aProtocol, aImAccount)
+ {
+ this._init(aProtocol, aImAccount);
+ this._knownMessageIds = new Set();
+ this._userInfo = new Map();
+ this._friends = new Set();
++ // Contains just `DirectMessageConversation`s
++ this._conversations = new Map();
+ }
+ Account.prototype = {
+ __proto__: GenericAccountPrototype,
+
+ // The correct normalization for twitter would be just toLowerCase().
+ // Unfortunately, for backwards compatibility we retain this normalization,
+ // which can cause edge cases for usernames with underscores.
+ normalize: aString => aString.replace(/[^a-z0-9]/gi, "").toLowerCase(),
+@@ -554,16 +550,21 @@ Account.prototype = {
+ reTweet: function(aTweet, aOnSent, aOnError, aThis) {
+ let url = "1.1/statuses/retweet/" + aTweet.id_str + ".json";
+ this.signAndSend(url, null, [], aOnSent, aOnError, aThis);
+ },
+ destroy: function(aTweet, aOnSent, aOnError, aThis) {
+ let url = "1.1/statuses/destroy/" + aTweet.id_str + ".json";
+ this.signAndSend(url, null, [], aOnSent, aOnError, aThis);
+ },
++ directMessage: function(aMsg, aName, aOnSent, aOnError, aThis) {
++ let POSTData = [["text", aMsg], ["screen_name", aName]];
++ this.signAndSend("1.1/direct_messages/new.json", null, POSTData, aOnSent,
++ aOnError, aThis);
++ },
+
+ _friends: null,
+ follow: function(aUserName) {
+ this.signAndSend("1.1/friendships/create.json", null,
+ [["screen_name", aUserName]]);
+ },
+ stopFollowing: function(aUserName) {
+ // friendships/destroy will return the user in case of success.
+@@ -615,39 +616,17 @@ Account.prototype = {
+ getParams = "?q=" + trackQuery + lastMsgParam + "&count=100";
+ let url = "1.1/search/tweets.json" + getParams;
+ this._pendingRequests.push(
+ this.signAndSend(url, null, null, this.onTimelineReceived,
+ this.onTimelineError, this, null));
+ }
+ },
+
+- get timeline() { return this._timeline || (this._timeline = new Conversation(this)); },
+- displayMessages: function(aMessages) {
+- let lastMsgId = this._lastMsgId;
+- for (let tweet of aMessages) {
+- if (!("user" in tweet) || !("text" in tweet) || !("id_str" in tweet) ||
+- this._knownMessageIds.has(tweet.id_str))
+- continue;
+- let id = tweet.id_str;
+- // Update the last known message.
+- // Compare the length of the ids first, and then the text.
+- // This avoids converting tweet ids into rounded numbers.
+- if (id.length > lastMsgId.length ||
+- (id.length == lastMsgId.length && id > lastMsgId))
+- lastMsgId = id;
+- this._knownMessageIds.add(id);
+- this.setUserInfo(tweet.user);
+- this.timeline.displayTweet(tweet);
+- }
+- if (lastMsgId != this._lastMsgId) {
+- this._lastMsgId = lastMsgId;
+- this.prefs.setCharPref("lastMessageId", this._lastMsgId);
+- }
+- },
++ get timeline() { return this._timeline || (this._timeline = new TimelineConversation(this)); },
+
+ onTimelineError: function(aError, aResponseText, aRequest) {
+ this.ERROR(aError);
+ if (aRequest.status == 401)
+ ++this._timelineAuthError;
+ this._doneWithTimelineRequest(aRequest);
+ },
+
+@@ -685,17 +664,17 @@ Account.prototype = {
+ this.reportConnected();
+
+ // If the conversation already exists, notify it we are back online.
+ if (this._timeline)
+ this._timeline.notifyObservers(this._timeline, "update-buddy-status");
+
+ this._timelineBuffer.sort(this.sortByDate);
+ this._timelineBuffer.forEach(aTweet => aTweet.delayed = true);
+- this.displayMessages(this._timelineBuffer);
++ this.timeline.displayMessages(this._timelineBuffer);
+
+ // Fetch userInfo for the user if we don't already have it.
+ this.requestBuddyInfo(this.name);
+
+ // Reset in case we get disconnected
+ delete this._timelineBuffer;
+ delete this._pendingRequests;
+
+@@ -747,18 +726,23 @@ Account.prototype = {
+ continue;
+ let msg;
+ try {
+ msg = JSON.parse(message);
+ } catch (e) {
+ this.ERROR(e + " while parsing " + message);
+ continue;
+ }
+- if ("text" in msg)
+- this.displayMessages([msg]);
++ if ("direct_message" in msg) {
++ let dm = msg["direct_message"];
++ if (dm.sender_screen_name !== this.name) // These are displayed on send.
++ this.getConversation(dm.sender_screen_name).displayMessages([dm]);
++ }
++ else if ("text" in msg)
++ this.timeline.displayMessages([msg]);
+ else if ("friends" in msg) {
+ // Filter out the IDs that info has already been received from (e.g. a
+ // tweet has been received as part of the timeline request).
+ let userInfoIds = new Set();
+ for (let userInfo of this._userInfo.values())
+ userInfoIds.add(userInfo.id_str);
+ let ids = msg.friends.filter(
+ aId => !userInfoIds.has(aId.toString()));
+@@ -1099,16 +1083,29 @@ Account.prototype = {
+ this.config = JSON.parse(aData);
+ },
+
+ // Allow us to reopen the timeline via the join chat menu.
+ get canJoinChat() { return true; },
+ joinChat: function(aComponents) {
+ // The 'timeline' getter opens a timeline conversation if none exists.
+ this.timeline;
++ },
++
++ getConversation: function(aName) {
++ if (!this._conversations.has(aName))
++ this._conversations.set(aName, new DirectMessageConversation(this, aName));
++ return this._conversations.get(aName);
++ },
++ removeConversation: function(aName) {
++ if (this._conversations.has(aName))
++ this._conversations.delete(aName);
++ },
++ createConversation: function(aName) {
++ return this.getConversation(aName);
+ }
+ };
+
+ // Shortcut to get the JavaScript account object.
+ function getAccount(aConv) { return aConv.wrappedJSObject._account; }
+
+ function TwitterProtocol() {
+ this.registerCommands();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits