1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2007 Johann Prieur <johann.prieur@gmail.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
from pymsn.service.OfflineIM.constants import *
20
from pymsn.service.OfflineIM.scenario.base import BaseScenario
21
from pymsn.msnp.challenge import _msn_challenge
23
__all__ = ['SendMessageScenario']
25
class SendMessageScenario(BaseScenario):
26
def __init__(self, oim, client, recipient, message, callback, errback):
27
"""Accepts an invitation.
29
@param oim: the oim service
30
@param client: the client object sending the OIM
31
@param recipient: the contact to send the OIM to
32
@param message: the message to send
33
@param callback: tuple(callable, *args)
34
@param errback: tuple(callable, *args)
36
BaseScenario.__init__(self, callback, errback)
38
self.__client = client
39
self.__from = client.profile
43
self.sequence_num = -1
48
self.__oim.Store2((self.__store2_callback,),
49
(self.__store2_errback,),
51
self.__from.display_name,
58
def __store2_callback(self):
59
callback = self._callback
60
callback[0](*callback[1:])
62
def __store2_errback(self, error_code, auth_policy, lock_key_challenge):
63
if error_code == OfflineMessagesBoxError.AUTHENTICATION_FAILED:
64
if lock_key_challenge != None:
65
self.__oim.set_lock_key(_msn_challenge(lock_key_challenge))
66
if auth_policy != None:
67
self._client._sso.DiscardSecurityTokens([LiveService.CONTACTS])
68
self._client._sso.RequestMultipleSecurityTokens((self.execute, ), None, LiveService.CONTACTS)
74
errback = self._errback
75
errback[0](error_code, *errback[1:])