Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

add chat visibility #434

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module.exports = {
DC_GCL_ADD_ALLDONE_HINT: 4,
DC_GCL_ADD_SELF: 2,
DC_GCL_ARCHIVED_ONLY: 1,
DC_GCL_FOR_FORWARDING: 8,
DC_GCL_NO_SPECIALS: 2,
DC_GCL_VERIFIED_ONLY: 1,
DC_GCM_ADDDAYMARKER: 1,
Expand Down
16 changes: 12 additions & 4 deletions lib/chat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable camelcase */

const binding = require('../binding')
const debug = require('debug')('deltachat:node:chat')
const { C } = require('./constants')
import binding from '../binding'
import rawDebug from 'debug'
const debug = rawDebug('deltachat:node:chat')
import { C } from './constants'

interface NativeChat {}
/**
Expand All @@ -13,6 +14,11 @@ export class Chat {
debug('Chat constructor')
}

getVisibility():C.DC_CHAT_VISIBILITY_NORMAL | C.DC_CHAT_VISIBILITY_ARCHIVED | C.DC_CHAT_VISIBILITY_PINNED {
return binding.dcn_chat_get_visibility(this.dc_chat)
}

/** @deprecated */
getArchived ():boolean {
return binding.dcn_chat_get_archived(this.dc_chat)
}
Expand Down Expand Up @@ -67,8 +73,10 @@ export class Chat {

toJson () {
debug('toJson')
const visibility = this.getVisibility()
return {
archived: this.getArchived(),
archived: visibility === C.DC_CHAT_VISIBILITY_ARCHIVED,
pinned: visibility === C.DC_CHAT_VISIBILITY_PINNED,
color: this.getColor(),
id: this.getId(),
name: this.getName(),
Expand Down
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export enum C {
DC_GCL_ADD_ALLDONE_HINT= 4,
DC_GCL_ADD_SELF= 2,
DC_GCL_ARCHIVED_ONLY= 1,
DC_GCL_FOR_FORWARDING= 8,
DC_GCL_NO_SPECIALS= 2,
DC_GCL_VERIFIED_ONLY= 1,
DC_GCM_ADDDAYMARKER= 1,
Expand Down
13 changes: 12 additions & 1 deletion lib/deltachat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import mkdirp from 'mkdirp'
import path from 'path'
import {Locations} from './locations'
import pick from 'lodash.pick'
const debug = require('debug')('deltachat:node:index')
import rawDebug from 'debug'
const debug = rawDebug('deltachat:node:index')

const noop = function () {}
const DC_SHOW_EMAILS = [
Expand Down Expand Up @@ -73,6 +74,7 @@ export class DeltaChat extends EventEmitter {
return binding.dcn_add_device_msg(this.dcn_context, label, msg.dc_msg)
}

/** @deprecated use setChatVisibility instead */
archiveChat (chatId:number, archive:boolean) {
debug(`archiveChat ${chatId} ${archive}`)
binding.dcn_archive_chat(
Expand All @@ -82,6 +84,15 @@ export class DeltaChat extends EventEmitter {
)
}

setChatVisibility(chatId:number, visibility: C.DC_CHAT_VISIBILITY_NORMAL | C.DC_CHAT_VISIBILITY_ARCHIVED | C.DC_CHAT_VISIBILITY_PINNED){
debug(`setChatVisibility ${chatId} ${visibility}`)
binding.dcn_set_chat_visibility(
this.dcn_context,
Number(chatId),
visibility
)
}

blockContact (contactId:number, block:boolean) {
debug(`blockContact ${contactId} ${block}`)
binding.dcn_block_contact(
Expand Down
26 changes: 26 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,19 @@ NAPI_METHOD(dcn_get_next_media) {
NAPI_RETURN_UINT32(next_id);
}

NAPI_METHOD(dcn_set_chat_visibility) {
NAPI_ARGV(3);
NAPI_DCN_CONTEXT();
NAPI_ARGV_UINT32(chat_id, 1);
NAPI_ARGV_INT32(visibility, 2);
//TRACE("calling..");
dc_set_chat_visibility(dcn_context->dc_context,
chat_id,
visibility);
//TRACE("result %d", next_id);
NAPI_RETURN_UNDEFINED();
}

NAPI_METHOD(dcn_get_securejoin_qr) {
NAPI_ARGV(2);
NAPI_DCN_CONTEXT();
Expand Down Expand Up @@ -1644,6 +1657,17 @@ NAPI_METHOD(dcn_chat_get_color) {
NAPI_RETURN_UINT32(color);
}

NAPI_METHOD(dcn_chat_get_visibility) {
NAPI_ARGV(1);
NAPI_DC_CHAT();

//TRACE("calling..");
uint32_t visibility = dc_chat_get_visibility(dc_chat);
//TRACE("result %d", color);

NAPI_RETURN_UINT32(visibility);
}

NAPI_METHOD(dcn_chat_get_id) {
NAPI_ARGV(1);
NAPI_DC_CHAT();
Expand Down Expand Up @@ -2740,6 +2764,7 @@ NAPI_INIT() {
NAPI_EXPORT_FUNCTION(dcn_get_msg_cnt);
NAPI_EXPORT_FUNCTION(dcn_get_msg_info);
NAPI_EXPORT_FUNCTION(dcn_get_next_media);
NAPI_EXPORT_FUNCTION(dcn_set_chat_visibility);
NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr);
NAPI_EXPORT_FUNCTION(dcn_imex);
NAPI_EXPORT_FUNCTION(dcn_imex_has_backup);
Expand Down Expand Up @@ -2776,6 +2801,7 @@ NAPI_INIT() {

NAPI_EXPORT_FUNCTION(dcn_chat_get_archived);
NAPI_EXPORT_FUNCTION(dcn_chat_get_color);
NAPI_EXPORT_FUNCTION(dcn_chat_get_visibility);
NAPI_EXPORT_FUNCTION(dcn_chat_get_id);
NAPI_EXPORT_FUNCTION(dcn_chat_get_name);
NAPI_EXPORT_FUNCTION(dcn_chat_get_profile_image);
Expand Down