Skip to content

Commit

Permalink
Merge branch 'master' into camera
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan authored Sep 21, 2023
2 parents 2ee2693 + 7a85ae2 commit 586ac1a
Show file tree
Hide file tree
Showing 352 changed files with 48,201 additions and 2,649 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
## [1.6-17] - 2023-08-23

### Added

- Add support for status URLs (William Casarin)
- Click music statuses to display in spotify (William Casarin)
- Add settings for disabling user statuses (William Casarin)

### Changed

- clear statuses if they only contain whitespace (William Casarin)

### Fixed

- Fix long status lines (William Casarin)
- Fix status events not expiring locally (William Casarin)

[1.6-17]: https://github.com/damus-io/damus/releases/tag/v1.6-17

## [1.6-16] - 2023-08-23

### Added

- Added live music statuses (William Casarin)
- Added generic user statuses (William Casarin)

### Fixed

- Avoid notification for zaps from muted profiles ([email protected])
- Fix text editing issues on characters added right after mention link (Daniel D’Aquino)
- Mute hellthreads everywhere (William Casarin)


[1.6-16]: https://github.com/damus-io/damus/releases/tag/v1.6-16

## [1.6-13] - 2023-08-18

### Fixed

- Fix bug where it would sometimes show -1 in replies ([email protected])
- Fix images and links occasionally appearing with escaped slashes (Daniel D‘Aquino)
- Fixed nostrscript not working on smaller phones (William Casarin)
- Fix zaps sometimes not appearing (William Casarin)
- Fixed issue where reposts would sometimes repost the wrong thing (William Casarin)
- Fixed issue where sometimes there would be empty entries on your profile (William Casarin)

[1.6-13]: https://github.com/damus-io/damus/releases/tag/v1.6-13


## [1.6-11]: "Bugfix Sunday" - 2023-08-07

### Added
Expand Down Expand Up @@ -1477,3 +1526,4 @@

[0.1.2]: https://github.com/damus-io/damus/releases/tag/v0.1.2


190 changes: 167 additions & 23 deletions damus-c/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ static inline int pull_byte(struct cursor *cursor, u8 *c)
return 1;
}

static inline int parse_byte(struct cursor *cursor, u8 *c)
{
if (unlikely(cursor->p >= cursor->end))
return 0;

*c = *cursor->p;
//cursor->p++;

return 1;
}

static inline int parse_char(struct cursor *cur, char c) {
if (cur->p >= cur->end)
return 0;

if (*cur->p == c) {
cur->p++;
return 1;
}

return 0;
}

static inline int peek_char(struct cursor *cur, int ind) {
if ((cur->p + ind < cur->start) || (cur->p + ind >= cur->end))
return -1;

return *(cur->p + ind);
}

