Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1568|回复: 0
打印 上一主题 下一主题

MailSpring源码分析--左侧账户树

[复制链接]

1272

主题

2067

帖子

7962

积分

认证用户组

Rank: 5Rank: 5

积分
7962
跳转到指定楼层
楼主
发表于 2020-10-14 18:48:23 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
app\src\flux\mailsync-bridge.ts
_onIncomingMessages = msgs => {
  for (const msg of msgs) {
   json = JSON.parse(msg);
   const { type, modelJSONs, modelClass } = json;   ---modelClass: Folder Message Thread
   const models = modelJSONs.map(Utils.convertToModel);
      this._onIncomingChangeRecord(
        new DatabaseChangeRecord({
          type, // TODO BG move to "model" naming style, finding all uses might be tricky
          objectClass: modelClass,
          objects: models,
          objectsRawJSON: modelJSONs,
        })
      );
      }
_onIncomingChangeRecord{
  // Allow observers of the database to handle this change
    DatabaseStore.trigger(record);  //查找对应的监听事件DatabaseStore.listen
}

app\src\flux\stores\database-store.ts
class DatabaseStore extends MailspringStore {

}

监听事件DatabaseStore.listen
app\internal_packages\thread-sharing\lib\main.tsx //分享
this._unlisten = DatabaseStore.listen(_onDatabaseChange);
  ipcRenderer.on('openThreadFromWeb', _onOpenThreadFromWeb);

const _onDatabaseChange = change => {  
   change.objects.forEach(async thread => {
    if (isShared(thread)) { //这里是分享的逻辑,不再跟了
      syncThreadToWebSoon(thread); //会上传送到官方
    }

app\internal_packages\unread-notifications\lib\main.ts  //新邮件通知逻辑处理

app\src\components\list-selection.ts  //列表选中部分的处理

跟踪不到,直接找下左侧的邮件账号树控件,看数据从哪里加载
app\internal_packages\account-sidebar\lib\components\account-sidebar.tsx



app\internal_packages\account-sidebar\lib\sidebar-store.ts

this.listenTo(AccountStore, this._onAccountsChanged);
this.listenTo(CategoryStore, this._updateSections);
  _updateSections = () => {
   this._sections[Sections.Standard] = SidebarSection.standardSectionForAccounts(accounts);
  }

app\internal_packages\account-sidebar\lib\sidebar-section.ts

  if (CategoryStore.categories().length === 0) {
      return this.empty(localized('All Accounts'));
    }


app\src\flux\stores\category-store.ts  //数据来源
_categoryCache = {};
Categories.forAllAccounts()  //从数据库查询
      .sort()
      .subscribe(this._onCategoriesChanged);

_onCategoriesChanged = categories => {
    this._categoryResult = categories;
    this._categoryCache = {};
    for (const cat of categories) {
      this._categoryCache[cat.accountId] = this._categoryCache[cat.accountId] || {};
      this._categoryCache[cat.accountId][cat.id] = cat;
    }

app\src\global\mailspring-observables.ts
const CategoryObservables = {
  forAllAccounts() {
    const folders = Rx.Observable.fromQuery<Folder[]>(DatabaseStore.findAll<Folder>(Folder));
    const labels = Rx.Observable.fromQuery(DatabaseStore.findAll<Label>(Label));
    const joined = Rx.Observable.combineLatest<Category[], Category[], Category[]>(
      folders,
      labels,
      (f, l) => [].concat(f, l)
    );
    Object.assign(joined, CategoryOperators);
    return joined as Observable<Category[]> & ICategoryOperators;
  },





app\internal_packages\category-picker\spec\category-picker-spec.jsx
app\spec\mailbox-perspective-spec.ts
app\spec\tasks\task-factory-spec.ts
生成邮件夹的测试用例  造数据


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-11-26 06:33 , Processed in 0.056898 second(s), 20 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表