# -*- coding: utf-8  -*-
"""Classes and functions for working with the Echo extension."""
from __future__ import absolute_import, unicode_literals

import pywikibot


class Notification(object):

    """A notification issued by the Echo extension."""

    def __init__(self, site):
        """Construct an empty Notification object."""
        self.site = site

    @classmethod
    def fromJSON(cls, site, data):
        """
        Construct a Notification object from JSON data returned by the API.

        @rtype: Notification
        """
        notif = cls(site)

        notif.id = data['id']  # TODO: use numeric id ?
        notif.type = data['type']
        notif.category = data['category']
        notif.timestamp = pywikibot.Timestamp.fromtimestampformat(data['timestamp']['mw'])

        if 'title' in data and 'full' in data['title']:
            notif.page = pywikibot.Page(site, data['title']['full'])
        else:
            notif.page = None

        if 'agent' in data and 'name' in data['agent']:
            notif.agent = pywikibot.User(site, data['agent']['name'])
        else:
            notif.agent = None

        if 'read' in data:
            notif.read = pywikibot.Timestamp.fromtimestampformat(data['read'])
        else:
            notif.read = False

        notif.content = data.get('*', None)

        return notif

    def mark_as_read(self):
        """Mark the notification as read."""
        return self.site.notifications_mark_read(list=self.id)

# -*- coding: utf-8  -*-
"""Classes and functions for working with the Echo extension."""
from __future__ import absolute_import, unicode_literals

import pywikibot


class Notification(object):

    """A notification issued by the Echo extension."""

    def __init__(self, site):
        """Construct an empty Notification object."""
        self.site = site

    @classmethod
    def fromJSON(cls, site, data):
        """
        Construct a Notification object from JSON data returned by the API.

        @rtype: Notification
        """
        notif = cls(site)

        notif.id = data['id']  # TODO: use numeric id ?
        notif.type = data['type']
        notif.category = data['category']
        notif.timestamp = pywikibot.Timestamp.fromtimestampformat(data['timestamp']['mw'])

        if 'title' in data and 'full' in data['title']:
            notif.page = pywikibot.Page(site, data['title']['full'])
        else:
            notif.page = None

        if 'agent' in data and 'name' in data['agent']:
            notif.agent = pywikibot.User(site, data['agent']['name'])
        else:
            notif.agent = None

        if 'read' in data:
            notif.read = pywikibot.Timestamp.fromtimestampformat(data['read'])
        else:
            notif.read = False

        notif.content = data.get('*', None)
        notif.revid = data.get('revid', None)

        return notif

    def mark_as_read(self):
        """Mark the notification as read."""
        return self.site.notifications_mark_read(list=self.id)

Add revid to Notification object
Add revid to Notification object

Since most edit-related notifications include revid attributes,
we should include the revids in the Notification objects as we're
building them (if they exist).

Change-Id: Ifdb98e7c79729a1c2f7a5c4c4366e28071a48239
