def _getConversation(self, user1, user2): """ """ folder = self._getConversationsFolder() id = '.'.join(sorted([hashed(user1), hashed(user2)])) if not folder.hasObject(id): folder._setObject(id, Conversation(id, user1, user2)) return folder._getOb(id)
def _getChatRooms(self, ids): folder = self._getChatRoomsFolder() if type(ids) == str: ids= [ids] crs = [] for c in ids: crs.append(folder._getOb(hashed(c))) return crs
def createChatRoom(self, username, password, path, participants): if self._authenticate(username, password) is None: log.warn('createChatRoom: authentication failed') return json.dumps({'status': config.AUTH_FAIL}) folder = self._getChatRoomsFolder() id = hashed(path) folder._setObject(id, ChatRoom(id, path, participants)) return json.dumps({'status': config.SUCCESS})
def _getMessageBox(self, owner): """ The MessageBox is a container that stores the messages sent a user. We store the sent and received messages in two different messageboxes, instead of the conversation itself, to avoid conflict errors. """ owner = hashed(owner) if owner not in self.objectIds(): self._setObject(owner, MessageBox(owner)) return self._getOb(owner)
def removeChatRoom(self, username, password, id): """ See interfaces.IChatService """ if self._authenticate(username, password) is None: log.warn('getMessages: authentication failed') return json.dumps({'status': config.AUTH_FAIL}) parent = self._getChatRoomsFolder() hid = hashed(id) if hid not in parent.keys(): return json.dumps({'status': config.NOT_FOUND}) parent.manage_delObjects([hid]) return json.dumps({'status': config.SUCCESS})
def _getMessageBox(self, owner): """ The MessageBox is a container that stores the messages sent by a user. Each user has his own messagebox to aviod conflicts. """ if owner not in self.participants: raise Unauthorized owner = hashed(owner) if owner not in self.objectIds(): self._setObject(owner, MessageBox(owner)) return self._getOb(owner)
def _getConversationsFor(self, username): """ """ f = self._getConversationsFolder() username = hashed(username) return [f._getOb(i) for i in f.objectIds() if username in i.split('.')]
def _getChatRoom(self, id): folder = self._getChatRoomsFolder() return folder._getOb(hashed(id))