Skip to content

Commit

Permalink
block message recall
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 27, 2017
1 parent 53fae2b commit b4ecd45
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ API from [https://web.wechat.com/](https://web.wechat.com/)
## Feature
- Work on desktop
- On macOS, window vibrancy effect
- Block message recall
- Desktop notifications
- Send image by paste
![preview](https://raw.githubusercontent.com/trazyn/weweChat/master/screenshots/pasteconfirmation.png)
Expand Down
11 changes: 11 additions & 0 deletions src/js/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import helper from 'utils/helper';
setDownloads: stores.settings.setDownloads,
confirmImagePaste: stores.settings.confirmImagePaste,
setConfirmImagePaste: stores.settings.setConfirmImagePaste,
blockRecall: stores.settings.blockRecall,
setBlockRecall: stores.settings.setBlockRecall,
user: stores.session.user,
logout: stores.session.logout,

Expand Down Expand Up @@ -72,6 +74,8 @@ export default class Settings extends Component {
setDownloads,
confirmImagePaste,
setConfirmImagePaste,
blockRecall,
setBlockRecall,
plugins,
user,
} = this.props;
Expand Down Expand Up @@ -120,6 +124,13 @@ export default class Settings extends Component {
</label>
</li>

<li>
<label htmlFor="blockRecall">
<span>Block Message Recall</span>
<Switch id="blockRecall" checked={blockRecall} onChange={e => setBlockRecall(e.target.checked)} />
</label>
</li>

<li>
<label htmlFor="confirmImagePaste">
<span>Image paste Confirmation</span>
Expand Down
11 changes: 8 additions & 3 deletions src/js/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ipcRenderer } from 'electron';
import storage from 'utils/storage';
import helper from 'utils/helper';
import contacts from './contacts';
import settings from './settings';
import session from './session';
import members from './members';
import snackbar from './snackbar';
Expand Down Expand Up @@ -82,7 +83,7 @@ async function resolveMessage(message) {

message.MsgType += 2000;
message.transfer = {
desc: value,
desc: value.des,
money: +value.match(/[\d.]+元/)[0].slice(0, -1),
};
break;
Expand Down Expand Up @@ -122,9 +123,13 @@ async function resolveMessage(message) {

case 10002:
let text = isChatRoom ? message.Content.split(':<br/>').slice(-1).pop() : message.Content;
let { value } = helper.parseXml(text, 'replacemsg');
let { value } = helper.parseXml(text, ['replacemsg', 'msgid']);

message.Content = value;
if (!settings.blockRecall) {
self.deleteMessage(message.FromUserName, value.msgid);
}

message.Content = value.replacemsg;
message.MsgType = 19999;
break;

Expand Down
16 changes: 13 additions & 3 deletions src/js/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Settings {
@observable showNotification = true;
@observable confirmImagePaste = true;
@observable startup = false;
@observable blockRecall = false;
@observable downloads = '';
@observable plugins = [{
name: 'Message Backup',
Expand All @@ -26,6 +27,11 @@ class Settings {
self.save();
}

@action setBlockRecall(blockRecall) {
self.blockRecall = blockRecall;
self.save();
}

@action setShowOnTray(showOnTray) {
self.showOnTray = showOnTray;
self.save();
Expand Down Expand Up @@ -53,7 +59,7 @@ class Settings {

@action async init() {
var settings = await storage.get('settings');
var { alwaysOnTop, showOnTray, showNotification, startup, downloads } = self;
var { alwaysOnTop, showOnTray, showNotification, blockRecall, startup, downloads } = self;

if (settings && Object.keys(settings).length) {
// Use !! force convert to a bool value
Expand All @@ -62,14 +68,16 @@ class Settings {
self.showNotification = !!settings.showNotification;
self.confirmImagePaste = !!settings.confirmImagePaste;
self.startup = !!settings.startup;
self.downloads = !!settings.downloads;
self.downloads = settings.downloads;
self.blockRecall = !!settings.blockRecall;
} else {
await storage.set('settings', {
alwaysOnTop,
showOnTray,
showNotification,
startup,
downloads,
blockRecall,
});
}

Expand All @@ -87,7 +95,7 @@ class Settings {
}

save() {
var { alwaysOnTop, showOnTray, showNotification, confirmImagePaste, startup, downloads } = self;
var { alwaysOnTop, showOnTray, showNotification, confirmImagePaste, blockRecall, startup, downloads } = self;

storage.set('settings', {
alwaysOnTop,
Expand All @@ -96,6 +104,7 @@ class Settings {
confirmImagePaste,
startup,
downloads,
blockRecall,
});

ipcRenderer.send('settings-apply', {
Expand All @@ -106,6 +115,7 @@ class Settings {
confirmImagePaste,
startup,
downloads,
blockRecall,
}
});
}
Expand Down
10 changes: 6 additions & 4 deletions src/js/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ const helper = {
parseXml: (text, tagName) => {
var parser = new window.DOMParser();
var xml = parser.parseFromString(text.replace(/&lt;/g, '<').replace(/&gt;/g, '>'), 'text/xml');
var value;
var value = {};

if (tagName) {
value = xml.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
}
tagName = Array.isArray(tagName) ? tagName : [tagName];

tagName.map(e => {
value[e] = xml.getElementsByTagName(e)[0].childNodes[0].nodeValue;
});

return { xml, value };
},
Expand Down

0 comments on commit b4ecd45

Please sign in to comment.