]> www.infradead.org Git - pidgin-chime.git/commitdiff
Fix for attachment ignore problem
authorAhmet Ipkin <ipkiahme@amazon.com>
Tue, 10 Dec 2019 22:03:36 +0000 (23:03 +0100)
committerAhmet Ipkin <ipkiahme@amazon.com>
Tue, 10 Dec 2019 22:13:46 +0000 (23:13 +0100)
prpl/chat.c
prpl/conversations.c

index 30b6434646066454c70b201aa82e3348ca708cd1..7a67bfdf15090a322ceeffc7f8c022d020774223 100644 (file)
@@ -146,8 +146,7 @@ static void do_chat_deliver_msg(ChimeConnection *cxn, struct chime_msgs *msgs,
        int id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(chat->conv));
        const gchar *content, *sender;
 
-       if (!parse_string(node, "Content", &content) ||
-           !parse_string(node, "Sender", &sender))
+       if (!parse_string(node, "Sender", &sender))
                return;
 
        const gchar *from = _("Unknown sender");
@@ -163,19 +162,6 @@ static void do_chat_deliver_msg(ChimeConnection *cxn, struct chime_msgs *msgs,
                msg_flags = PURPLE_MESSAGE_RECV;
        }
 
-       gchar *escaped = g_markup_escape_text(content, -1);
-
-       gchar *parsed = NULL;
-       if (CHIME_IS_ROOM(chat->m.obj)) {
-               if (parse_inbound_mentions(cxn, pc->mention_regex, escaped, &parsed) &&
-                   (msg_flags & PURPLE_MESSAGE_RECV)) {
-                       // Presumably this will trigger a notification.
-                       msg_flags |= PURPLE_MESSAGE_NICK;
-               }
-               g_free(escaped);
-       } else
-               parsed = escaped;
-
        ChimeAttachment *att = extract_attachment(node);
        if (att) {
                AttachmentContext *ctx = g_new(AttachmentContext, 1);
@@ -188,12 +174,27 @@ static void do_chat_deliver_msg(ChimeConnection *cxn, struct chime_msgs *msgs,
                download_attachment(cxn, att, ctx);
        }
 
-       serv_got_chat_in(conn, id, from, msg_flags, parsed, msg_time);
+       if (parse_string(node, "Content", &content)) {
+               gchar *escaped = g_markup_escape_text(content, -1);
+
+               gchar *parsed = NULL;
+               if (CHIME_IS_ROOM(chat->m.obj)) {
+                       if (parse_inbound_mentions(cxn, pc->mention_regex, escaped, &parsed)
+                                       && (msg_flags & PURPLE_MESSAGE_RECV)) {
+                               // Presumably this will trigger a notification.
+                               msg_flags |= PURPLE_MESSAGE_NICK;
+                       }
+                       g_free(escaped);
+               } else
+                       parsed = escaped;
+
+               serv_got_chat_in(conn, id, from, msg_flags, parsed, msg_time);
+               g_free(parsed);
+       }
        /* If the conversation already had focus and unseen-count didn't change, fake
           a PURPLE_CONV_UPDATE_UNSEEN notification anyway, so that we see that it's
           (still) zero and tell the server it's read. */
        purple_conversation_update(chat->conv, PURPLE_CONV_UPDATE_UNSEEN);
-       g_free(parsed);
 }
 
 static gint participant_sort(gconstpointer a, gconstpointer b)
