Commits

Ian Lewis  committed 51df55f

ユーザーへのメッセージを送信できるようにAPI修正

  • Participants
  • Parent commits d1ec4c6

Comments (0)

Files changed (2)

File skypehub/forms.py

 class PostMessageForm(forms.Form):
     message = forms.CharField()
     chat = forms.CharField()
+
+class PostUserMessageForm(forms.Form):
+    message = forms.CharField()
+    username = forms.CharField()

File skypehub/views.py

     from django.utils import simplejson as json
 
 from skypehub.decorators import skype_required
-from skypehub.forms import PostMessageForm
+from skypehub.forms import PostMessageForm, PostUserMessageForm
 
 def make_json_response(content):
     return HttpResponse(json.dumps(content, indent=2), content_type='application/javascript')
         chat = skype.Chat(form.cleaned_data['chat'])
         chat.SendMessage(form.cleaned_data['message'])
         return make_json_response({'result': 'ok'})
+    else:
+        form = PostUserMessageForm(request.POST or None)
+        if form.is_valid():
+            chat = skype.CreateChatWith(form.cleaned_data['username'])
+            chat.SendMessage(form.cleaned_data['message'])
+            return make_json_response({'result': 'ok'})
+
     return  make_json_response({'result': 'validation error.'})