From 614d23926454c60f3f7f1a9f10382300c5584c58 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Thu, 20 Jul 2017 18:54:19 +0000 Subject: [PATCH] Remove group chats --- ext/tox/extconf.rb | 5 -- ext/tox/tox.c | 136 --------------------------------------- lib/lita/adapters/tox.rb | 20 +----- lib/tox.rb | 8 --- 4 files changed, 1 insertion(+), 168 deletions(-) diff --git a/ext/tox/extconf.rb b/ext/tox/extconf.rb index 3d4e464..b8465f5 100755 --- a/ext/tox/extconf.rb +++ b/ext/tox/extconf.rb @@ -28,11 +28,6 @@ have_library LIBTOXCORE, 'tox_friend_add_norequest' and have_library LIBTOXCORE, 'tox_friend_send_message' and have_library LIBTOXCORE, 'tox_callback_friend_request' and have_library LIBTOXCORE, 'tox_callback_friend_message' and -have_library LIBTOXCORE, 'tox_join_groupchat' and -have_library LIBTOXCORE, 'tox_group_message_send' and -have_library LIBTOXCORE, 'tox_callback_group_invite' and -have_library LIBTOXCORE, 'tox_callback_group_message' and -have_library LIBTOXCORE, 'tox_group_peernumber_is_ours' and have_library LIBTOXCORE, 'tox_self_get_name_size' and have_library LIBTOXCORE, 'tox_self_get_name' and have_library LIBTOXCORE, 'tox_self_set_name' and diff --git a/ext/tox/tox.c b/ext/tox/tox.c index ea7bec1..0d9163f 100644 --- a/ext/tox/tox.c +++ b/ext/tox/tox.c @@ -40,9 +40,6 @@ static VALUE cTox_kill(VALUE self); static VALUE cTox_loop(VALUE self); static VALUE cTox_friend_add_norequest(VALUE self, VALUE key); static VALUE cTox_friend_send_message(VALUE self, VALUE friend_number, VALUE text); -static VALUE cTox_join_groupchat(VALUE self, VALUE friend_number, VALUE data); -static VALUE cTox_group_message_send(VALUE self, VALUE group_number, VALUE text); -static VALUE cTox_group_peernumber_is_ours(VALUE self, VALUE group_number, VALUE peer_number); static VALUE cTox_name(VALUE self); static VALUE cTox_name_ASSIGN(VALUE self, VALUE name); static VALUE cTox_status_message(VALUE self); @@ -63,24 +60,6 @@ static void on_friend_message( size_t length, VALUE self); -static void on_group_invite( - Tox *tox, - int32_t friend_number, - uint8_t type, - const uint8_t *data, - uint16_t length, - VALUE self - ); - -static void on_group_message( - Tox *tox, - int group_number, - int peer_number, - const uint8_t *text, - uint16_t length, - VALUE self - ); - typedef struct Tox_Options cTox_cOptions_; static VALUE cTox_cOptions; @@ -105,9 +84,6 @@ void Init_tox() rb_define_method(cTox, "loop", cTox_loop, 0); rb_define_method(cTox, "friend_add_norequest", cTox_friend_add_norequest, 1); rb_define_method(cTox, "friend_send_message", cTox_friend_send_message, 2); - rb_define_method(cTox, "join_groupchat", cTox_join_groupchat, 2); - rb_define_method(cTox, "group_message_send", cTox_group_message_send, 2); - rb_define_method(cTox, "group_peernumber_is_ours", cTox_group_peernumber_is_ours, 2); rb_define_method(cTox, "name", cTox_name, 0); rb_define_method(cTox, "name=", cTox_name_ASSIGN, 1); rb_define_method(cTox, "status_message", cTox_status_message, 0); @@ -170,14 +146,6 @@ VALUE cTox_initialize_with(const VALUE self, const VALUE options) tox_callback_friend_request(tox->tox, (tox_friend_request_cb*)on_friend_request, (void*)self); tox_callback_friend_message(tox->tox, (tox_friend_message_cb*)on_friend_message, (void*)self); - tox_callback_group_invite( - tox->tox, - (void (*)(struct Tox *, int32_t, uint8_t, const uint8_t *, uint16_t, void *))on_group_invite, - (void*)self); - tox_callback_group_message( - tox->tox, - (void (*)(struct Tox *, int, int, const uint8_t *, uint16_t, void *))on_group_message, - (void*)self); return self; } @@ -321,65 +289,6 @@ VALUE cTox_friend_send_message(const VALUE self, const VALUE friend_number, cons )); } -VALUE cTox_join_groupchat(const VALUE self, const VALUE friend_number, const VALUE data) -{ - cTox_ *tox; - - // Don't know yet how to check for integers - // Check_Type(friend_number, T_INTEGER); - Check_Type(data, T_STRING); - - Data_Get_Struct(self, cTox_, tox); - - return INT2FIX(tox_join_groupchat( - tox->tox, - NUM2LONG(friend_number), - (uint8_t*)RSTRING_PTR(data), - RSTRING_LEN(data) - )); -} - -VALUE cTox_group_message_send(const VALUE self, const VALUE group_number, const VALUE text) -{ - cTox_ *tox; - - // Don't know yet how to check for integers - // Check_Type(group_number, T_INTEGER); - Check_Type(text, T_STRING); - - Data_Get_Struct(self, cTox_, tox); - - return INT2FIX(tox_group_message_send( - tox->tox, - NUM2LONG(group_number), - (uint8_t*)RSTRING_PTR(text), - RSTRING_LEN(text) - )); -} - -VALUE cTox_group_peernumber_is_ours( - const VALUE self, - const VALUE group_number, - const VALUE peer_number) -{ - cTox_ *tox; - - // Don't know yet how to check for integers - // Check_Type(group_number, T_INTEGER); - // Check_Type(peer_number, T_INTEGER); - - Data_Get_Struct(self, cTox_, tox); - - if (tox_group_peernumber_is_ours( - tox->tox, - NUM2INT(group_number), - NUM2INT(peer_number)) - ) - return Qtrue; - else - return Qfalse; -} - VALUE cTox_name(const VALUE self) { cTox_ *tox; @@ -498,51 +407,6 @@ void on_friend_message( ); } -static void on_group_invite( - Tox *const tox, - const int32_t friend_number, - const uint8_t type, - const uint8_t *const data, - const uint16_t length, - const VALUE self) -{ - VALUE rb_on_group_invite; - - rb_on_group_invite = rb_iv_get(self, "@on_group_invite"); - - if (Qnil != rb_on_group_invite) - rb_funcall( - rb_on_group_invite, - rb_intern("call"), - 2, - LONG2FIX(friend_number), - rb_str_new((char*)data, length) - ); -} - -static void on_group_message( - Tox *const tox, - const int group_number, - const int peer_number, - const uint8_t *const text, - const uint16_t length, - const VALUE self) -{ - VALUE rb_on_group_message; - - rb_on_group_message = rb_iv_get(self, "@on_group_message"); - - if (Qnil != rb_on_group_message) - rb_funcall( - rb_on_group_message, - rb_intern("call"), - 3, - LONG2FIX(group_number), - LONG2FIX(peer_number), - rb_str_new((char*)text, length) - ); -} - /****************************************************************************** * Tox::Options ******************************************************************************/ diff --git a/lib/lita/adapters/tox.rb b/lib/lita/adapters/tox.rb index 768bcea..4a61bb1 100644 --- a/lib/lita/adapters/tox.rb +++ b/lib/lita/adapters/tox.rb @@ -45,20 +45,6 @@ module Lita message.command! robot.receive(message) end - - @tox.on_group_invite do |friend_number, data| - @tox.join_groupchat(friend_number, data) - end - - @tox.on_group_message do |group_number, peer_number, text| - unless @tox.group_peernumber_is_ours(group_number, peer_number) - user = User.new(-1 - peer_number) # TODO - source = Source.new(user: user, room: group_number) - message = Message.new(robot, text, source) - - robot.receive(message) - end - end end def run @@ -77,11 +63,7 @@ module Lita def send_messages(target, messages) messages.reject(&:empty?).each do |message| - if target.user.id.to_i >= 0 - @tox.friend_send_message(target.user.id.to_i, message) - else - @tox.group_message_send(target.room.to_i, message) - end + @tox.friend_send_message(target.user.id.to_i, message) end end end diff --git a/lib/tox.rb b/lib/tox.rb index f390ecf..ccab134 100644 --- a/lib/tox.rb +++ b/lib/tox.rb @@ -50,12 +50,4 @@ class Tox def on_friend_message(&block) @on_friend_message = block end - - def on_group_invite(&block) - @on_group_invite = block - end - - def on_group_message(&block) - @on_group_message = block - end end