Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Mobile
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
199
Issues
199
List
Boards
Labels
Service Desk
Milestones
Merge Requests
18
Merge Requests
18
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Minds
Minds Mobile
Compare Revisions
7ad581c49f73621a2f0b835b30bb4b2090d352c0...04b7da57f844e1403de99d503946eae83e59af62
Source
04b7da57f844e1403de99d503946eae83e59af62
Select Git revision
...
Target
7ad581c49f73621a2f0b835b30bb4b2090d352c0
Select Git revision
Compare
Commits (2)
(feat) ignore aborts on log service exception handling
· 1452f069
Martin Santangelo
authored
4 hours ago
1452f069
(feat) handle 403 in entity service, delete cache and react in UI
· 04b7da57
Martin Santangelo
authored
16 minutes ago
04b7da57
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
17 deletions
+63
-17
src/common/BaseModel.js
src/common/BaseModel.js
+9
-2
src/common/services/api.service.js
src/common/services/api.service.js
+4
-0
src/common/services/entities.service.js
src/common/services/entities.service.js
+31
-5
src/common/services/log.service.js
src/common/services/log.service.js
+3
-5
src/common/services/sql/entities.storage.js
src/common/services/sql/entities.storage.js
+9
-0
src/newsfeed/ActivityModel.js
src/newsfeed/ActivityModel.js
+1
-5
src/newsfeed/ActivityScreen.js
src/newsfeed/ActivityScreen.js
+6
-0
No files found.
src/common/BaseModel.js
View file @
04b7da57
...
...
@@ -52,6 +52,13 @@ export default class BaseModel {
return
this
.
__list
;
}
@
action
removeFromList
()
{
if
(
this
.
_list
)
{
this
.
_list
.
remove
(
this
);
}
}
toPlainObject
()
{
const
plainEntity
=
toJS
(
this
);
...
...
@@ -92,9 +99,9 @@ export default class BaseModel {
const
childs
=
this
.
childModels
();
Object
.
getOwnPropertyNames
(
this
).
forEach
(
key
=>
{
if
(
data
[
key
])
{
if
(
data
[
key
]
!==
undefined
)
{
if
(
childs
[
key
])
{
if
(
childs
[
key
]
&&
this
[
key
]
&&
this
[
key
].
update
)
{
// we update the child model
this
[
key
].
update
(
data
[
key
]);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/common/services/api.service.js
View file @
04b7da57
...
...
@@ -21,6 +21,10 @@ export const isApiError = function(err) {
return
err
instanceof
ApiError
;
}
export
const
isApiForbidden
=
function
(
err
)
{
return
err
instanceof
ApiError
&&
err
.
status
==
403
;
}
/**
* Api service
*/
...
...
This diff is collapsed.
Click to expand it.
src/common/services/entities.service.js
View file @
04b7da57
// @flow
import
_
from
'
lodash
'
;
import
apiService
from
"
./api.service
"
;
import
apiService
,
{
isApiForbidden
,
ApiError
}
from
"
./api.service
"
;
import
sessionService
from
"
./session.service
"
;
import
blockListService
from
"
./block-list.service
"
;
import
GroupModel
from
"
../../groups/GroupModel
"
;
...
...
@@ -67,6 +67,15 @@ class EntitiesService {
entitiesStorage
.
remove
(
urn
);
}
/**
* Delete an entity from the cache
* @param {Array<string>} urn
*/
deleteManyFromCache
(
urns
:
Array
<
string
>
)
{
urns
.
forEach
((
urn
:
string
):
boolean
=>
this
.
entities
.
delete
(
urn
));
entitiesStorage
.
removeMany
(
urns
);
}
/**
* Get entities from feed
* @param {Array} feed
...
...
@@ -185,7 +194,7 @@ class EntitiesService {
* @param {boolean} asActivities
* @return []
*/
async
fetch
(
urns
:
Array
<
string
>
,
abortTag
:
any
,
asActivities
:
boolean
=
false
):
Promise
<
Array
<
Object
>
>
{
async
fetch
(
urns
:
Array
<
string
>
,
abortTag
:
any
,
asActivities
:
boolean
=
false
):
Promise
<
void
>
{
try
{
const
response
:
any
=
await
apiService
.
get
(
'
api/v2/entities/
'
,
{
urns
,
as_activities
:
asActivities
?
1
:
0
},
abortTag
);
...
...
@@ -193,10 +202,25 @@ class EntitiesService {
for
(
const
entity
of
response
.
entities
)
{
this
.
addEntity
(
entity
);
}
return
response
;
}
catch
(
err
)
{
console
.
log
(
err
)
// if the server response is a 403
if
(
isApiForbidden
(
err
))
{
// if the entity exists in the cache, remove the permissions to force the UI update
urns
.
forEach
((
urn
:
string
)
=>
{
const
cache
=
this
.
entities
.
get
(
urn
);
if
(
cache
)
{
// remove permissions
cache
.
entity
.
setPermissions
({
permissions
:[]});
// if the entity is attached to a list we remove if from the list
cache
.
entity
.
removeFromList
();
}
})
// remove it from memory and local storage
this
.
deleteManyFromCache
(
urns
);
return
;
}
throw
err
;
}
}
...
...
@@ -211,6 +235,7 @@ class EntitiesService {
this
.
cleanEntity
(
entity
);
const
storedEntity
=
this
.
getFromCache
(
entity
.
urn
);
if
(
storedEntity
)
{
storedEntity
.
update
(
entity
);
}
else
{
...
...
@@ -254,6 +279,7 @@ class EntitiesService {
return
ActivityModel
.
create
(
entity
);
}
}
return
ActivityModel
.
create
(
entity
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/common/services/log.service.js
View file @
04b7da57
import
deviceLog
,
{
LogView
,
InMemoryAdapter
}
from
'
react-native-device-log
'
;
import
deviceLog
from
'
react-native-device-log
'
;
import
*
as
stacktraceParser
from
"
stacktrace-parser
"
;
import
AsyncStorage
from
'
@react-native-community/async-storage
'
;
import
storageService
from
'
./storage.service
'
;
import
settingsService
from
'
../../settings/SettingsService
'
import
settingsStore
from
'
../../settings/SettingsStore
'
;
import
*
as
Sentry
from
'
@sentry/react-native
'
;
import
{
isNetworkFail
}
from
'
../helpers/abortableFetch
'
;
import
{
isNetworkFail
,
isAbort
}
from
'
../helpers/abortableFetch
'
;
import
{
ApiError
}
from
'
./api.service
'
;
const
parseErrorStack
=
error
=>
{
...
...
@@ -77,7 +75,7 @@ class LogService {
}
// do not log request or api errors < 500
if
(
!
isNetworkFail
(
error
)
&&
(
!
this
.
isApiError
(
error
)
||
this
.
isUnexpectedError
(
error
)))
{
if
(
!
isNetworkFail
(
error
)
&&
(
!
this
.
isApiError
(
error
)
||
this
.
isUnexpectedError
(
error
))
&&
!
isAbort
(
error
)
)
{
// report the issue to sentry
Sentry
.
captureException
(
error
);
...
...
This diff is collapsed.
Click to expand it.
src/common/services/sql/entities.storage.js
View file @
04b7da57
...
...
@@ -87,6 +87,15 @@ export class EntitiesStorage {
return
await
this
.
db
.
executeSql
(
'
DELETE FROM entities WHERE urn=?
'
,
[
urn
]);
}
/**
* Remove many entities
* @param {Array} urns
*/
async
removeMany
(
urns
)
{
const
urnsIn
=
"
('
"
+
urns
.
join
(
"
','
"
)
+
"
')
"
;
return
await
this
.
db
.
executeSql
(
'
DELETE FROM entities WHERE urn IN
'
+
urnsIn
);
}
/**
* Remove all entities
*/
...
...
This diff is collapsed.
Click to expand it.
src/newsfeed/ActivityModel.js
View file @
04b7da57
...
...
@@ -222,11 +222,7 @@ export default class ActivityModel extends BaseModel {
async
deleteEntity
()
{
try
{
await
deleteItem
(
this
.
guid
)
if
(
this
.
_list
)
{
runInAction
(()
=>
{
this
.
_list
.
remove
(
this
);
});
}
this
.
removeFromList
();
entitiesService
.
deleteFromCache
(
this
.
urn
)
}
catch
(
err
)
{
logService
.
exception
(
'
[ActivityModel]
'
,
err
);
...
...
This diff is collapsed.
Click to expand it.
src/newsfeed/ActivityScreen.js
View file @
04b7da57
...
...
@@ -125,6 +125,12 @@ class ActivityScreen extends Component {
*/
render
()
{
if
(
!
this
.
entityStore
.
entity
&&
!
this
.
entityStore
.
errorLoading
)
return
<
CenteredLoading
/>
;
if
(
!
this
.
entityStore
.
entity
.
can
(
FLAG_VIEW
,
true
))
{
this
.
props
.
navigation
.
goBack
();
return
null
;
}
return
(
<
View
style
=
{[
CS
.
flexContainer
,
CS
.
backgroundWhite
]}
>
{
...
...
This diff is collapsed.
Click to expand it.