Provide usernames without further data as more human-readable numbers

This commit is contained in:
Ian Gulliver
2014-05-10 22:26:19 +03:00
parent a912e973c3
commit 3f54bbf284
2 changed files with 13 additions and 1 deletions

View File

@@ -14,6 +14,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// We use long keys in many places. Provide a method to trim those down for
// human readability.
String.prototype.hashCode = function() {
var hash = 0;
for (i = 0; i < this.length; i++) {
var char = this.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return hash;
};
var cosmopolite = {};
cosmopolite.Client = function(opt_callbacks, opt_urlPrefix, opt_namespace) {

View File

@@ -73,7 +73,7 @@ var addMessage = function(message) {
var messageDiv = document.createElement('div');
messageDiv.innerHTML = (
(new Date(message['created'] * 1000)).toString() +
' &lt;' + message['sender'] + '&gt; ' +
' &lt;????-' + (Math.abs(message['sender'].hashCode()) % 10000) + '&gt; ' +
message['message']
);
messages.appendChild(messageDiv);