comparison src/memory/sqlite.py @ 538:2c4016921403

core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles - added profile argument to askConfirmation, actionResult, actionResultExt, entityDataUpdated, confirmationAnswer, getProgress - core, frontends: fixed calls/signals according to new bridge API - user of proper profile namespace for progression indicators and dialogs - memory: getParam* now return bool when param type is bool - memory: added getStringParam* to return string instead of typed value - core, memory, storage, quick_frontend: getHistory now manage properly multi-profiles - plugins XEP-0047, XEP-0054, XEP-0065, XEP-0077, XEP-0096; multi-profiles proper handling
author Goffi <goffi@goffi.org>
date Sat, 10 Nov 2012 16:38:16 +0100
parents 862c0d6ab974
children 9faccd827657
comparison
equal deleted inserted replaced
537:28cddc96c4ed 538:2c4016921403
181 @param to_jid: full dest JID 181 @param to_jid: full dest JID
182 @param message: message 182 @param message: message
183 @param _type: message type (see RFC 6121 §5.2.2) 183 @param _type: message type (see RFC 6121 §5.2.2)
184 @param timestamp: timestamp in seconds since epoch, or None to use current time 184 @param timestamp: timestamp in seconds since epoch, or None to use current time
185 """ 185 """
186 assert(profile!=None) 186 assert(profile)
187 d = self.dbpool.runQuery("INSERT INTO history(source, source_res, dest, dest_res, timestamp, message, type, profile_id) VALUES (?,?,?,?,?,?,?,?)", 187 d = self.dbpool.runQuery("INSERT INTO history(source, source_res, dest, dest_res, timestamp, message, type, profile_id) VALUES (?,?,?,?,?,?,?,?)",
188 (from_jid.userhost(), from_jid.resource, to_jid.userhost(), to_jid.resource, timestamp or time.time(), 188 (from_jid.userhost(), from_jid.resource, to_jid.userhost(), to_jid.resource, timestamp or time.time(),
189 message, _type, self.profiles[profile])) 189 message, _type, self.profiles[profile]))
190 d.addErrback(lambda ignore: error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" % 190 d.addErrback(lambda ignore: error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" %
191 {"from_jid":from_jid.full(), "to_jid":to_jid.full(), "message":message}))) 191 {"from_jid":from_jid.full(), "to_jid":to_jid.full(), "message":message})))
192 return d 192 return d
193 193
194 def getHistory(self, from_jid, to_jid, limit=0, between=True): 194 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=None):
195 """Store a new message in history 195 """Store a new message in history
196 @param from_jid: source JID (full, or bare for catchall 196 @param from_jid: source JID (full, or bare for catchall
197 @param to_jid: dest JID (full, or bare for catchall 197 @param to_jid: dest JID (full, or bare for catchall
198 @param size: maximum number of messages to get, or 0 for unlimited 198 @param size: maximum number of messages to get, or 0 for unlimited
199 """ 199 """
200 assert(profile)
200 def sqliteToDict(query_result): 201 def sqliteToDict(query_result):
201 query_result.reverse() 202 query_result.reverse()
202 result = [] 203 result = []
203 for row in query_result: 204 for row in query_result:
204 timestamp, source, source_res, dest, dest_res, message, _type= row 205 timestamp, source, source_res, dest, dest_res, message, _type= row
206 "%s/%s" % (dest, dest_res) if dest_res else dest, 207 "%s/%s" % (dest, dest_res) if dest_res else dest,
207 message, _type)) 208 message, _type))
208 return result 209 return result
209 210
210 211
211 query_parts = ["SELECT timestamp, source, source_res, dest, dest_res, message, type FROM history WHERE"] 212 query_parts = ["SELECT timestamp, source, source_res, dest, dest_res, message, type FROM history WHERE profile_id=? AND"]
212 values = [] 213 values = [self.profiles[profile]]
213 214
214 def test_jid(_type,_jid): 215 def test_jid(_type,_jid):
215 values.append(_jid.userhost()) 216 values.append(_jid.userhost())
216 if _jid.resource: 217 if _jid.resource:
217 values.append(_jid.resource) 218 values.append(_jid.resource)