Ejemplo n.º 1
0
void window_notify_ancs(uint8_t command, uint32_t uid, uint8_t flag, uint8_t category)
{
  if (command == 0) // add
  {
    if (lastmessageid != -1 && lastmessageid >= uid)
    {
      return;
    }

    message_title = NULL;
    message = NULL;
    push_uid(uid, (flag << 8) | category);
    selectidx = 0;
    motor_on(50, CLOCK_SECOND);
    backlight_on(window_readconfig()->light_level, CLOCK_SECOND * 3);

    lastmessageid = uid;
    if (state & STATE_ACTIVE)
      window_invalid(NULL);
    else 
      window_open(notify_process, NULL);

    fetch_content();    
  }
  else if (command == 1)
  {
    if (state & STATE_ACTIVE)
    {
      // check if the current 
      if (uids[0] == uid)
      {
        fetch_content();
      }
      window_invalid(NULL);
      motor_on(50, CLOCK_SECOND);
    }
  }
  else if (command == 2) // remove
  {
    if (!(state & STATE_ACTIVE))
      return;

    uint8_t refresh = 0;
    if (uids[0] == uid)
    {
      refresh = 1;
    }

    // find the item
    int i;
    for(i = 0; i < num_uids; i++)
    {
      if (uids[i] == uid)
        break;
    }

    if (i == num_uids)
      return;

    for (int j = i ; j < num_uids; j++)
    {
      uids[j] = uids[j+1];
      attributes[j] = attributes[j+1];
    }
    num_uids--;

    if (refresh)
      fetch_content();
  }
}
Ejemplo n.º 2
0
// notify window process
static uint8_t notify_process(uint8_t ev, uint16_t lparam, void* rparam)
{
  switch(ev)
  {
  case EVENT_WINDOW_CREATED:
  {
    state |= STATE_ACTIVE;
    add_watch_status(WS_NOTIFY);
    return 0x80;
  }
  case EVENT_WINDOW_PAINT:
    {
      onDraw((tContext*)rparam);
      break;
    }
  case EVENT_WINDOW_CLOSING:
    state &= ~STATE_ACTIVE;
    process_post(ui_process, EVENT_NOTIFY_RESULT, (void*)message_result);
    motor_on(0, 0);
    del_watch_status(WS_NOTIFY);
    selectidx = 0;
    num_uids = 0;
    return 0;
    break;
  case EVENT_KEY_PRESSED:
    if (lparam == KEY_DOWN)
    {
      if (state & STATE_MORE)
      {
        skip += 16;
        window_invalid(NULL);
      }
      else if (selectidx < num_uids)
      {
        selectidx++;
        fetch_content();
        window_invalid(NULL);
      }
    }
    else if (lparam == KEY_UP)
    {
      if (skip >= 16)
      {
        skip-=16;
        window_invalid(NULL);
      }
      else if (skip == 0)
      {
        if (selectidx > 0)
        {  
          selectidx--;
          fetch_content();
          window_invalid(NULL);
        }
     }
    }
    else if (lparam == KEY_ENTER)
    {
      if (selectidx < num_uids - 1)
      {
        selectidx++;
        fetch_content();
        window_invalid(NULL);
      }
    }
    break;
  default:
    return 0;
  }

  return 1;
}
Ejemplo n.º 3
0
static void route_result(cJSON* result)
{
    cJSON* cjson_current;
    size_t i;
    for (cjson_current = result->child; cjson_current; cjson_current = cjson_current->next)
    {
        if (strcmp(cJSON_GetObjectItem(cjson_current, "poll_type")->valuestring, "message") == 0)
        {
            cJSON* cjson_value = cJSON_GetObjectItem(cjson_current, "value");
            ullong from_uin = cJSON_GetObjectItem(cjson_value, "from_uin")->valuedouble;
            ullong number = get_friend_number(from_uin);
            msg_content_array_t content = fetch_content(cJSON_GetObjectItem(cjson_value, "content"));
            dump_message(number, str_from("friend_message"), &content);
#ifdef _DEBUG
            {
                char* str = msg_content_array_to_json_object_string(&content, "content");
                fprintf(stdout, "Received message from: %llu\nContent: %s\n", number, str);
                fflush(stdout);
                free(str);
            }
#endif

            for (i = 0; i < robot.received_message_funcs_count; ++i) robot.received_message_funcs[i](from_uin, number, &content);
            msg_content_array_free(&content);
        }
        else if (strcmp(cJSON_GetObjectItem(cjson_current, "poll_type")->valuestring, "group_message") == 0)
        {
            cJSON* cjson_value = cJSON_GetObjectItem(cjson_current, "value");
            ullong from_uin = cJSON_GetObjectItem(cjson_value, "from_uin")->valuedouble;
            ullong number = get_group_number(cJSON_GetObjectItem(cjson_value, "group_code")->valuedouble);
            msg_content_array_t content = fetch_content(cJSON_GetObjectItem(cjson_value, "content"));
            dump_message(number, str_from("group_message"), &content);
#ifdef _DEBUG
            {
                char* str = msg_content_array_to_json_object_string(&content, "content");
                fprintf(stdout, "Received group_message from: %llu\nContent: %s\n", number, str);
                fflush(stdout);
                free(str);
            }
#endif

            for (i = 0; i < robot.received_group_message_funcs_count; ++i) robot.received_group_message_funcs[i](from_uin, number, &content);
            msg_content_array_free(&content);
        }
        else
        {
            bson_t document;
            bson_t content;
            bson_error_t error;
            time_t t;
            char* ptr = cJSON_PrintUnformatted(cjson_current);
            mongoc_collection_t* collection = mongoc_database_get_collection(robot.mongoc_database, "unprocessed");

            time(&t);
            if (!bson_init_from_json(&content, ptr, strlen(ptr), &error))
            {
                MONGOC_WARNING("%s\n", error.message);
                return;
            }
            bson_init(&document);
            BSON_APPEND_TIME_T(&document, "time", t);
            BSON_APPEND_DOCUMENT(&document, "content", &content);
            if (!mongoc_collection_insert(collection, MONGOC_INSERT_NONE, &document, NULL, &error)) MONGOC_WARNING("%s\n", error.message);
            bson_destroy(&document);
            bson_destroy(&content);
        }
    }
}