You are here

function messaging_notify_notifications in Messaging 6

Implementation of hook_notifications()

File

messaging_notify/messaging_notify.module, line 141
Subscriptions to messaging events

Code

function messaging_notify_notifications($op, &$arg0, $arg1 = NULL, $arg2 = NULL) {
  switch ($op) {
    case 'names':
      $subs =& $arg0;
      if ($subs->event_type == 'message') {
        $subs->type_name = t('Messaging');
        if (!empty($subs->fields['method'])) {
          $subs->names['method'] = t('Method: %name', array(
            '%name' => messaging_method_info($subs->fields['method'], 'name'),
          ));
        }
      }
      break;
    case 'subscription types':
      $types['messaging'] = array(
        'event_type' => 'message',
        'title' => t('Messages'),
        'description' => t('Receive an aditional notification whenever a message is sent to you by a different method.'),
        'access' => 'subscribe to messages',
        'fields' => array(
          'method',
        ),
      );
      return $types;
    case 'subscription fields':

      // Information about available fields for subscriptions
      $fields['method'] = array(
        'name' => t('Sending method'),
        'field' => 'method',
        'type' => 'string',
        'options callback' => 'messaging_notify_method_list',
      );
      return $fields;
    case 'query':

      // This one will handle only single destinations. $arg2 is $event array.
      if ($arg0 == 'event' && $arg1 == 'message' && ($message = $arg2->message) && is_numeric($message->destination) && $message->uid) {
        $query[] = array(
          'fields' => array(
            'method' => $message->method,
          ),
          'where' => array(
            's.uid' => $message->uid,
          ),
        );
        return $query;
      }
      break;
    case 'event load':

      // $arg0 is event
      $event =& $arg0;
      if ($event->type == 'message') {
        if (!empty($event->params['mqid'])) {
          $message = messaging_message_load($event->params['mqid']);
          $event->objects['message'] = $message;
          $event->objects['author'] = $message->sender_account;
        }
      }
      break;
    case 'event types':

      // Node inserts are not grouped by node but all together. The digest will look like:
      //   New content has been submitted
      //   - Story Title1 by Author1
      //   - Event Title2 by Author2
      $types[] = array(
        'type' => 'message',
        'action' => 'sent',
        'name' => t('New message from [method-name]'),
        'line' => t('[type-name] [title] by [author-name]'),
        'digest' => array(
          'message',
          'method',
        ),
        'description' => t('Message received'),
      );
      return $types;
  }
}