Skip to content

Commit

Permalink
Store stable buffer ID as a string
Browse files Browse the repository at this point in the history
In WeeChat, the buffer ID is of type `long long`, which cannot be safely
represented as a JavaScript number. BigInt can't be serialized, so we
store the ID as a string.
  • Loading branch information
mhoran committed Dec 12, 2024
1 parent 6b3f9d9 commit 2931ab9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions __tests__/lib/weechat/action_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('transformToReduxAction', () => {

expect(store.getState().buffers).toHaveProperty('83a41cd80');
const buffer = store.getState().buffers['83a41cd80'];
expect(buffer._id).toEqual(1730555173010842);
expect(buffer._id).toEqual('1730555173010842');
});

it('defaults _id to the buffer pointer', () => {
Expand All @@ -175,7 +175,7 @@ describe('transformToReduxAction', () => {

expect(store.getState().buffers).toHaveProperty('83a41cd80');
const buffer = store.getState().buffers['83a41cd80'];
expect(buffer._id).toEqual(parseInt('83a41cd80', 16));
expect(buffer._id).toEqual(BigInt('0x83a41cd80').toString());
});
});

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('transformToReduxAction', () => {

expect(store.getState().buffers).toHaveProperty('83a41cd80');
const buffer = store.getState().buffers['83a41cd80'];
expect(buffer._id).toEqual(1730555173010842);
expect(buffer._id).toEqual('1730555173010842');
});

it('defaults _id to the buffer pointer', () => {
Expand All @@ -229,7 +229,7 @@ describe('transformToReduxAction', () => {

expect(store.getState().buffers).toHaveProperty('83a41cd80');
const buffer = store.getState().buffers['83a41cd80'];
expect(buffer._id).toEqual(parseInt('83a41cd80', 16));
expect(buffer._id).toEqual(BigInt('0x83a41cd80').toString());
});
});

Expand Down
10 changes: 5 additions & 5 deletions __tests__/store/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe(PendingBufferNotificationListener, () => {
preloadedState: {
buffers: {
['83a41cd80']: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: '83a41cd80',
Expand Down Expand Up @@ -50,7 +50,7 @@ describe(PendingBufferNotificationListener, () => {
store.dispatch(
actions.pendingBufferNotificationAction({
identifier: '1fb4fc1d-530b-466f-85be-de27772de0a9',
bufferId: 1730555173010842,
bufferId: '1730555173010842',
lineId: 0
})
);
Expand Down Expand Up @@ -88,15 +88,15 @@ describe(PendingBufferNotificationListener, () => {
store.dispatch(
actions.pendingBufferNotificationAction({
identifier: '1fb4fc1d-530b-466f-85be-de27772de0a9',
bufferId: 1730555173010842,
bufferId: '1730555173010842',
lineId: 0
})
);

store.dispatch(
actions.fetchBuffersAction({
['83a41cd80']: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: '83a41cd80',
Expand Down Expand Up @@ -146,7 +146,7 @@ describe(PendingBufferNotificationListener, () => {
store.dispatch(
actions.pendingBufferNotificationAction({
identifier: '1fb4fc1d-530b-466f-85be-de27772de0a9',
bufferId: 1730555173010842,
bufferId: '1730555173010842',
lineId: 0
})
);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/usecase/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('App', () => {
preloadedState: {
buffers: {
[bufferId]: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: bufferId,
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('App', () => {
preloadedState: {
buffers: {
[bufferId]: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: bufferId,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/usecase/buffers/ui/BufferContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('BufferContainer', () => {
preloadedState: {
buffers: {
[bufferId]: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: bufferId,
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('BufferContainer', () => {
preloadedState: {
buffers: {
[bufferId]: {
_id: 1730555173010842,
_id: '1730555173010842',
full_name: 'irc.libera.#weechat',
hidden: 0,
id: bufferId,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/weechat/action_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export const transformToReduxAction = (
const buffer = object.content[0];
buffer._id =
buffer.id !== undefined
? parseInt(buffer.id)
: parseInt(buffer.pointers[0], 16);
? buffer.id
: BigInt(`0x${buffer.pointers[0]}`).toString();
buffer.id = buffer.pointers[0];

return actions.bufferOpenedAction(buffer);
Expand Down Expand Up @@ -201,8 +201,8 @@ export const transformToReduxAction = (
id: buf.pointers[0],
_id:
buf.id !== undefined
? parseInt(buf.id)
: parseInt(buf.pointers[0], 16)
? buf.id
: BigInt(`0x${buf.pointers[0]}`).toString()
})
);
const removed = Object.keys(buffers).filter((buffer) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/weechat/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface WeechatInfoList {

interface WeechatBuffer {
id: string;
_id: number;
_id: string;
pointers: string[];
local_variables: Localvariables;
notify: number;
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const changeCurrentBufferAction = createAction<string>(

export const pendingBufferNotificationAction = createAction<{
identifier: string;
bufferId: number;
bufferId: string;
lineId: number;
}>('PENDING_BUFFER_NOTIFICATION');
export const bufferNotificationAction = createAction<{
Expand Down
2 changes: 1 addition & 1 deletion src/usecase/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class WeechatNative extends React.Component<null, State> {
store.dispatch(
actions.pendingBufferNotificationAction({
identifier: request.identifier,
bufferId: Number(bufferId),
bufferId: BigInt(bufferId as string).toString(),
lineId: Number(lineId)
})
);
Expand Down

0 comments on commit 2931ab9

Please sign in to comment.