示例#1
0
GHashTable *tgp_chat_info_new (struct tgl_state *TLS, struct tgl_chat *chat) {
  gchar *admin = g_strdup_printf ("%d", chat->admin_id);
  gchar *title = g_strdup (chat->print_title);
  gchar *name  = p2tgl_strdup_id (chat->id);
  
  GHashTable *ht = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
  g_hash_table_insert (ht, "subject", title);
  g_hash_table_insert (ht, "id", name);
  g_hash_table_insert (ht, "owner", admin);
  
  return ht;
}
示例#2
0
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
  connection_data *conn = TLS->ev_base;
  struct tgl_message *M = C->msg;
  char *text = NULL;
  int flags = 0;

  // only display new messages, ignore updates or deletions
  if ((M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) ||
      !(M->flags & TGLMF_CREATED) ||
      !M->message ||
      tgp_outgoing_msg (TLS, M) ||
      !tgl_get_peer_type (M->to_id)) {
    return;
  }

  if (M->flags & TGLMF_SERVICE) {
    text = format_service_msg (TLS, M);
    flags |= PURPLE_MESSAGE_SYSTEM;
  }
  else if (M->media.type == tgl_message_media_document && M->media.document->flags & TGLDF_STICKER) {
#ifdef HAVE_LIBWEBP
    char *filename = C->data;
    int img = p2tgl_imgstore_add_with_id_webp (filename);
    if (img <= 0) { failure ("Cannot display sticker, adding to imgstore failed"); return; }
    used_images_add (conn, img);
    text = format_img_full (img);
    flags |= PURPLE_MESSAGE_IMAGES;
    g_free (filename);
#else
    char *txt_user = p2tgl_strdup_alias (tgl_peer_get (TLS, M->from_id));
    text = g_strdup_printf ("%s sent a sticker", txt_user);
    flags |= PURPLE_MESSAGE_SYSTEM;
    g_free (txt_user);
#endif
  }
  else if (M->media.type == tgl_message_media_photo ||
          (M->media.type == tgl_message_media_document_encr && M->media.encr_document->flags & TGLDF_IMAGE)) {
    char *filename = C->data;
    int img = p2tgl_imgstore_add_with_id (filename);
    if (img <= 0) {
      failure ("Cannot display picture message, adding to imgstore failed.");
      return;
    }
    used_images_add (conn, img);
    text = format_img_full (img);
    flags |= PURPLE_MESSAGE_IMAGES;
    g_free (filename);
  }
  else if (M->media.type == tgl_message_media_document) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! tgp_our_msg(TLS, M)) {
      tgprpl_recv_file (conn->gc, who, M->media.document);
    }
    g_free (who);
    return;
  }
  else if (M->media.type == tgl_message_media_document_encr) {
    char *who = p2tgl_strdup_id (M->to_id);
    if (! tgp_our_msg(TLS, M)) {
      tgprpl_recv_encr_file (conn->gc, who, M->media.encr_document);
    }
    g_free (who);
    return;
  }
  else {
    text = format_message (M);
    flags |= PURPLE_MESSAGE_RECV;
  }
  
  if (! text || ! *text) {
    warning ("No text to display");
    return;
  }
  switch (tgl_get_peer_type (M->to_id)) {
    case TGL_PEER_CHAT: {
      if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) {
        p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date);
      }
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_ENCR_CHAT: {
      p2tgl_got_im (TLS, M->to_id, text, flags, M->date);
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_USER: {
      if (tgp_our_msg (TLS, M)) {
        flags |= PURPLE_MESSAGE_SEND;
        flags &= ~PURPLE_MESSAGE_RECV;
        p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
      } else {
        p2tgl_got_im (TLS, M->from_id, text, flags, M->date);
        pending_reads_add (conn->pending_reads, M->from_id);
      }
      break;
    }
  }
  
  if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa)) && p2tgl_send_notifications(conn->pa)) {
    pending_reads_send_all (conn->pending_reads, conn->TLS);
  }
  
  g_free (text);
}
示例#3
0
static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) {
  connection_data *conn = TLS->ev_base;
  struct tgl_message *M = C->msg;
  char *text = NULL;
  int flags = 0;
  
  // Filter message updates and deletes, are not created and
  // all messages in general that were already displayed, or shouldn't be displayed
  if ((M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) ||
      !(M->flags & FLAG_CREATED) ||
      !M->message ||
      our_msg (TLS, M) ||
      !tgl_get_peer_type (M->to_id)) {
    return;
  }
  
  
  if (M->service) {
    text = format_service_msg (TLS, M);
    flags |= PURPLE_MESSAGE_SYSTEM;
  }
  else if (M->media.type == tgl_message_media_document) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! out_msg(TLS, M)) {
      tgprpl_recv_file (conn->gc, who, &M->media.document);
    }
    g_free (who);
    return;
  }
  else if (M->media.type == tgl_message_media_document_encr) {
    char *who = p2tgl_strdup_id (M->from_id);
    if (! out_msg(TLS, M)) {
      tgprpl_recv_encr_file (conn->gc, who, &M->media.encr_document);
    }
    g_free (who);
  }
  else if (M->media.type == tgl_message_media_photo) {
    char *filename = C->data;
    int imgStoreId = p2tgl_imgstore_add_with_id (filename);
    if (imgStoreId <= 0) {
      failure ("Cannot display picture message, adding to imgstore failed.");
      return;
    }
    used_images_add (conn, imgStoreId);
    text = format_img_full (imgStoreId);
    flags |= PURPLE_MESSAGE_IMAGES;
  }
  else {
    text = format_message (M);
    flags |= PURPLE_MESSAGE_RECV;
  }
  
  
  if (! text || ! *text) {
    warning ("No text to display");
    return;
  }
  switch (tgl_get_peer_type (M->to_id)) {
    case TGL_PEER_CHAT: {
      if (chat_show (conn->gc, tgl_get_peer_id (M->to_id))) {
        p2tgl_got_chat_in (TLS, M->to_id, M->from_id, text, flags, M->date);
      }
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_ENCR_CHAT: {
      p2tgl_got_im (TLS, M->to_id, text, flags, M->date);
      pending_reads_add (conn->pending_reads, M->to_id);
      break;
    }
    case TGL_PEER_USER: {
      if (out_msg (TLS, M)) {
        flags |= PURPLE_MESSAGE_SEND;
        flags &= ~PURPLE_MESSAGE_RECV;
        p2tgl_got_im_combo (TLS, M->to_id, text, flags, M->date);
      } else {
        p2tgl_got_im (TLS, M->from_id, text, flags, M->date);
        pending_reads_add (conn->pending_reads, M->from_id);
      }
      break;
    }
  }
  
  
  if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa))) {
    pending_reads_send_all (conn->pending_reads, conn->TLS);
  }

  
  g_free (text);
}