Example #1
0
void ggp_chat_got_message(PurpleConnection *gc, uint64_t chat_id,
	const char *message, time_t time, uin_t who)
{
	ggp_chat_local_info *chat;
	uin_t me;

	me = ggp_str_to_uin(purple_account_get_username(
		purple_connection_get_account(gc)));

	chat = ggp_chat_get(gc, chat_id);
	if (!chat) {
		purple_debug_error("gg", "ggp_chat_got_message: "
			"chat %" G_GUINT64_FORMAT " doesn't exists\n", chat_id);
		return;
	}

	ggp_chat_open_conv(chat);
	if (who == me) {
		PurpleMessage *pmsg;

		pmsg = purple_message_new_outgoing(
			ggp_uin_to_str(who), message, 0);
		purple_message_set_time(pmsg, time);

		purple_conversation_write_message(
			PURPLE_CONVERSATION(chat->conv), pmsg);
	} else {
		purple_serv_got_chat_in(gc, chat->local_id, ggp_uin_to_str(who),
			PURPLE_MESSAGE_RECV, message, time);
	}
}
Example #2
0
void
fb_util_serv_got_im(PurpleConnection *gc, const gchar *who, const gchar *text,
                    PurpleMessageFlags flags, guint64 timestamp)
{
	const gchar *name;
	PurpleAccount *acct;
	PurpleIMConversation *conv;
	PurpleMessage *msg;

	if (!(flags & PURPLE_MESSAGE_SEND)) {
		purple_serv_got_im(gc, who, text, flags, timestamp);
		return;
	}

	acct = purple_connection_get_account(gc);
	conv = purple_conversations_find_im_with_account(who, acct);

	if (conv == NULL) {
		conv = purple_im_conversation_new(acct, who);
	}

	name = purple_account_get_username(acct);
	msg = purple_message_new_outgoing(name, text, flags);
	purple_message_set_time(msg, timestamp);
	purple_conversation_write_message(PURPLE_CONVERSATION(conv), msg);
}
Example #3
0
static PurpleCmdRet send_whisper(PurpleConversation *conv, const gchar *cmd,
                                 gchar **args, gchar **error, void *userdata) {
  const char *to_username;
  const char *message;
  const char *from_username;
  PurpleChatUser *chat_user;
  PurpleConnection *to;

  /* parse args */
  to_username = args[0];
  message = args[1];

  if (!to_username || !*to_username) {
    *error = g_strdup(_("Whisper is missing recipient."));
    return PURPLE_CMD_RET_FAILED;
  } else if (!message || !*message) {
    *error = g_strdup(_("Whisper is missing message."));
    return PURPLE_CMD_RET_FAILED;
  }

  from_username = purple_account_get_username(purple_conversation_get_account(conv));
  purple_debug_info("nullprpl", "%s whispers to %s in chat room %s: %s\n",
                    from_username, to_username,
                    purple_conversation_get_name(conv), message);

  chat_user = purple_chat_conversation_find_user(PURPLE_CHAT_CONVERSATION(conv), to_username);
  to = get_nullprpl_gc(to_username);

  if (!chat_user) {
    /* this will be freed by the caller */
    *error = g_strdup_printf(_("%s is not logged in."), to_username);
    return PURPLE_CMD_RET_FAILED;
  } else if (!to) {
    *error = g_strdup_printf(_("%s is not in this chat room."), to_username);
    return PURPLE_CMD_RET_FAILED;
  } else {
    /* write the whisper in the sender's chat window  */
    char *message_to = g_strdup_printf("%s (to %s)", message, to_username);
    purple_conversation_write_message(conv, from_username, message_to,
                                      PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_WHISPER,
                                      time(NULL));
    g_free(message_to);

    /* send the whisper */
    purple_serv_chat_whisper(to, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(conv)),
                      from_username, message);

    return PURPLE_CMD_RET_OK;
  }
}
Example #4
0
static void set_chat_topic_fn(PurpleChatConversation *from, PurpleChatConversation *to,
                              int id, const char *room, gpointer userdata) {
  const char *topic = (const char *)userdata;
  const char *username = purple_account_get_username(purple_conversation_get_account(PURPLE_CONVERSATION(from)));
  char *msg;

  purple_chat_conversation_set_topic(to, username, topic);

  if (topic && *topic)
    msg = g_strdup_printf(_("%s sets topic to: %s"), username, topic);
  else
    msg = g_strdup_printf(_("%s clears topic"), username);

  purple_conversation_write_message(PURPLE_CONVERSATION(to), username, msg,
                                    PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG,
                                    time(NULL));
  g_free(msg);
}