projects
/
blerg.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7a1c067
)
Generalize status setting (mute, etc.)
author
Chip Black
<bytex64@bytex64.net>
Sun, 29 Jun 2014 06:16:00 +0000
(
01:16
-0500)
committer
Chip Black
<bytex64@bytex64.net>
Sun, 29 Jun 2014 06:16:37 +0000
(
01:16
-0500)
database/database.c
patch
|
blob
|
history
database/database.h
patch
|
blob
|
history
lib/perl/Blerg-Database/Database.xs
patch
|
blob
|
history
lib/perl/Blerg-Database/Makefile.PL
patch
|
blob
|
history
lib/perl/Blerg-Database/lib/Blerg/Database.pm
patch
|
blob
|
history
lib/perl/Blerg-Database/t/database.t
patch
|
blob
|
history
tools/blergtool.c
patch
|
blob
|
history
diff --git
a/database/database.c
b/database/database.c
index
e0c9eb7
..
fd8279c
100644
(file)
--- a/
database/database.c
+++ b/
database/database.c
@@
-291,7
+291,7
@@
uint64_t blerg_store(struct blerg *blerg, const char *data, int length) {
flock(blerg->data_fd, LOCK_UN);
flock(blerg->index_fd, LOCK_UN);
flock(blerg->data_fd, LOCK_UN);
flock(blerg->index_fd, LOCK_UN);
- if (!blerg_get_
mute(blerg
)) {
+ if (!blerg_get_
status(blerg, BLERGSTATUS_MUTED
)) {
/* Now do those dirty microblogging deeds */
tag_scan(blerg->name, data, length, record);
subscription_notify(blerg->name, record);
/* Now do those dirty microblogging deeds */
tag_scan(blerg->name, data, length, record);
subscription_notify(blerg->name, record);
@@
-379,17
+379,17
@@
uint64_t blerg_get_subscription_mark(struct blerg *blerg) {
return blerg->meta->subscription_mark;
}
return blerg->meta->subscription_mark;
}
-int blerg_set_
mute(struct blerg *blerg
, int v) {
+int blerg_set_
status(struct blerg *blerg, uint32_t status
, int v) {
CHECK_VALID_BLERG(0)
if (v) {
CHECK_VALID_BLERG(0)
if (v) {
- blerg->meta->status |=
BLERGMETA_MUTED
;
+ blerg->meta->status |=
status
;
} else {
} else {
- blerg->meta->status &= ~
BLERGMETA_MUTED
;
+ blerg->meta->status &= ~
status
;
}
return 1;
}
}
return 1;
}
-int blerg_get_
mute(struct blerg *blerg
) {
+int blerg_get_
status(struct blerg *blerg, uint32_t status
) {
CHECK_VALID_BLERG(0)
CHECK_VALID_BLERG(0)
- return (blerg->meta->status &
BLERGMETA_MUTED
) > 0;
+ return (blerg->meta->status &
status
) > 0;
}
}
diff --git
a/database/database.h
b/database/database.h
index
7971249
..
15fd072
100644
(file)
--- a/
database/database.h
+++ b/
database/database.h
@@
-23,7
+23,12
@@
struct meta {
uint32_t status;
};
uint32_t status;
};
-#define BLERGMETA_MUTED 0x00000001
+/* meta.status is a bitfield of these options */
+/* Muted - if set, tags/refs and subscriptions are not calculated */
+#define BLERGSTATUS_MUTED 0x00000001
+/* Mentioned - if set, user has been mentioned. Cleared by /status/<user> with
+ * {"clear": "mentioned"} */
+#define BLERGSTATUS_MENTIONED 0x00000002
struct blerg {
int meta_fd;
struct blerg {
int meta_fd;
@@
-50,7
+55,7
@@
uint64_t blerg_get_record_count(struct blerg *);
time_t blerg_get_timestamp(struct blerg *blerg, uint64_t record);
int blerg_set_subscription_mark(struct blerg *blerg);
uint64_t blerg_get_subscription_mark(struct blerg *blerg);
time_t blerg_get_timestamp(struct blerg *blerg, uint64_t record);
int blerg_set_subscription_mark(struct blerg *blerg);
uint64_t blerg_get_subscription_mark(struct blerg *blerg);
-int blerg_set_
mute(struct blerg *blerg
, int v);
-int blerg_get_
mute(struct blerg *blerg
);
+int blerg_set_
status(struct blerg *blerg, uint32_t status
, int v);
+int blerg_get_
status(struct blerg *blerg, uint32_t status
);
#endif //_DATABASE_H
#endif //_DATABASE_H
diff --git
a/lib/perl/Blerg-Database/Database.xs
b/lib/perl/Blerg-Database/Database.xs
index
1911538
..
e3614db
100644
(file)
--- a/
lib/perl/Blerg-Database/Database.xs
+++ b/
lib/perl/Blerg-Database/Database.xs
@@
-117,15
+117,15
@@
const char * _get_subscription_mark(struct blerg *ptr)
n = snprintf(buf, 21, "%llu", mark);
XPUSHs(sv_2mortal(newSVpv(buf, n)));
n = snprintf(buf, 21, "%llu", mark);
XPUSHs(sv_2mortal(newSVpv(buf, n)));
-int _set_
mute(struct blerg *ptr
, int v)
+int _set_
status(struct blerg *ptr, int status
, int v)
CODE:
CODE:
- RETVAL = blerg_set_
mute(ptr
, v);
+ RETVAL = blerg_set_
status(ptr, status
, v);
OUTPUT:
RETVAL
OUTPUT:
RETVAL
-int _get_
mute(struct blerg *ptr
)
+int _get_
status(struct blerg *ptr, int status
)
CODE:
CODE:
- RETVAL = blerg_get_
mute(ptr
);
+ RETVAL = blerg_get_
status(ptr, status
);
OUTPUT:
RETVAL
OUTPUT:
RETVAL
diff --git
a/lib/perl/Blerg-Database/Makefile.PL
b/lib/perl/Blerg-Database/Makefile.PL
index
6003b64
..
5f0ab24
100644
(file)
--- a/
lib/perl/Blerg-Database/Makefile.PL
+++ b/
lib/perl/Blerg-Database/Makefile.PL
@@
-13,15
+13,13
@@
WriteMakefile(
OBJECT => '$(BASEEXT)$(OBJ_EXT) ../../../blerg.a ../../../blerg_auth.a ../../../builddeps/scrypt.a',
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I../../..', # e.g., '-I. -I/usr/include/other'
OBJECT => '$(BASEEXT)$(OBJ_EXT) ../../../blerg.a ../../../blerg_auth.a ../../../builddeps/scrypt.a',
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I../../..', # e.g., '-I. -I/usr/include/other'
- # Un-comment this if you add C files to link with later:
- # OBJECT => '$(O_FILES)', # link all the C files too
);
if (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
);
if (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
- my @names = (qw(RECORDS_PER_SEGMENT MAX_RECORD_SIZE MAX_TAG_LENGTH MAX_TAGS_PER_RECORD),
+ my @names = (qw(RECORDS_PER_SEGMENT MAX_RECORD_SIZE MAX_TAG_LENGTH MAX_TAGS_PER_RECORD
BLERGSTATUS_MUTED BLERGSTATUS_MENTIONED
),
{name => 'BASEURL', type => 'PV'},
{name => 'DATA_PATH', type => 'PV'},
{name => 'HASH_TAGS_PATH', type => 'PV'},
{name => 'BASEURL', type => 'PV'},
{name => 'DATA_PATH', type => 'PV'},
{name => 'HASH_TAGS_PATH', type => 'PV'},
@@
-33,6
+31,7
@@
if (eval {require ExtUtils::Constant; 1}) {
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
+ PROXYSUBS => 1,
);
}
);
}
diff --git
a/lib/perl/Blerg-Database/lib/Blerg/Database.pm
b/lib/perl/Blerg-Database/lib/Blerg/Database.pm
index
d71340d
..
bf41706
100644
(file)
--- a/
lib/perl/Blerg-Database/lib/Blerg/Database.pm
+++ b/
lib/perl/Blerg-Database/lib/Blerg/Database.pm
@@
-130,9
+130,19
@@
sub mute {
my ($obj, $v) = @_;
$obj->_ensure_pointer;
if (defined $v) {
my ($obj, $v) = @_;
$obj->_ensure_pointer;
if (defined $v) {
- return Blerg::Database::_set_
mute($obj->{ptr}
, $v);
+ return Blerg::Database::_set_
status($obj->{ptr}, $obj->BLERGSTATUS_MUTED
, $v);
} else {
} else {
- return Blerg::Database::_get_mute($obj->{ptr});
+ return Blerg::Database::_get_status($obj->{ptr}, $obj->BLERGSTATUS_MUTED);
+ }
+}
+
+sub mention {
+ my ($obj, $v) = @_;
+ $obj->_ensure_pointer;
+ if (defined $v) {
+ return Blerg::Database::_set_status($obj->{ptr}, $obj->BLERGSTATUS_MENTIONED, $v);
+ } else {
+ return Blerg::Database::_get_status($obj->{ptr}, $obj->BLERGSTATUS_MENTIONED);
}
}
}
}
@@
-303,7
+313,7
@@
C<tag_list('@' . $obj-E<gt>{name})>.
=item mute(v)
=item mute(v)
-When v = 1, mute the user, otherwise, unmute.
+When v = 1, mute the user, otherwise, unmute.
If v is absent, return the mute status.
=item close()
=item close()
diff --git
a/lib/perl/Blerg-Database/t/database.t
b/lib/perl/Blerg-Database/t/database.t
index
203d286
..
2944a06
100644
(file)
--- a/
lib/perl/Blerg-Database/t/database.t
+++ b/
lib/perl/Blerg-Database/t/database.t
@@
-9,7
+9,7
@@
use File::Path qw/remove_tree/;
use strict;
use warnings;
use strict;
use warnings;
-use Test::More tests =>
26
;
+use Test::More tests =>
30
;
BEGIN { use_ok('Blerg::Database') };
#########################
BEGIN { use_ok('Blerg::Database') };
#########################
@@
-68,14
+68,14
@@
ok( @list == 3 );
ok( $list[0]->{author} eq $test_user );
ok( $list[0]->{record} == $n );
ok( $list[0]->{author} eq $test_user );
ok( $list[0]->{record} == $n );
-# Test
mute
-ok( Blerg::Database::_set_
mute($ptr
, 1) );
-ok( Blerg::Database::_get_
mute($ptr
) == 1 );
+# Test
status
+ok( Blerg::Database::_set_
status($ptr, Blerg::Database::BLERGSTATUS_MUTED
, 1) );
+ok( Blerg::Database::_get_
status($ptr, Blerg::Database::BLERGSTATUS_MUTED
) == 1 );
Blerg::Database::_store($ptr, "Testing more #data");
@list = Blerg::Database::tag_list('#data', 0, 1);
ok( @list == 3 );
Blerg::Database::_store($ptr, "Testing more #data");
@list = Blerg::Database::tag_list('#data', 0, 1);
ok( @list == 3 );
-ok( Blerg::Database::_set_
mute($ptr
, 0) );
-ok( Blerg::Database::_get_
mute($ptr
) == 0 );
+ok( Blerg::Database::_set_
status($ptr, Blerg::Database::BLERGSTATUS_MUTED
, 0) );
+ok( Blerg::Database::_get_
status($ptr, Blerg::Database::BLERGSTATUS_MUTED
) == 0 );
Blerg::Database::_store($ptr, "Testing more #data");
@list = Blerg::Database::tag_list('#data', 0, 1);
ok( @list == 4 );
Blerg::Database::_store($ptr, "Testing more #data");
@list = Blerg::Database::tag_list('#data', 0, 1);
ok( @list == 4 );
@@
-109,6
+109,12
@@
ok( $blerg->store($data) == $n + 1 );
$n++;
ok( $blerg->fetch($n) eq $data );
$n++;
ok( $blerg->fetch($n) eq $data );
+# Mute
+ok( $blerg->mute(1) );
+ok( $blerg->mute == 1 );
+ok( $blerg->mute(0) );
+ok( $blerg->mute == 0 );
+
# Close database
$blerg->close;
# Close database
$blerg->close;
diff --git
a/tools/blergtool.c
b/tools/blergtool.c
index
eee8aef
..
c689d2f
100644
(file)
--- a/
tools/blergtool.c
+++ b/
tools/blergtool.c
@@
-93,7
+93,7
@@
int main(int argc, char *argv[]) {
exit(1);
}
exit(1);
}
- blerg_set_
mute(f
, 1);
+ blerg_set_
status(f, BLERGSTATUS_MUTED
, 1);
blerg_close(f);
} else if (strncmp(argv[1], "unmute", 6) == 0) {
char *store = argv[2];
blerg_close(f);
} else if (strncmp(argv[1], "unmute", 6) == 0) {
char *store = argv[2];
@@
-103,7
+103,7
@@
int main(int argc, char *argv[]) {
exit(1);
}
exit(1);
}
- blerg_set_
mute(f
, 0);
+ blerg_set_
status(f, BLERGSTATUS_MUTED
, 0);
blerg_close(f);
} else if (strncmp(argv[1], "subscribe", 9) == 0) {
if (argc < 4) {
blerg_close(f);
} else if (strncmp(argv[1], "subscribe", 9) == 0) {
if (argc < 4) {