diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-04 12:22:09 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-11-04 16:24:46 +0000 |
commit | 574d1468432bd066dfe7a50fed8c2bbae5d71975 (patch) | |
tree | 5bf3e45ffd3ad49d170a1398fe6bc48b8d7d6778 | |
parent | 46da670d5c0fa51b92a168d454d23e9b119e349a (diff) |
IMChannel: split incoming message and report handling
As a nice side effect, the new _gabble_im_channel_report_delivery()
function can do successful delivery reports if send_error ==
GABBLE_TEXT_CHANNEL_SEND_NO_ERROR. This will become useful
momentarily...
The funky formatting is to make clearer that this patch is mostly moving
code around unmodified; a subsequent patch will clean it up.
-rw-r--r-- | src/im-channel.c | 57 | ||||
-rw-r--r-- | src/im-channel.h | 11 | ||||
-rw-r--r-- | src/im-factory.c | 18 |
3 files changed, 58 insertions, 28 deletions
diff --git a/src/im-channel.c b/src/im-channel.c index 36fcd85f8..4ff438a1c 100644 --- a/src/im-channel.c +++ b/src/im-channel.c @@ -444,24 +444,18 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, time_t timestamp, const gchar *id, const char *text, - TpChannelTextSendError send_error, - TpDeliveryStatus delivery_status, gint state) { GabbleIMChannelPrivate *priv; TpBaseChannel *base_chan; - TpBaseConnection *base_conn; TpHandle peer; TpMessage *msg; - gchar *tmp; g_assert (GABBLE_IS_IM_CHANNEL (chan)); priv = chan->priv; base_chan = (TpBaseChannel *) chan; - base_conn = tp_base_channel_get_connection (base_chan); peer = tp_base_channel_get_target_handle (base_chan); - if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR) { /* update peer's full JID if it's changed */ if (tp_strdiff (from, priv->peer_jid)) @@ -479,20 +473,9 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, _gabble_im_channel_state_receive (chan, state); } } - else - { - /* strip off the resource (if any), since we just failed to send to it */ - char *slash = strchr (priv->peer_jid, '/'); - - if (slash != NULL) - *slash = '\0'; - - priv->chat_states_supported = CHAT_STATES_UNKNOWN; - } msg = build_message (chan, type, timestamp, text); - if (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR) { tp_cm_message_set_sender (msg, peer); tp_message_set_int64 (msg, 0, "message-received", time (NULL)); @@ -502,9 +485,45 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, tp_message_mixin_take_received (G_OBJECT (chan), msg); } - else +} + +void +_gabble_im_channel_report_delivery ( + GabbleIMChannel *self, + TpChannelTextMessageType type, + time_t timestamp, + const gchar *id, + const char *text, + TpChannelTextSendError send_error, + TpDeliveryStatus delivery_status) +{ + GabbleIMChannelPrivate *priv; + TpBaseChannel *base_chan = (TpBaseChannel *) self; + TpBaseConnection *base_conn; + TpHandle peer; + TpMessage *msg; + + g_return_if_fail (GABBLE_IS_IM_CHANNEL (self)); + priv = self->priv; + peer = tp_base_channel_get_target_handle (base_chan); + base_conn = tp_base_channel_get_connection (base_chan); + + if (send_error != GABBLE_TEXT_CHANNEL_SEND_NO_ERROR) + { + /* strip off the resource (if any), since we just failed to send to it */ + char *slash = strchr (priv->peer_jid, '/'); + + if (slash != NULL) + *slash = '\0'; + + priv->chat_states_supported = CHAT_STATES_UNKNOWN; + } + + msg = build_message (self, type, timestamp, text); + { TpMessage *delivery_report = tp_cm_message_new (base_conn, 1); + gchar *tmp; tp_message_set_uint32 (delivery_report, 0, "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); @@ -533,7 +552,7 @@ _gabble_im_channel_receive (GabbleIMChannel *chan, tp_cm_message_take_message (delivery_report, 0, "delivery-echo", msg); - tp_message_mixin_take_received (G_OBJECT (chan), delivery_report); + tp_message_mixin_take_received (G_OBJECT (self), delivery_report); } } diff --git a/src/im-channel.h b/src/im-channel.h index 1280e44da..fdbae19bf 100644 --- a/src/im-channel.h +++ b/src/im-channel.h @@ -70,12 +70,19 @@ void _gabble_im_channel_receive (GabbleIMChannel *chan, time_t timestamp, const char *id, const char *text, - TpChannelTextSendError send_error, - TpDeliveryStatus delivery_status, gint state); void _gabble_im_channel_state_receive (GabbleIMChannel *chan, TpChannelChatState state); +void _gabble_im_channel_report_delivery ( + GabbleIMChannel *self, + TpChannelTextMessageType type, + time_t timestamp, + const gchar *id, + const char *text, + TpChannelTextSendError send_error, + TpDeliveryStatus delivery_status); + G_END_DECLS #endif /* #ifndef __GABBLE_IM_CHANNEL_H__*/ diff --git a/src/im-factory.c b/src/im-factory.c index cd82810e4..0cd805610 100644 --- a/src/im-factory.c +++ b/src/im-factory.c @@ -248,14 +248,18 @@ im_factory_message_cb (LmMessageHandler *handler, DEBUG ("got error sending to %s, msgtype %u, body:\n%s", from, msgtype, body); - } - - if (body != NULL) - _gabble_im_channel_receive (chan, msgtype, from, stamp, id, body, - send_error, delivery_status, state); - else if (state != -1 && send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR) - _gabble_im_channel_state_receive (chan, (TpChannelChatState) state); + _gabble_im_channel_report_delivery (chan, msgtype, stamp, id, body, + send_error, delivery_status); + } + else if (body != NULL) + { + _gabble_im_channel_receive (chan, msgtype, from, stamp, id, body, state); + } + else if (state != -1) + { + _gabble_im_channel_state_receive (chan, (TpChannelChatState) state); + } return LM_HANDLER_RESULT_REMOVE_MESSAGE; } |