Compare commits
4 Commits
develop
...
fix.unread
Author | SHA1 | Date |
---|---|---|
|
180e877fcf | |
|
702ffb9e58 | |
|
aa63357231 | |
|
7ca2c3cfee |
|
@ -59,6 +59,7 @@ const RoomItem = ({
|
||||||
toggleFav={toggleFav}
|
toggleFav={toggleFav}
|
||||||
isRead={isRead}
|
isRead={isRead}
|
||||||
rid={rid}
|
rid={rid}
|
||||||
|
tunread={tunread}
|
||||||
toggleRead={toggleRead}
|
toggleRead={toggleRead}
|
||||||
hideChannel={hideChannel}
|
hideChannel={hideChannel}
|
||||||
testID={testID}
|
testID={testID}
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Touchable extends React.Component {
|
||||||
favorite: PropTypes.bool,
|
favorite: PropTypes.bool,
|
||||||
isRead: PropTypes.bool,
|
isRead: PropTypes.bool,
|
||||||
rid: PropTypes.string,
|
rid: PropTypes.string,
|
||||||
|
tunread: PropTypes.array,
|
||||||
toggleFav: PropTypes.func,
|
toggleFav: PropTypes.func,
|
||||||
toggleRead: PropTypes.func,
|
toggleRead: PropTypes.func,
|
||||||
hideChannel: PropTypes.func,
|
hideChannel: PropTypes.func,
|
||||||
|
@ -177,9 +178,12 @@ class Touchable extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
toggleRead = () => {
|
toggleRead = () => {
|
||||||
const { toggleRead, rid, isRead } = this.props;
|
const {
|
||||||
|
toggleRead, rid, isRead, tunread
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
if (toggleRead) {
|
if (toggleRead) {
|
||||||
toggleRead(rid, isRead);
|
toggleRead(rid, isRead, tunread);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -632,18 +632,40 @@ class RoomsListView extends React.Component {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
toggleRead = async(rid, isRead) => {
|
readThreads = async(tunread) => {
|
||||||
|
const result = [];
|
||||||
|
for (let i = 0; i < tunread.length; i += 1) {
|
||||||
|
const tmid = tunread[i];
|
||||||
|
try {
|
||||||
|
if (tmid) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const response = await RocketChat.readThreads(tmid);
|
||||||
|
result.push(response.success);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logEvent(events.RL_TOGGLE_READ_F);
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.every(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleRead = async(rid, isRead, tunread) => {
|
||||||
logEvent(isRead ? events.RL_UNREAD_CHANNEL : events.RL_READ_CHANNEL);
|
logEvent(isRead ? events.RL_UNREAD_CHANNEL : events.RL_READ_CHANNEL);
|
||||||
try {
|
try {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const result = await RocketChat.toggleRead(isRead, rid);
|
const result = await RocketChat.toggleRead(isRead, rid);
|
||||||
if (result.success) {
|
const threadResult = tunread?.length > 0 ? await this.readThreads(tunread) : true;
|
||||||
|
|
||||||
|
if (result.success && threadResult) {
|
||||||
const subCollection = db.get('subscriptions');
|
const subCollection = db.get('subscriptions');
|
||||||
await db.action(async() => {
|
await db.action(async() => {
|
||||||
try {
|
try {
|
||||||
const subRecord = await subCollection.find(rid);
|
const subRecord = await subCollection.find(rid);
|
||||||
await subRecord.update((sub) => {
|
await subRecord.update((sub) => {
|
||||||
sub.alert = isRead;
|
sub.alert = isRead;
|
||||||
|
sub.unread = 0;
|
||||||
|
sub.tunread = tunread && [];
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
|
|
Loading…
Reference in New Issue