mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-08 01:04:39 +08:00
21bc2ef398
* Move to Slate 44, start using types more extensively in Composer * More types and cleanup * Expose the editor object to the draft session, try exposing editor to session * Bump to Slate 45 for https://github.com/ianstormtaylor/slate/pull/2225/files * How did the unsubscribe plugin get in here * Bump Slate types, fix TS errors, start testing * Polish * Fix issue with emails not shrinking when you close quoted text * Fix the “remove quoted text” button * More polish * Fix issues with PR, improve typings * Remove spurious log
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import React from 'react';
|
|
import { Message, localized, PropTypes, Thread } from 'mailspring-exports';
|
|
import { RetinaImg, BindGlobalCommands } from 'mailspring-component-kit';
|
|
|
|
function unsubscribe(message) {
|
|
//
|
|
}
|
|
|
|
function canUnsubscribe(message) {
|
|
if (message.extraHeaders && message.extraHeaders['X-UNSUBSCRIBE'] !== null) {
|
|
return true;
|
|
}
|
|
if (message.body) {
|
|
console.log('got body!');
|
|
}
|
|
}
|
|
|
|
export default class ThreadUnsubscribeButton extends React.Component<{
|
|
items: Thread[];
|
|
message: Message;
|
|
}> {
|
|
static displayName = 'ThreadUnsubscribeButton';
|
|
|
|
static containerRequired = false;
|
|
|
|
static propTypes = { message: PropTypes.instanceOf(Message).isRequired };
|
|
|
|
state = {
|
|
v: 0,
|
|
};
|
|
|
|
_mounted: boolean = false;
|
|
|
|
componentDidMount() {
|
|
this._mounted = true;
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this._mounted = false;
|
|
}
|
|
|
|
_onClick = async () => {
|
|
const message = this.props.items.find(canUnsubscribe);
|
|
if (!message) return;
|
|
this.setState({ v: this.state.v + 1 });
|
|
await unsubscribe(message);
|
|
if (!this._mounted) return;
|
|
this.setState({ v: this.state.v + 1 });
|
|
};
|
|
|
|
render() {
|
|
if (!canUnsubscribe(this.props.message)) {
|
|
return <span />;
|
|
}
|
|
|
|
return (
|
|
<BindGlobalCommands commands={{ 'core:unsubscribe': () => this._onClick() }}>
|
|
<button
|
|
className={`btn btn-toolbar thread-unsubscribe-button`}
|
|
title={localized('Share')}
|
|
style={{ marginRight: 0 }}
|
|
onClick={this._onClick}
|
|
>
|
|
<RetinaImg name="ic-toolbar-native-share.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
</button>
|
|
</BindGlobalCommands>
|
|
);
|
|
}
|
|
}
|