Generalize status setting (mute, etc.)
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);
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) {
- blerg->meta->status |= BLERGMETA_MUTED;
+ blerg->meta->status |= status;
} else {
- blerg->meta->status &= ~BLERGMETA_MUTED;
+ blerg->meta->status &= ~status;
}
return 1;
}
-int blerg_get_mute(struct blerg *blerg) {
+int blerg_get_status(struct blerg *blerg, uint32_t status) {
CHECK_VALID_BLERG(0)
- return (blerg->meta->status & BLERGMETA_MUTED) > 0;
+ return (blerg->meta->status & status) > 0;
}
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;
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
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:
- RETVAL = blerg_set_mute(ptr, v);
+ RETVAL = blerg_set_status(ptr, status, v);
OUTPUT:
RETVAL
-int _get_mute(struct blerg *ptr)
+int _get_status(struct blerg *ptr, int status)
CODE:
- RETVAL = blerg_get_mute(ptr);
+ RETVAL = blerg_get_status(ptr, status);
OUTPUT:
RETVAL
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.
- 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'},
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
+ PROXYSUBS => 1,
);
}
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 {
- 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);
}
}
=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()
use strict;
use warnings;
-use Test::More tests => 26;
+use Test::More tests => 30;
BEGIN { use_ok('Blerg::Database') };
#########################
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 );
-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 );
$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;
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];
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) {