Exemple #1
0
    def _build_notification_dict(self, event, tweaks, badge):
        ctx = yield push_tools.get_context_for_event(self.store,
                                                     self.state_handler, event,
                                                     self.user_id)

        d = {
            'notification': {
                'id':
                event.event_id,  # deprecated: remove soon
                'event_id':
                event.event_id,
                'room_id':
                event.room_id,
                'type':
                event.type,
                'sender':
                event.user_id,
                'counts': {  # -- we don't mark messages as read yet so
                    # we have no way of knowing
                    # Just set the badge to 1 until we have read receipts
                    'unread': badge,
                    # 'missed_calls': 2
                },
                'devices': [{
                    'app_id': self.app_id,
                    'pushkey': self.pushkey,
                    'pushkey_ts': long(self.pushkey_ts / 1000),
                    'data': self.data_minus_url,
                    'tweaks': tweaks
                }]
            }
        }
        if event.type == 'm.room.member':
            d['notification']['membership'] = event.content['membership']
            d['notification'][
                'user_is_target'] = event.state_key == self.user_id
        if 'content' in event:
            d['notification']['content'] = event.content

        # We no longer send aliases separately, instead, we send the human
        # readable name of the room, which may be an alias.
        if 'sender_display_name' in ctx and len(
                ctx['sender_display_name']) > 0:
            d['notification']['sender_display_name'] = ctx[
                'sender_display_name']
        if 'name' in ctx and len(ctx['name']) > 0:
            d['notification']['room_name'] = ctx['name']

        defer.returnValue(d)
Exemple #2
0
    def _build_notification_dict(self, event, tweaks, badge):
        ctx = yield push_tools.get_context_for_event(
            self.store, self.state_handler, event, self.user_id
        )

        d = {
            'notification': {
                'id': event.event_id,  # deprecated: remove soon
                'event_id': event.event_id,
                'room_id': event.room_id,
                'type': event.type,
                'sender': event.user_id,
                'counts': {  # -- we don't mark messages as read yet so
                             # we have no way of knowing
                    # Just set the badge to 1 until we have read receipts
                    'unread': badge,
                    # 'missed_calls': 2
                },
                'devices': [
                    {
                        'app_id': self.app_id,
                        'pushkey': self.pushkey,
                        'pushkey_ts': long(self.pushkey_ts / 1000),
                        'data': self.data_minus_url,
                        'tweaks': tweaks
                    }
                ]
            }
        }
        if event.type == 'm.room.member':
            d['notification']['membership'] = event.content['membership']
            d['notification']['user_is_target'] = event.state_key == self.user_id
        if 'content' in event:
            d['notification']['content'] = event.content

        # We no longer send aliases separately, instead, we send the human
        # readable name of the room, which may be an alias.
        if 'sender_display_name' in ctx and len(ctx['sender_display_name']) > 0:
            d['notification']['sender_display_name'] = ctx['sender_display_name']
        if 'name' in ctx and len(ctx['name']) > 0:
            d['notification']['room_name'] = ctx['name']

        defer.returnValue(d)
Exemple #3
0
    def _build_notification_dict(self, event, tweaks, badge):
        ctx = yield push_tools.get_context_for_event(self.hs.get_datastore(), event)

        d = {
            "notification": {
                "id": event.event_id,  # deprecated: remove soon
                "event_id": event.event_id,
                "room_id": event.room_id,
                "type": event.type,
                "sender": event.user_id,
                "counts": {  # -- we don't mark messages as read yet so
                    # we have no way of knowing
                    # Just set the badge to 1 until we have read receipts
                    "unread": badge,
                    # 'missed_calls': 2
                },
                "devices": [
                    {
                        "app_id": self.app_id,
                        "pushkey": self.pushkey,
                        "pushkey_ts": long(self.pushkey_ts / 1000),
                        "data": self.data_minus_url,
                        "tweaks": tweaks,
                    }
                ],
            }
        }
        if event.type == "m.room.member":
            d["notification"]["membership"] = event.content["membership"]
            d["notification"]["user_is_target"] = event.state_key == self.user_id
        if "content" in event:
            d["notification"]["content"] = event.content

        if len(ctx["aliases"]):
            d["notification"]["room_alias"] = ctx["aliases"][0]
        if "sender_display_name" in ctx and len(ctx["sender_display_name"]) > 0:
            d["notification"]["sender_display_name"] = ctx["sender_display_name"]
        if "name" in ctx and len(ctx["name"]) > 0:
            d["notification"]["room_name"] = ctx["name"]

        defer.returnValue(d)