harness: attachments named by real m.filename, not the caption; mimetype-derived extension fallback
This commit is contained in:
1 parent
e212e3e120
commit
cbe99e89d0
3 files changed
+35
-2
No files matched your search
+8
-1
@@ -339,6 +339,8 @@ pub const Event = struct {
|
||||
url: ?[]u8 = null, // allocated; caller frees
|
||||
mimetype: []u8 = "", // allocated; caller frees
|
||||
size: i64 = 0,
|
||||
/// Original attachment filename (distinct from body, which is the caption).
|
||||
filename: []u8 = &.{}, // allocated; caller frees
|
||||
};
|
||||
|
||||
/// One sync poll. Returns message events + next `since` token. Caller frees.
|
||||
@@ -438,6 +440,11 @@ pub fn sync(alloc: std.mem.Allocator, io: Io, token: []const u8, since: []const
|
||||
|
||||
// Attachment fields (m.file / m.image / m.audio / m.video).
|
||||
var url_copy: ?[]u8 = null;
|
||||
var fname_copy: []u8 = "";
|
||||
if (content.get("filename")) |f| switch (f) {
|
||||
.string => |v| fname_copy = alloc.dupe(u8, v) catch "",
|
||||
else => {},
|
||||
};
|
||||
if (content.get("url")) |u| switch (u) {
|
||||
.string => |v| url_copy = alloc.dupe(u8, v) catch null,
|
||||
else => {},
|
||||
@@ -463,7 +470,7 @@ pub fn sync(alloc: std.mem.Allocator, io: Io, token: []const u8, since: []const
|
||||
alloc.free(sender_copy);
|
||||
continue;
|
||||
};
|
||||
events.append(alloc, .{ .sender = sender_copy, .body = body_copy, .ts = ts, .url = url_copy, .mimetype = mime, .size = size }) catch {
|
||||
events.append(alloc, .{ .sender = sender_copy, .body = body_copy, .ts = ts, .url = url_copy, .filename = fname_copy, .mimetype = mime, .size = size }) catch {
|
||||
alloc.free(sender_copy);
|
||||
alloc.free(body_copy);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user