Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_chat.py @ 1222:e6e0ea4dc835
memory: add Parameter "Chat history limit"
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 24 Sep 2014 13:49:43 +0200 |
parents | 75025461141f |
children | 802b7e6bf098 |
comparison
equal
deleted
inserted
replaced
1221:5e5661ab5c81 | 1222:e6e0ea4dc835 |
---|---|
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.log import getLogger | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | 22 log = getLogger(__name__) |
23 from sat_frontends.tools.jid import JID | 23 from sat_frontends.tools.jid import JID |
24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate | 24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate |
25 from sat_frontends.quick_frontend.constants import Const | 25 from sat_frontends.quick_frontend.constants import Const as C |
26 | 26 |
27 | 27 |
28 class QuickChat(object): | 28 class QuickChat(object): |
29 | 29 |
30 def __init__(self, target, host, type_='one2one'): | 30 def __init__(self, target, host, type_='one2one'): |
98 | 98 |
99 def afterHistoryPrint(self): | 99 def afterHistoryPrint(self): |
100 """Refresh or scroll down the focus after the history is printed""" | 100 """Refresh or scroll down the focus after the history is printed""" |
101 pass | 101 pass |
102 | 102 |
103 def historyPrint(self, size=20, profile='@NONE@'): | 103 def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, profile='@NONE@'): |
104 """Print the current history | 104 """Print the current history |
105 @param size (int): number of messages | 105 @param size (int): number of messages |
106 @param profile (str): %(doc_profile)s | 106 @param profile (str): %(doc_profile)s |
107 """ | 107 """ |
108 log.debug(_("now we print the history (%d messages)") % size) | 108 log.debug(_("now we print the history (%d messages)") % size) |
117 self.afterHistoryPrint() | 117 self.afterHistoryPrint() |
118 | 118 |
119 def onHistoryError(err): | 119 def onHistoryError(err): |
120 log.error(_("Can't get history")) | 120 log.error(_("Can't get history")) |
121 | 121 |
122 if self.target.startswith(Const.PRIVATE_PREFIX): | 122 if self.target.startswith(C.PRIVATE_PREFIX): |
123 target = unescapePrivate(self.target) | 123 target = unescapePrivate(self.target) |
124 else: | 124 else: |
125 target = self.target.bare | 125 target = self.target.bare |
126 | 126 |
127 return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError) | 127 return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError) |
128 | 128 |
129 def _get_nick(self, jid): | 129 def _get_nick(self, jid): |
130 """Return nick of this jid when possible""" | 130 """Return nick of this jid when possible""" |
131 if self.target.startswith(Const.PRIVATE_PREFIX): | 131 if self.target.startswith(C.PRIVATE_PREFIX): |
132 unescaped = unescapePrivate(self.target) | 132 unescaped = unescapePrivate(self.target) |
133 if jid.startswith(Const.PRIVATE_PREFIX) or unescaped.bare == jid.bare: | 133 if jid.startswith(C.PRIVATE_PREFIX) or unescaped.bare == jid.bare: |
134 return unescaped.resource | 134 return unescaped.resource |
135 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) | 135 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) |
136 | 136 |
137 def printMessage(self, from_jid, msg, profile, timestamp = ''): | 137 def printMessage(self, from_jid, msg, profile, timestamp = ''): |
138 """Print message in chat window. Must be implemented by child class""" | 138 """Print message in chat window. Must be implemented by child class""" |
164 log.warning(_('getGame is not implemented in this frontend')) | 164 log.warning(_('getGame is not implemented in this frontend')) |
165 | 165 |
166 def updateChatState(self, state, nick=None): | 166 def updateChatState(self, state, nick=None): |
167 """Set the chat state (XEP-0085) of the contact. Leave nick to None | 167 """Set the chat state (XEP-0085) of the contact. Leave nick to None |
168 to set the state for a one2one conversation, or give a nickname or | 168 to set the state for a one2one conversation, or give a nickname or |
169 Const.ALL_OCCUPANTS to set the state of a participant within a MUC. | 169 C.ALL_OCCUPANTS to set the state of a participant within a MUC. |
170 @param state: the new chat state | 170 @param state: the new chat state |
171 @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS | 171 @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS |
172 """ | 172 """ |
173 raise NotImplementedError | 173 raise NotImplementedError |
174 | 174 |