Commits

Nicolás Echániz committed 04d93fa

added one on one chat. other minor fixes.

Comments (0)

Files changed (7)

Binary file modified.

live/frontend_views.py

         if request.user:
             nickname = request.user.username
         channel = content_object
-        return chat_html(request, channel.slug, nickname=nickname, extra_context=req_context)
+        return chat_html(request, channel.name, nickname=nickname, extra_context=req_context)
     
 frontend.site.register_view(Channel, ChannelWindow)

live/templates/live/base.html

         margin: 0px;
     }
 
-    .guest{
+    .guest a {
         color: grey;
     }
 
-    .registered{
+    .registered a {
         color: green;
     }
 
-    .staff{
+    .staff a {
         color: orange;
     }
-    .superuser{
+    .superuser a {
         color: red;
     }
 

live/templates/live/chat.html

     throw new Error('Could not find XMLHttpRequest or an alternative.');
 };
 
+var participant_link = function (nickname, user_type){
+    if (nickname!=current_nickname){
+        return "<li class='participant "+ user_type +"' id='"+ nickname +"'><a onClick='invite(this.text);' href='{% url one_on_one role='host' channel_name=channel_name %}.."+ current_nickname +".."+ nickname +"' target='_blank'>"+ nickname +"</a></li>"
+    }
+    else{
+        return "<li class='participant "+ user_type +"' id='"+ nickname +"'>"+ nickname +"</li>"   
+    }
+}
 
 Shell = function(output, participants_list){
     var self = this
     self.participants_list = participants_list
     
     self.add_participant = function(nickname, user_type){
-        self.participants_list.innerHTML += "<li class='participant "+ user_type +"' id='"+ nickname +"'><a>"+ nickname +"</a></li>"   
+        self.participants_list.innerHTML += participant_link(nickname, user_type)
     }
 
     self.add_participants = function(participants){
     self.run_command = function(action, payload, nickname){
         if (action == 'join'){
             var user_type = payload
+            // update the participants list
             self.add_participant(nickname, user_type)
-// update the participants list
-            self.print(nickname +' {% trans "has joined this channel." %}')
+            if (nickname != current_nickname){
+                self.print(nickname +' {% trans "has joined this channel." %}')
+            }
         }
 
         else if (action == 'say'){
             self.print(payload, nickname)
         }
 
+        else if (action == 'invite'){
+            invited = payload
+            if (current_nickname == invited){
+                self.safe_print(nickname +" <a href='{% url one_on_one role='guest' channel_name=channel_name %}.."+ nickname +".."+ current_nickname +"' target='_blank'>{% trans 'has invited you to chat'%}</a>")
+            }
+        }
+
         else if (action == 'rename'){
             new_nickname = payload
             li = document.getElementById(nickname)
-            li.innerHTML = "<a>"+ new_nickname +"</a>"
+            li.innerHTML = participant_link(new_nickname, user_type)
             li.id = new_nickname
             if (nickname != new_nickname){
                 self.print(nickname +' {% trans "is now known as" %} '+ new_nickname +".")
         }
     }
 
+    self.safe_print = function(s) {
+        self.output.innerHTML +=  "<span class='message channel_message'>&rarr; " + s + "</span><br>"
+        if (chat_scroll){
+            self.output.scrollTop = self.output.scrollHeight
+        }
+    }
+
     self.format = function(expr)
     {
         var s = prettyprint(expr)
 
 var current_nickname = '{{ nickname }}'
 var channel_slug = '{{ channel_slug }}'
+var channel_name = '{{ channel_name }}'
 
 var just_entered = true
 var previous_nickname = ''
     channel_action('rename', new_nickname, previous_nickname)
 }
 
+var invite = function(nickname){
+    channel_action('invite', nickname, current_nickname)
+}
+
 var leave = function() {
     var xhr = createXHR()
     xhr.open('GET', '{% url kickme_from_channel channel_slug=channel_slug %}', false)
     xhr.send()
+//    stomp.reset()
 }
 
 var channel_action = function (action, payload, nickname){
 
 {% block content %}
 <div id="chat_container">
-    <div id="channel_name">{{ channel_name }}</div>
+    {% if not '..' in channel_name %}<div id="channel_name">{{ channel_name }}</div>{% endif %}
     <div id="change_name">
     {% trans "your name" %}: <input id="nickname" value="{{ nickname  }}" onKeyPress="previous_nickname = current_nickname; if(event.keyCode==13) change_nickname(this.value);"/>
     </div>
          onKeyPress="if (just_entered){ this.value=''; just_entered = false}; if(event.keyCode==13) user_message();"/>
     <label for="chat_scroll">{% trans "auto-scroll" %}</label>
         <input id="chat_scroll" type="checkbox" checked="checked"
-         onChange="chat_scroll = this.value;"/>
+         onChange="if (chat_scroll) chat_scroll = false; else chat_scroll = true;"/>
 
       </div>
     </div>

live/templates/live/manage.html

     <script>
 
 var manage_channel = "{{ manage_channel }}";
-var stomp_broker = "{{ STOMP_BROKER }}";
 var stomp_port = {{ STOMP_PORT }};
 
-if (stomp_broker=='rabbitmq'){
-  var subscribe_destination = '';
-  var subscribe_headers = {exchange:'amq.topic', routing_key:manage_channel};
-}
-
-else {
-  var send_headers = {exchange:''};
-  var subscribe_destination = manage_channel;
-  var subscribe_headers = {exchange:''};
-}
-
+var send_headers = {exchange:''};
+var subscribe_destination = manage_channel;
+var subscribe_headers = {exchange:''};
 
 var channels = [];
 
     url(r'^public/$', 'public', name='default_public_channel'),
     url(r'^public/(?P<channel_name>[\w\s-]+)$', 'public',
         name='named_public_channel'),
+    url(r'^one_on_one/(?P<role>[\w]+)/(?P<channel_name>[\w\s\.-]+)$', 'one_on_one',
+        name='one_on_one'),
     url(r'^kickme/(?P<channel_slug>[\w-]+)/$', 'kickme',
         name='kickme_from_channel'),
     url(r'^participants/(?P<channel_slug>[\w-]+)$', 'channel_participants',
         return HttpResponse(_('You are already participating in this chat channel. You can <a href="/live/kickme/%s">close your active sessions</a> and try again' % channel_slug))
 
     if not nickname:
-        nickname = 'guest' + str(time.time())
+        timestamp = str(time.time()).replace('.', '')[5:]
+        nickname = 'guest' + timestamp
     channel_session = "%s__%s" % (request.session.session_key, channel_slug)
 
     ## we make sure the session gets saved
         return HttpResponse(_('Not allowed'))
 
 
+def one_on_one(request, role, channel_name):
+    names = channel_name.split('..')[1:]
+    if role == 'host':
+        nickname = names[0]
+    else:
+        nickname = names[1]
+    return _show_chat(request, channel_name=channel_name, nickname=nickname)
+
+
 def public(request, channel_name="PUBLIC"):
     if request.user:
         nickname = request.user.username
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.