コード例 #1
0
ファイル: tgp-info.c プロジェクト: majn/telegram-purple
static void tgp_info_load_channel_done (struct tgl_state *TLS, void *extra, int success, struct tgl_channel *C) {
  g_return_if_fail(success);
  
  PurpleNotifyUserInfo *info = purple_notify_user_info_new ();
  
  if (str_not_empty (C->about)) {
    purple_notify_user_info_add_pair (info, _("Description"), C->about);
  }
  
  if (str_not_empty (C->username)) {
    char *link = g_strdup_printf ("https://telegram.me/%s", C->username);
    purple_notify_user_info_add_pair (info, _("Link"), link);
    g_free (link);
  }
  
  if (str_not_empty (C->print_title)) {
    purple_notify_user_info_add_pair (info, _("Print Title"), C->print_title);
  }
  
  char *admins = g_strdup_printf ("%d", C->admins_count);
  purple_notify_user_info_add_pair (info, _("Administrators"), admins);
  g_free (admins);
  
  char *participants = g_strdup_printf ("%d", C->participants_count);
  purple_notify_user_info_add_pair (info, _("Participants"), participants);
  g_free (participants);
  
  char *kicked = g_strdup_printf ("%d", C->kicked_count);
  purple_notify_user_info_add_pair (info, _("Kicked"), kicked);
  g_free (kicked);
  
  purple_notify_userinfo (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, C->id), info, NULL, NULL);
}
コード例 #2
0
ファイル: tgp-chat.c プロジェクト: Houlbek/telegram-purple
PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C) {
  PurpleConvChat *chat = NULL;
  
  // check if chat is already shown
  PurpleConversation *conv = purple_find_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id));
  if (conv) {
    chat = purple_conversation_get_chat_data (conv);
    if (chat && ! purple_conv_chat_has_left (chat)) {
      return conv;
    }
  }
  
  // join the chat now
  conv = serv_got_joined_chat (tls_get_conn (TLS), tgl_get_peer_id (C->id), C->print_title);
  g_return_val_if_fail(conv, NULL);
  
  purple_conv_chat_clear_users (purple_conversation_get_chat_data (conv));
  tgp_chat_add_all_users (TLS, conv, C);
  
  return conv;
}
コード例 #3
0
ファイル: tgp-chat.c プロジェクト: Houlbek/telegram-purple
void tgp_chat_join_all_pending (struct tgl_state *TLS) {
  GList *pending;
  for (pending = tls_get_data (TLS)->pending_joins; pending != NULL; pending = g_list_next(pending)) {
    GHashTable *data = g_hash_table_new (g_str_hash, g_str_equal);
    g_hash_table_insert (data, "id", pending->data);
    tgprpl_chat_join (tls_get_conn (TLS), data);
    g_hash_table_destroy (data);
  }
  if (tls_get_data (TLS)->pending_joins) {
    g_list_free (tls_get_data (TLS)->pending_joins);
    tls_get_data (TLS)->pending_joins = NULL;
  }
}
コード例 #4
0
ファイル: tgp-msg.c プロジェクト: Houlbek/telegram-purple
void tgp_msg_err_out (struct tgl_state *TLS, const char *error, tgl_peer_id_t to) {
  int flags = PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_SYSTEM;
  time_t now;
  time (&now);
  switch (tgl_get_peer_type (to)) {
      case TGL_PEER_CHAT:
        p2tgl_got_chat_in (TLS, to, to, error, flags, now);
        break;
      case TGL_PEER_USER:
      case TGL_PEER_ENCR_CHAT:
        serv_got_im (tls_get_conn (TLS), tgp_blist_lookup_purple_name (TLS, to), error, flags, now);
        break;
  }
}
コード例 #5
0
ファイル: tgp-info.c プロジェクト: majn/telegram-purple
static void tgp_info_load_user_done (struct tgl_state *TLS, void *extra, int success, struct tgl_user *U) {
  g_return_if_fail(success);
  
  // user info
  
  PurpleNotifyUserInfo *info = purple_notify_user_info_new ();
  
  if (str_not_empty (U->first_name) && str_not_empty (U->last_name)) {
    purple_notify_user_info_add_pair (info, _("First name"), U->first_name);
    purple_notify_user_info_add_pair (info, _("Last name"), U->last_name);
  } else {
    purple_notify_user_info_add_pair (info, _("Name"), U->print_name);
  }
  
  if (str_not_empty (U->username)) {
    char *username = g_strdup_printf ("@%s", U->username);
    purple_notify_user_info_add_pair (info, _("Username"), username);
    g_free (username);
  }
  
  char *status = tgp_format_user_status (&U->status);
  purple_notify_user_info_add_pair (info, _("Last seen"), status);
  g_free (status);
  
  if (str_not_empty (U->phone)) {
    char *phone = g_strdup_printf ("+%s", U->phone);
    purple_notify_user_info_add_pair (info, _("Phone"), phone);
    g_free (phone);
  }
  
  // secret chat info
  
  tgl_peer_t *O = extra;
  if (O && tgl_get_peer_type (O->id) == TGL_PEER_ENCR_CHAT) {
    
    struct tgl_secret_chat *secret = &O->encr_chat;
    
    if (secret->state == sc_waiting) {
      purple_notify_user_info_add_pair (info, "", _("Waiting for the user to get online..."));
    } else {
      const char *ttl_key = _("Self destruction timer");
      if (secret->ttl) {
        char *ttl = g_strdup_printf ("%d", secret->ttl);
        purple_notify_user_info_add_pair (info, ttl_key, ttl);
        g_free (ttl);
      } else {
        purple_notify_user_info_add_pair (info, ttl_key, _("Timer is not enabled."));
      }
      
      if (secret->first_key_sha[0]) {
        int sha1key = tgp_visualize_key (TLS, secret->first_key_sha);
        if (sha1key != -1) {
          char *ident_icon = tgp_format_img (sha1key);
          purple_notify_user_info_add_pair (info, _("Secret key"), ident_icon);
          g_free(ident_icon);
        }
      }
    }
  }
  
  const char *who = NULL;
  if (tgl_get_peer_type (O->id) == TGL_PEER_ENCR_CHAT) {
    who = tgp_blist_lookup_purple_name (TLS, O->id);
  } else {
    who = tgp_blist_lookup_purple_name (TLS, U->id);
  }
  
  purple_notify_userinfo (tls_get_conn (TLS), who, info, NULL, NULL);
}