static inline int cursor_pull_c_str(struct cursor *cursor, const char **str)
{
*str = (const char*)cursor->p;
Expand Down Expand Up @@ -435,12 +465,124 @@ static inline int is_whitespace(char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}

static inline int is_underscore(char c) {
return c == '_';
}

static inline int is_utf8_byte(u8 c) {
return c & 0x80;
}

static inline int is_right_boundary(char c) {
return is_whitespace(c) || ispunct(c);
static inline int parse_utf8_char(struct cursor *cursor, unsigned int *code_point, unsigned int *utf8_length)
{
u8 first_byte;
if (!parse_byte(cursor, &first_byte))
return 0; // Not enough data

// Determine the number of bytes in this UTF-8 character
int remaining_bytes = 0;
if (first_byte < 0x80) {
*code_point = first_byte;
return 1;
} else if ((first_byte & 0xE0) == 0xC0) {
remaining_bytes = 1;
*utf8_length = remaining_bytes + 1;
*code_point = first_byte & 0x1F;
} else if ((first_byte & 0xF0) == 0xE0) {
remaining_bytes = 2;
*utf8_length = remaining_bytes + 1;
*code_point = first_byte & 0x0F;
} else if ((first_byte & 0xF8) == 0xF0) {
remaining_bytes = 3;
*utf8_length = remaining_bytes + 1;
*code_point = first_byte & 0x07;
} else {
remaining_bytes = 0;
*utf8_length = 1; // Assume 1 byte length for unrecognized UTF-8 characters
// TODO: We need to gracefully handle unrecognized UTF-8 characters
printf("Invalid UTF-8 byte: %x\n", *code_point);
*code_point = ((first_byte & 0xF0) << 6); // Prevent testing as punctuation
return 0; // Invalid first byte
}

// Peek at remaining bytes
for (int i = 0; i < remaining_bytes; ++i) {
signed char next_byte;
if ((next_byte = peek_char(cursor, i+1)) == -1) {
*utf8_length = 1;
return 0; // Not enough data
}

// Debugging lines
//printf("Cursor: %s\n", cursor->p);
//printf("Codepoint: %x\n", *code_point);
//printf("Codepoint <<6: %x\n", ((*code_point << 6) | (next_byte & 0x3F)));
//printf("Remaining bytes: %x\n", remaining_bytes);
//printf("First byte: %x\n", first_byte);
//printf("Next byte: %x\n", next_byte);
//printf("Bitwise AND result: %x\n", (next_byte & 0xC0));

if ((next_byte & 0xC0) != 0x80) {
*utf8_length = 1;
return 0; // Invalid byte in sequence
}

*code_point = (*code_point << 6) | (next_byte & 0x3F);
}

return 1;
}

/**
* Checks if a given Unicode code point is a punctuation character
*
* @param codepoint The Unicode code point to check. @return true if the
* code point is a punctuation character, false otherwise.
*/
static inline int is_punctuation(unsigned int codepoint) {

// Check for underscore (underscore is not treated as punctuation)
if (is_underscore(codepoint))
return 0;

// Check for ASCII punctuation
if (ispunct(codepoint))
return 1;

// Check for Unicode punctuation exceptions (punctuation allowed in hashtags)
if (codepoint == 0x301C || codepoint == 0xFF5E) // Japanese Wave Dash / Tilde
return 0;

// Check for Unicode punctuation
// NOTE: We may need to adjust the codepoint ranges in the future,
// to include/exclude certain types of Unicode characters in hashtags.
// Unicode Blocks Reference: https://www.compart.com/en/unicode/block
return (
// Latin-1 Supplement No-Break Space (NBSP): U+00A0
(codepoint == 0x00A0) ||

// Latin-1 Supplement Punctuation: U+00A1 to U+00BF
(codepoint >= 0x00A1 && codepoint <= 0x00BF) ||

// General Punctuation: U+2000 to U+206F
(codepoint >= 0x2000 && codepoint <= 0x206F) ||

// Currency Symbols: U+20A0 to U+20CF
(codepoint >= 0x20A0 && codepoint <= 0x20CF) ||

// Supplemental Punctuation: U+2E00 to U+2E7F
(codepoint >= 0x2E00 && codepoint <= 0x2E7F) ||

// CJK Symbols and Punctuation: U+3000 to U+303F
(codepoint >= 0x3000 && codepoint <= 0x303F) ||

// Ideographic Description Characters: U+2FF0 to U+2FFF
(codepoint >= 0x2FF0 && codepoint <= 0x2FFF)
);
}

static inline int is_right_boundary(int c) {
return is_whitespace(c) || is_punctuation(c);
}

static inline int is_left_boundary(char c) {
Expand All @@ -452,15 +594,36 @@ static inline int is_alphanumeric(char c) {
}

static inline int consume_until_boundary(struct cursor *cur) {
char c;
unsigned int c;
unsigned int char_length = 1;
unsigned int *utf8_char_length = &char_length;

while (cur->p < cur->end) {
c = *cur->p;

*utf8_char_length = 1;

if (is_whitespace(c))
return 1;

// Need to check for UTF-8 characters, which can be multiple bytes long
if (is_utf8_byte(c)) {
if (!parse_utf8_char(cur, &c, utf8_char_length)) {
if (!is_right_boundary(c)){
// TODO: We should work towards handling all UTF-8 characters.
printf("Invalid UTF-8 code point: %x\n", c);
}
}
}

if (is_right_boundary(c))
return 1;

cur->p++;
// Need to use a variable character byte length for UTF-8 (2-4 bytes)
if (cur->p + *utf8_char_length <= cur->end)
cur->p += *utf8_char_length;
else
cur->p++;
}

return 1;
Expand Down Expand Up @@ -500,23 +663,4 @@ static inline int consume_until_non_alphanumeric(struct cursor *cur, int or_end)
return or_end;
}

static inline int parse_char(struct cursor *cur, char c) {
if (cur->p >= cur->end)
return 0;

if (*cur->p == c) {
cur->p++;
return 1;
}

return 0;
}

static inline int peek_char(struct cursor *cur, int ind) {
if ((cur->p + ind < cur->start) || (cur->p + ind >= cur->end))
return -1;

return *(cur->p + ind);
}

#endif
1 change: 1 addition & 0 deletions damus-c/damus-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
#include "wasm.h"
#include "nostrscript.h"
#include "nostrdb.h"
#include "lmdb.h"

1 change: 1 addition & 0 deletions damus-c/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -7100,6 +7100,7 @@ int wasm_interp_init(struct wasm_interp *interp, struct module *module)
return 0;
}

// keep total memory size small for now, iOS doesn't like like mallocs
memory_pages_size = 8 * WASM_PAGE_SIZE;

memsize =
Expand Down
Loading

0 comments on commit 586ac1a

Please sign in to comment.