2020-05-09 14:07:21 +02:00
|
|
|
#include "chat-info.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-05-12 15:21:16 +02:00
|
|
|
static const char *_(const char *s) { return s; }
|
|
|
|
|
2020-05-12 19:37:59 +02:00
|
|
|
static char idKey[] = "id";
|
|
|
|
static char inviteKey[] = "link";
|
2020-05-09 14:07:21 +02:00
|
|
|
|
|
|
|
GList *getChatJoinInfo()
|
|
|
|
{
|
2020-05-12 15:21:16 +02:00
|
|
|
// First entry is the internal chat name used to look up conversations
|
2020-05-09 14:07:21 +02:00
|
|
|
struct proto_chat_entry *pce;
|
|
|
|
pce = g_new0 (struct proto_chat_entry, 1);
|
2020-05-12 15:21:16 +02:00
|
|
|
pce->label = _("Chat ID (leave empty):");
|
2020-05-09 14:07:21 +02:00
|
|
|
pce->identifier = idKey;
|
|
|
|
pce->required = FALSE;
|
|
|
|
GList *info = g_list_append (NULL, pce);
|
|
|
|
|
|
|
|
pce = g_new0 (struct proto_chat_entry, 1);
|
2020-05-12 15:21:16 +02:00
|
|
|
pce->label = _("Invite link (empty if creating new):");
|
2020-05-12 19:37:59 +02:00
|
|
|
pce->identifier = inviteKey;
|
2020-05-09 14:07:21 +02:00
|
|
|
pce->required = FALSE;
|
|
|
|
info = g_list_append (info, pce);
|
|
|
|
|
|
|
|
pce = g_new0 (struct proto_chat_entry, 1);
|
2020-05-12 15:21:16 +02:00
|
|
|
pce->label = _("Subject (if creating a group):");
|
2020-05-09 14:07:21 +02:00
|
|
|
pce->identifier = "subject";
|
|
|
|
pce->required = FALSE;
|
|
|
|
info = g_list_append (info, pce);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getChatName(const td::td_api::chat &chat)
|
|
|
|
{
|
2020-05-09 19:53:06 +02:00
|
|
|
return "chat" + std::to_string(chat.id_);
|
2020-05-09 14:07:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GHashTable *getChatComponents(const td::td_api::chat &chat)
|
|
|
|
{
|
|
|
|
char name[32];
|
2020-05-16 14:13:34 +02:00
|
|
|
snprintf(name, sizeof(name)-1, "chat%" G_GINT64_FORMAT "", chat.id_);
|
2020-05-09 14:07:21 +02:00
|
|
|
name[sizeof(name)-1] = '\0';
|
|
|
|
|
|
|
|
GHashTable *table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
|
|
|
|
g_hash_table_insert(table, idKey, g_strdup(name));
|
|
|
|
return table;
|
|
|
|
}
|
2020-05-10 12:05:55 +02:00
|
|
|
|
|
|
|
const char *getChatName(GHashTable *components)
|
|
|
|
{
|
|
|
|
return (const char *)g_hash_table_lookup(components, idKey);
|
|
|
|
}
|
|
|
|
|
2020-05-12 19:37:59 +02:00
|
|
|
const char *getChatInviteLink(GHashTable *components)
|
|
|
|
{
|
|
|
|
return (const char *)g_hash_table_lookup(components, inviteKey);
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:05:55 +02:00
|
|
|
int64_t getTdlibChatId(const char *chatName)
|
|
|
|
{
|
|
|
|
if (chatName && !strncmp(chatName, "chat", 4)) {
|
2020-05-13 15:59:45 +12:00
|
|
|
int64_t id;
|
|
|
|
if (sscanf(chatName+4, "%" G_GINT64_FORMAT "", &id) == 1)
|
2020-05-10 12:05:55 +02:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|