Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32158980
client-db-utils.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
client-db-utils.js
View Options
// @flow
import
type
{
ClientDBMessageStoreOperation
}
from
'lib/ops/message-store-ops.js'
;
import
{
threadStoreOpsHandlers
}
from
'lib/ops/thread-store-ops.js'
;
import
{
createUpdateDBOpsForThreadStoreThreadInfos
}
from
'lib/shared/redux/client-db-utils.js'
;
import
type
{
RawMessageInfo
,
ClientDBMessageInfo
,
ClientDBThreadMessageInfo
,
}
from
'lib/types/message-types.js'
;
import
type
{
RawThreadInfos
}
from
'lib/types/thread-types.js'
;
import
{
translateClientDBMessageInfoToRawMessageInfo
,
translateRawMessageInfoToClientDBMessageInfo
,
translateClientDBThreadMessageInfos
,
translateThreadMessageInfoToClientDBThreadMessageInfo
,
type
TranslatedThreadMessageInfos
,
}
from
'lib/utils/message-ops-utils.js'
;
import
{
entries
}
from
'lib/utils/objects.js'
;
import
type
{
AppState
}
from
'./state-types.js'
;
import
{
commCoreModule
}
from
'../native-modules.js'
;
function
updateClientDBThreadStoreThreadInfos
(
state
:
AppState
,
migrationFunc
:
RawThreadInfos
=>
RawThreadInfos
,
handleMigrationFailure
?:
AppState
=>
AppState
,
)
:
AppState
{
const
clientDBThreadInfos
=
commCoreModule
.
getAllThreadsSync
();
const
operations
=
createUpdateDBOpsForThreadStoreThreadInfos
(
clientDBThreadInfos
,
migrationFunc
,
);
const
dbOperations
=
threadStoreOpsHandlers
.
convertOpsToClientDBOps
(
operations
);
try
{
commCoreModule
.
processThreadStoreOperationsSync
(
dbOperations
);
}
catch
(
exception
)
{
console
.
log
(
exception
);
if
(
handleMigrationFailure
)
{
return
handleMigrationFailure
(
state
);
}
return
({
...
state
,
cookie
:
null
}
:
any
);
}
return
state
;
}
function
createUpdateDBOpsForMessageStoreMessages
(
clientDBMessageInfos
:
$ReadOnlyArray
<
ClientDBMessageInfo
>
,
migrationFunc
:
(
$ReadOnlyArray
<
RawMessageInfo
>
,
)
=>
$ReadOnlyArray
<
RawMessageInfo
>
,
)
:
$ReadOnlyArray
<
ClientDBMessageStoreOperation
>
{
const
rawMessageInfos
=
clientDBMessageInfos
.
map
(
translateClientDBMessageInfoToRawMessageInfo
,
);
const
convertedRawMessageInfos
=
migrationFunc
(
rawMessageInfos
);
const
replaceMessagesOperations
:
$ReadOnlyArray
<
ClientDBMessageStoreOperation
>
=
convertedRawMessageInfos
.
map
(
messageInfo
=>
({
type
:
'replace'
,
payload
:
translateRawMessageInfoToClientDBMessageInfo
(
messageInfo
),
}));
return
[
{
type
:
'remove_all'
,
},
...
replaceMessagesOperations
,
];
}
function
createUpdateDBOpsForMessageStoreThreads
(
messageStoreThreads
:
$ReadOnlyArray
<
ClientDBThreadMessageInfo
>
,
migrationFunc
:
TranslatedThreadMessageInfos
=>
TranslatedThreadMessageInfos
,
)
:
$ReadOnlyArray
<
ClientDBMessageStoreOperation
>
{
const
translatedMessageStoreThreads
=
translateClientDBThreadMessageInfos
(
messageStoreThreads
);
const
convertedTranslatedMessageStoreThreads
=
migrationFunc
(
translatedMessageStoreThreads
,
);
return
[
{
type
:
'remove_all_threads'
,
},
{
type
:
'replace_threads'
,
payload
:
{
threads
:
entries
(
convertedTranslatedMessageStoreThreads
).
map
(
([
id
,
thread
])
=>
translateThreadMessageInfoToClientDBThreadMessageInfo
(
id
,
thread
),
),
},
},
];
}
export
{
updateClientDBThreadStoreThreadInfos
,
createUpdateDBOpsForThreadStoreThreadInfos
,
createUpdateDBOpsForMessageStoreMessages
,
createUpdateDBOpsForMessageStoreThreads
,
};
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Dec 7, 4:24 PM (6 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5839545
Default Alt Text
client-db-utils.js (3 KB)
Attached To
Mode
rCOMM Comm
Attached
Detach File
Event Timeline
Log In to Comment