| 1664 | | error_msg = msg.getError() |
| 1665 | | if not error_msg: |
| 1666 | | error_msg = msgtxt |
| 1667 | | msgtxt = None |
| 1668 | | if session.is_loggable(): |
| 1669 | | try: |
| 1670 | | gajim.logger.write('error', frm, error_msg, tim = tim, |
| 1671 | | subject = subject) |
| 1672 | | except exceptions.PysqliteOperationalError, e: |
| 1673 | | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| 1674 | | self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt, |
| 1675 | | tim)) |
| | 1671 | self.dispatch_error_message(msg, msgtxt, session, frm, tim, subject) |
| | 1672 | |
| 1678 | | has_timestamp = False |
| 1679 | | if msg.timestamp: |
| 1680 | | has_timestamp = True |
| 1681 | | if subject != None: |
| 1682 | | self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) |
| 1683 | | else: |
| 1684 | | statusCode = msg.getStatusCode() |
| 1685 | | if not msg.getTag('body'): #no <body> |
| 1686 | | # It could be a config change. See |
| 1687 | | # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify |
| 1688 | | if msg.getTag('x'): |
| 1689 | | if statusCode != []: |
| 1690 | | self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) |
| 1691 | | return |
| 1692 | | # Ignore message from room in which we are not |
| 1693 | | if not self.last_history_line.has_key(jid): |
| 1694 | | return |
| 1695 | | self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml, |
| 1696 | | statusCode)) |
| 1697 | | if self.name not in no_log_for and jid not in no_log_for and not \ |
| 1698 | | int(float(mktime(tim))) <= self.last_history_line[jid] and msgtxt: |
| 1699 | | try: |
| 1700 | | gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) |
| 1701 | | except exceptions.PysqliteOperationalError, e: |
| 1702 | | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| 1703 | | return |
| 1704 | | elif mtype == 'chat': # it's type 'chat' |
| 1705 | | if not msg.getTag('body') and chatstate is None: #no <body> |
| | 1675 | self.dispatch_gc_message(msg, subject, frm, msgtxt, jid, tim, msghtml) |
| | 1676 | |
| | 1677 | return |
| | 1678 | elif invite is not None: |
| | 1679 | self.dispatch_invite_message(invite, frm) |
| | 1680 | |
| | 1681 | return |
| | 1682 | elif mtype == 'chat': |
| | 1683 | if not msg.getTag('body') and chatstate is None: # no <body> |
| 1707 | | if msg.getTag('body') and session.is_loggable() and msgtxt: |
| 1708 | | try: |
| 1709 | | msg_id = gajim.logger.write('chat_msg_recv', frm, msgtxt, |
| 1710 | | tim = tim, subject = subject) |
| 1711 | | except exceptions.PysqliteOperationalError, e: |
| 1712 | | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| 1713 | | else: # it's single message |
| 1714 | | if invite is not None: |
| 1715 | | item = invite.getTag('invite') |
| 1716 | | jid_from = item.getAttr('from') |
| 1717 | | reason = item.getTagData('reason') |
| 1718 | | item = invite.getTag('password') |
| 1719 | | password = invite.getTagData('password') |
| 1720 | | is_continued = False |
| 1721 | | if invite.getTag('invite').getTag('continue'): |
| 1722 | | is_continued = True |
| 1723 | | self.dispatch('GC_INVITATION',(frm, jid_from, reason, password, |
| 1724 | | is_continued)) |
| 1725 | | return |
| 1726 | | if session.is_loggable()and msgtxt: |
| 1727 | | try: |
| 1728 | | gajim.logger.write('single_msg_recv', frm, msgtxt, tim = tim, |
| 1729 | | subject = subject) |
| 1730 | | except exceptions.PysqliteOperationalError, e: |
| 1731 | | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| | 1685 | |
| | 1686 | log_type = 'chat_msg_recv' |
| | 1687 | else: # it's a single message |
| | 1688 | log_type = 'single_msg_recv' |
| | 1689 | |
| | 1707 | |
| | 1708 | # process and dispatch an error message |
| | 1709 | def dispatch_error_message(self, msg, msgtxt, session, frm, tim, subject) |
| | 1710 | error_msg = msg.getError() |
| | 1711 | |
| | 1712 | if not error_msg: |
| | 1713 | error_msg = msgtxt |
| | 1714 | msgtxt = None |
| | 1715 | |
| | 1716 | if session.is_loggable(): |
| | 1717 | try: |
| | 1718 | gajim.logger.write('error', frm, error_msg, tim = tim, |
| | 1719 | subject = subject) |
| | 1720 | except exceptions.PysqliteOperationalError, e: |
| | 1721 | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| | 1722 | |
| | 1723 | self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt, tim)) |
| | 1724 | |
| | 1725 | # process and dispatch a groupchat message |
| | 1726 | def dispatch_gc_message(self, msg, subject, frm, msgtxt, jid, tim, msghtml): |
| | 1727 | has_timestamp = bool(msg.timestamp) |
| | 1728 | |
| | 1729 | if subject != None: |
| | 1730 | self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) |
| | 1731 | else: |
| | 1732 | statusCode = msg.getStatusCode() |
| | 1733 | |
| | 1734 | if not msg.getTag('body'): #no <body> |
| | 1735 | # It could be a config change. See |
| | 1736 | # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify |
| | 1737 | if msg.getTag('x'): |
| | 1738 | if statusCode != []: |
| | 1739 | self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) |
| | 1740 | return |
| | 1741 | |
| | 1742 | # Ignore messages from rooms that we're not in |
| | 1743 | if not self.last_history_line.has_key(jid): |
| | 1744 | return |
| | 1745 | |
| | 1746 | self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml, |
| | 1747 | statusCode)) |
| | 1748 | |
| | 1749 | no_log_for = gajim.config.get_per('accounts', self.name, |
| | 1750 | 'no_log_for') |
| | 1751 | |
| | 1752 | if not no_log_for: |
| | 1753 | no_log_for = '' |
| | 1754 | |
| | 1755 | no_log_for = no_log_for.split() |
| | 1756 | |
| | 1757 | if self.name not in no_log_for and jid not in no_log_for and not \ |
| | 1758 | int(float(mktime(tim))) <= self.last_history_line[jid] and msgtxt: |
| | 1759 | try: |
| | 1760 | gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) |
| | 1761 | except exceptions.PysqliteOperationalError, e: |
| | 1762 | self.dispatch('ERROR', (_('Disk Write Error'), str(e))) |
| | 1763 | |
| | 1764 | def dispatch_invite_message(self, invite, frm) |
| | 1765 | item = invite.getTag('invite') |
| | 1766 | |
| | 1767 | jid_from = item.getAttr('from') |
| | 1768 | reason = item.getTagData('reason') |
| | 1769 | item = invite.getTag('password') |
| | 1770 | password = invite.getTagData('password') |
| | 1771 | |
| | 1772 | is_continued = False |
| | 1773 | if invite.getTag('invite').getTag('continue'): |
| | 1774 | is_continued = True |
| | 1775 | |
| | 1776 | self.dispatch('GC_INVITATION',(frm, jid_from, reason, password, |
| | 1777 | is_continued)) |