def __setChannelHistory(self, jid): channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) if channel: g_messengerEvents.channels.onHistoryReceived( sorted(self.__history, key=operator.attrgetter('sentAt')), channel)
def restore(self, jid, state): jid = jid_entity.ContactBareJID(jid) channel = entities.XMPPChatChannelEntity(jid_entity.ContactBareJID(jid)) result = channel.setPersistentState(state) if result and not self.hasChannel(channel.getID()): self.__addSession(channel, jid.getDatabaseID()) return result
def stopSession(self, jid): channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) if channel: self._removeChannel(channel) self.__sessions.discard(jid) self.__historyRQ.cancel(jid)
def restoreSession(self, jid, state): channel = entities.XMPPChatChannelEntity(jid) jid = ContactBareJID(jid) if channel.setPersistentState(state) and jid not in self.__sessions: channel = self._addChannel(channel, jid.getDatabaseID(), channel.getProtoData().name) if channel: self.__sessions.add(jid)
def startSession(self, jid, name): search = entities.XMPPChatChannelEntity(jid, name) channel = self.channelsStorage.getChannel(search) if not channel: channel = self._addChannel(search, jid.getDatabaseID(), name) if not channel: return g_messengerEvents.channels.onPlayerEnterChannelByAction(channel) self.__sessions.add(jid)
def setContactPresence(self, contact): dbID = contact.getID() if contact.getProtoType() == PROTO_TYPE.XMPP: jid = contact.getJID() else: jid = makeContactJID(dbID) if jid not in self.__sessions: return channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) if channel: member = channel.getMember(dbID) if member: member.setOnline(contact.isOnline())
def sendMessage(self, jid, body, filters): channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) if channel: if self.playerCtx.isBanned(components=XMPP_BAN_COMPONENT.PRIVATE): error = createChatBanError(self.playerCtx.getBanInfo()) if error: g_messengerEvents.onErrorReceived(error) return dbID = getPlayerDatabaseID() name = getPlayerName() g_messengerEvents.channels.onMessageReceived( ChatMessage(dbID, name, filters.chainIn(dbID, body), time.time()), channel) self.client().sendMessage(ChatMessageHolder(jid, msgBody=body))
def __setChannelHistory(self, jid): channel = self.channelsStorage.getChannel( entities.XMPPChatChannelEntity(jid)) for unreadMessage in channel.getUnreadMessages(): isExist = False for historyMessage in self.__history: isExist = unreadMessage.uuid == historyMessage.uuid if isExist: break if not isExist: self.__history.append(unreadMessage) channel.clearUnreadMessages() if channel: g_messengerEvents.channels.onHistoryReceived( sorted(self.__history, key=operator.attrgetter('sentAt')), channel)
def addMessage(self, jid, message): if message.isHistory(): self.__historyRQ.addHistory(message) return dbID = message.accountDBID name = message.accountName if jid not in self.__sessions and g_settings.userPrefs.chatContactsListOnly: contact = self.usersStorage.getUser(dbID) if not contact or not USER_TAG.filterClosedContactsTags( contact.getTags()): g_logOutput.debug( CLIENT_LOG_AREA.MESSAGE, "There is not closed contact in player's contacts list,contact's message is ignored", jid, name) return search = entities.XMPPChatChannelEntity(jid, name) channel = self.channelsStorage.getChannel(search) if not channel: channel = self._addChannel(search, dbID, name) if not channel: return self.__sessions.add(jid) if message.body: g_messengerEvents.channels.onMessageReceived(message, channel)
def _searchChannel(self, jid, name=''): created = entities.XMPPChatChannelEntity(jid, name=name) exists = self.channelsStorage.getChannel(created) return (created, exists)