index fd6252e3b8086ba2cf33b83e7f4a7233e1a28cac..1c9a731ae5b35b3c74e60fc259810781bd7ac6a8 100644 (file)
@@ -39,12 +39,11 @@ static gboolean do_conv_deliver_msg(ChimeConnection *cxn, struct chime_im *im,
 {
        const gchar *sender, *message;
        gint64 sys;
-
        if (!parse_string(record, "Sender", &sender) ||
-           !parse_string(record, "Content", &message) ||
            !parse_int(record, "IsSystemMessage", &sys))
                return FALSE;
 
+
        PurpleMessageFlags flags = 0;
        if (sys)
                flags |= PURPLE_MESSAGE_SYSTEM;
@@ -58,7 +57,6 @@ static gboolean do_conv_deliver_msg(ChimeConnection *cxn, struct chime_im *im,
                if (who)
                        from = chime_contact_get_email(who);
        }
-       gchar *escaped = g_markup_escape_text(message, -1);
 
        ChimeAttachment *att = extract_attachment(record);
        if (att) {
@@ -71,39 +69,47 @@ static gboolean do_conv_deliver_msg(ChimeConnection *cxn, struct chime_im *im,
                /* The attachment and context structs will be owned by the code doing the download and will be disposed of at the end. */
                download_attachment(cxn, att, ctx);
        }
-
-       if (!strcmp(sender, chime_connection_get_profile_id(cxn))) {
-               /* Ick, how do we inject a message from ourselves? */
-               PurpleAccount *account = im->m.conn->account;
-               PurpleConversation *pconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
-                                                                                 email, account);
-               if (!pconv) {
-                       pconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, email);
+       // Download messages don't have 'content' but normal messages do.
+       // if you receive one, parse it:
+       if (parse_string(record, "Content", &message)) {
+               gchar *escaped = g_markup_escape_text(message, -1);
+
+               if (!strcmp(sender, chime_connection_get_profile_id(cxn))) {
+                       /* Ick, how do we inject a message from ourselves? */
+                       PurpleAccount *account = im->m.conn->account;
+                       PurpleConversation *pconv = purple_find_conversation_with_account(
+                                       PURPLE_CONV_TYPE_IM, email, account);
                        if (!pconv) {
-                               purple_debug_error("chime", "NO CONV FOR %s\n", email);
-                               g_free(escaped);
-                               return FALSE;
+                               pconv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account,
+                                                                                               email);
+                               if (!pconv) {
+                                       purple_debug_error("chime", "NO CONV FOR %s\n", email);
+                                       g_free(escaped);
+                                       return FALSE;
+                               }
+                       }
+                       purple_conversation_write(pconv, NULL, escaped,
+                                       flags | PURPLE_MESSAGE_SEND, msg_time);
+                       purple_signal_emit(purple_connection_get_prpl(account->gc),
+                                       "chime-got-convmsg", pconv, TRUE, record);
+               } else {
+                       serv_got_im(im->m.conn, email, escaped, flags | PURPLE_MESSAGE_RECV,
+                                               msg_time);
+
+                       /* If the conversation already had focus and unseen-count didn't change, fake
+                        a PURPLE_CONV_UPDATE_UNSEEN notification anyway, so that we see that it's
+                        (still) zero and tell the server it's read. */
+                       PurpleConversation *pconv = purple_find_conversation_with_account(
+                                       PURPLE_CONV_TYPE_IM, email, im->m.conn->account);
+                       if (pconv) {
+                               purple_conversation_update(pconv, PURPLE_CONV_UPDATE_UNSEEN);
+                               purple_signal_emit(purple_connection_get_prpl(im->m.conn),
+                                                                  "chime-got-convmsg", pconv, FALSE, record);
                        }
-               }
-               purple_conversation_write(pconv, NULL, escaped, flags | PURPLE_MESSAGE_SEND, msg_time);
-               purple_signal_emit(purple_connection_get_prpl(account->gc), "chime-got-convmsg",
-                                  pconv, TRUE, record);
-       } else {
-               serv_got_im(im->m.conn, email, escaped, flags | PURPLE_MESSAGE_RECV, msg_time);
-
-               /* If the conversation already had focus and unseen-count didn't change, fake
-                  a PURPLE_CONV_UPDATE_UNSEEN notification anyway, so that we see that it's
-                  (still) zero and tell the server it's read. */
-               PurpleConversation *pconv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
-                                                                                 email, im->m.conn->account);
-               if (pconv) {
-                       purple_conversation_update(pconv, PURPLE_CONV_UPDATE_UNSEEN);
-                       purple_signal_emit(purple_connection_get_prpl(im->m.conn),
-                                          "chime-got-convmsg", pconv, FALSE, record);
-               }
 
+               }
+               g_free(escaped);
        }
-       g_free(escaped);
        return TRUE;
 }