Skip to content

Commit

Permalink
Fixed styling issues and optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjunetime committed Aug 28, 2020
1 parent b59c7cb commit 0597e01
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 104 deletions.
7 changes: 7 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

0.3.5 -> 0.3.6
- Maybe fixed Cydia never-ending update issue?
- Fixed styling issues with css grid noncompatible browsers
- Fixed weird colors on light theme
- Fixed crashing issue when marking conversation as read
- Optimized chat retrieval SQL Query

0.3.4 -> 0.3.5
- Added support for marking conversations as read when viewed in web interface
- Added support for relative date displays
Expand Down
11 changes: 7 additions & 4 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ This is the initial number of messages to load when you select a conversation on
### Initial number of photos to load:
This is the initial number of photos that will load when retrieving photos from the photos library on the device, specifically with the `photos` parameter on the `requests` As of 0-2-0+debug8, this has not yet been implemented into the web interface, but exists in the API.

### Theme
This setting sets the color theme of the web interface; Dark is the default. It is much more polished, and, I think, looks much better than the light theme, but I did make a light theme as well for easy access.

### Websocket Port
This is the port that the webSocket runs on; must not be the same as the server port or outside of the allowable range, or else the app will crash when launching the server. You must restart the server before this takes effect

### Theme
This setting sets the color theme of the web interface; Dark is the default. It is much more polished, and, I think, looks much better than the light theme, but I did make a light theme as well for easy access.

### Toggle debug
This will log basically every thing that happens, and may slow down the server considerably. Unless you're actually debugging or logging with the app, I'd highly recommend leaving this off. This does not require a server restart to take effect.

Expand All @@ -42,4 +42,7 @@ Toggling this on will prevent anyone from querying the host if they have not alr
Toggling this on will prevent the server from shutting off when the app goes into the background, given that the server is already running. Even if this is on, though, the server will shut down when the app is forcibly killed from the multitasking screen. This does not require anything to take effect, simply a toggle.

### Enable SSL
Toggling this will require you to connect to the `https://` site, instead of the `http://` site. It also encrypts everything sent to your phone for the server, preventing anyone from listening in on your messages.
Toggling this will require you to connect to the `https://` site, instead of the `http://` site. It also encrypts everything sent to your phone for the server, preventing anyone from listening in on your messages.

### Mark conversations as read when viewed on web interface
This should be fairly self explanatory; if this is toggled, whenever you view a conversation on the web interface, it is marked as read on your device as well.
8 changes: 2 additions & 6 deletions package/deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
Package: com.ianwelker.smserver
Depends: com.janshai.libsmserver | com.twickd.ian-welker.libsmserver
Name: SMServer
Version: 0.3.5
Version: 0.3.6
Architecture: iphoneos-arm
Description: Send texts from your browser!
Maintainer: Ian Welker
Maintainer: Ian Welker <[email protected]>
Author: Ian Welker
Section: Multimedia
dev: Ian Welker
Depiction:
Installed-Size: 0

Binary file not shown.
17 changes: 8 additions & 9 deletions src/SMServer/ChatDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class ChatDelegate {
/// check if it's a group chat
let is_group = num.prefix(4) == "chat"

let formatter = RelativeDateTimeFormatter()
formatter.dateTimeStyle = .named
/*let formatter = RelativeDateTimeFormatter()
formatter.dateTimeStyle = .named*/

/// for each message
for i in 0..<messages.count {
Expand Down Expand Up @@ -332,11 +332,14 @@ class ChatDelegate {
var contacts_db = createConnection(connection_string: "/private/var/mobile/Library/AddressBook/AddressBook.sqlitedb")
if db == nil || contacts_db == nil { return [[String:String]]() }

let chats = selectFromSql(db: db, columns: ["m.ROWID", "m.is_read", "m.is_from_me", "m.text", "m.item_type", "m.date_read", "m.date", "m.cache_has_attachments", "c.chat_identifier", "c.display_name", "c.room_name", "h.uncanonicalized_id"], table: "chat_message_join j", condition: "inner join message m on j.message_id = m.ROWID inner join chat c on c.ROWID = j.chat_id inner join chat_handle_join hj on hj.chat_id = c.ROWID inner join handle h on h.ROWID = hj.handle_id where j.message_date in (select max(message_date) from chat_message_join group by chat_id) group by c.chat_identifier order by j.message_date desc", num_items: num_to_load, offset: offset)
let chats = selectFromSql(db: db, columns: ["m.ROWID", "m.is_read", "m.is_from_me", "m.text", "m.item_type", "m.date_read", "m.date", "m.cache_has_attachments", "c.chat_identifier", "c.display_name", "c.room_name"], table: "chat_message_join j", condition: "inner join message m on j.message_id = m.ROWID inner join chat c on c.ROWID = j.chat_id where j.message_date in (select max(message_date) from chat_message_join group by chat_id) group by c.chat_identifier order by j.message_date desc", num_items: num_to_load, offset: offset)
var return_array = [[String:String]]()

let locale = Locale.current

let formatter = RelativeDateTimeFormatter()
formatter.dateTimeStyle = .numeric
formatter.locale = locale
formatter.dateTimeStyle = .named

for i in chats {
if self.debug {
Expand All @@ -346,11 +349,7 @@ class ChatDelegate {
var new_chat = [String:String]()

/// Check for if it has unread. It has to fit all these specific things.
if i["m.is_from_me"] == "0" && i["m.date_read"] == "0" && i["m.text"] != nil && i["m.is_read"] == "0" && i["m.item_type"] == "0" {
new_chat["has_unread"] = "true"
} else {
new_chat["has_unread"] = "false"
}
new_chat["has_unread"] = (i["m.is_from_me"] == "0" && i["m.date_read"] == "0" && i["m.text"] != nil && i["m.is_read"] == "0" && i["m.item_type"] == "0") ? "true" : "false"

/// Content of the most recent text. If a text has attachments, `i["m.text"]` will look like `\u{ef}`. this checks for that.
if i["m.text"]?.replacingOccurrences(of: "\u{fffc}", with: "", options: NSString.CompareOptions.literal, range: nil).trimmingCharacters(in: .whitespacesAndNewlines).count != 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/SMServer/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ContentView: View {
@State var show_picker = false

static let chat_delegate = ChatDelegate()
@State var s = Sender()
@State var s = IWSSender()
@State var watcher: IPCTextWatcher = IPCTextWatcher.sharedInstance()

let custom_css_path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("smserver_custom.css")
Expand Down Expand Up @@ -404,7 +404,7 @@ struct ContentView: View {
}

self.backgroundTask = UIApplication.shared.beginBackgroundTask(expirationHandler: {
if UIApplication.shared.applicationState == .background {
if UIApplication.shared.applicationState != .active {
if self.debug {
self.log("relaunching app...")
}
Expand Down
2 changes: 1 addition & 1 deletion src/SMServer/Obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@end

@interface Sender : NSObject
@interface IWSSender : NSObject

- (void)launchMobileSMS;
- (void)relaunchApp;
Expand Down
16 changes: 8 additions & 8 deletions src/SMServer/Obj.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,22 @@ - (void)handleBatteryChanged {

@end

@implementation Sender

@implementation IWSSender

- (void)relaunchApp {

NSLog(@"SMServer_app: Relaunching app in objc");

MRYIPCCenter* center = [MRYIPCCenter centerNamed:@"com.ianwelker.smserverLaunch"];
[center callExternalVoidMethod:@selector(relaunchSMServer) withArguments:nil];
[center callExternalVoidMethod:@selector(launchSMS:) withArguments:@"YES"];

}

- (void)launchMobileSMS {

NSLog(@"SMServer_app: Entered obj-c func, launching MobileSMS");

MRYIPCCenter* center = [MRYIPCCenter centerNamed:@"com.ianwelker.smserverLaunch"];
[center callExternalVoidMethod:@selector(launchSMS) withArguments:nil];

NSLog(@"SMServer_app: Called IPC to launch MobileSMS");
[center callExternalVoidMethod:@selector(launchSMS:) withArguments:@"NO"];
}

- (uid_t)setUID {
Expand All @@ -73,8 +71,10 @@ - (void)sendIPCText:(NSString *)body toAddress:(NSString *)address withAttachmen
}

- (void)markConvoAsRead:(NSString *)chat_id {

MRYIPCCenter* center = [MRYIPCCenter centerNamed:@"com.ianwelker.smserver"];
[center callExternalMethod:@selector(setAllAsRead:) withArguments:chat_id];
[center callExternalVoidMethod:@selector(setAllAsRead:) withArguments:chat_id];

}

@end
Expand Down
4 changes: 1 addition & 3 deletions src/SMServer/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
//contentView.endBackgroundTask()
}

func sceneWillResignActive(_ scene: UIScene) {
Expand All @@ -45,15 +44,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
//contentView.endBackgroundTask()
}

func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
if contentView.server.isListening && UserDefaults.standard.object(forKey: "backgrounding_enabled") as? Bool ?? true && contentView.backgroundTask == .invalid {
os_log("%{public}@%{public}@", log: OSLog(subsystem: "com.ianwelker.smserver", category: "debugging"), type: .debug, "SMServer_app: ", "sceneDidEnterBackground, starting background task")
os_log("%{public}@", log: OSLog(subsystem: "com.ianwelker.smserver", category: "debugging"), type: .debug, "SMServer_app: sceneDidEnterBackground, starting background task")
contentView.startBackgroundTask()
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/SMServer/SocketDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class SocketDelegate : ServerWebSocketDelegate {
webSocket.send(text: "battery:\(String(battery_level))")*/

/// Backgrounding doesn't work with the next line uncommented
//NotificationCenter.default.addObserver(self, selector: Selector(("sendNewBattery:")), name: UIDevice.batteryLevelDidChangeNotification, object: nil)
}

func server(_ server: Server, webSocketDidDisconnect webSocket: WebSocket, error: Error?) {
Expand All @@ -105,7 +104,7 @@ class SocketDelegate : ServerWebSocketDelegate {
func server(_ server: Server, webSocket: WebSocket, didReceiveMessage message: WebSocketMessage) {
// One of our web sockets sent us a message
if message.payload.data != nil && self.debug {
self.log("Received message: \(String(describing: message.payload.data))")
self.log("Received message: \(message.payload.data)")
}
}
}
Expand Down
42 changes: 25 additions & 17 deletions src/SMServer/html/chats.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
var prefix = "";

if (doc_url === "127.0.0.1" || doc_url === "localhost") { /// when I'm debugging on local computer
prefix = "http://192.168.50.10:8741";
prefix = "http://10.37.27.19:8741";
num_texts_to_load = 100;
num_chats_to_load = 60;
socket_port = 8740;
socket_address = "192.168.50.10";
socket_address = "10.37.27.19";
}

function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp * 1000);
function timeConverter(t) {
var ts = (t / 1000000000) + 978307200;

var a = new Date(ts * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
Expand Down Expand Up @@ -76,8 +78,8 @@
classes += (text.is_from_me === "0" ? " is_from_them" : " is_from_me") + " " + text.service

t.setAttribute("class", classes);
//t.setAttribute("id", "texts-" + text.ROWID);
t.setAttribute("id", text.guid);
t.setAttribute("title", timeConverter(text.date));
t.innerHTML = ''

if (text.hasOwnProperty('attachment_file') && text.attachment_file.length != 0) {
Expand Down Expand Up @@ -110,22 +112,33 @@
i.src = prefix + "/data?chat_id=" + chat.chat_identifier.replace("+", "%2B");
b.appendChild(i);

var nonpic = document.createElement("div");
nonpic.setAttribute("class", "chat-nonpic");

var top = document.createElement("div");
top.setAttribute("class", "chat-toprow");

var n = document.createElement("div");
n.setAttribute("class", "chat-name");
n.innerHTML = (chat.display_name.length === 0 ? chat.chat_identifier : chat.display_name)
if (chat.chat_identifier.substring(0, 4) !== "chat" && chat.display_name.length !== 0) {
n.innerHTML += "<span style=\"color: #858585; font-weight: 200;\"> (" + chat.chat_identifier + ")</span>";
}
b.appendChild(n);
top.appendChild(n);

var d = document.createElement("div");
d.setAttribute("class", "chat-date");
d.innerHTML = chat.relative_time;
top.appendChild(d);

nonpic.appendChild(top);

var t = document.createElement("div");
t.setAttribute("class", "chat-text");
t.innerHTML = chat.latest_text.replace("", "").replace("", "")
b.appendChild(t);
nonpic.appendChild(t);
b.appendChild(nonpic);

//let unix_timestamp = (chat.time_marker / 1000000000) + 978307200;
//b.innerHTML += "<div class=\"chat-date\">" + timeConverter(unix_timestamp) + "</div>";
b.innerHTML += "<div class=\"chat-date\">" + chat.relative_time + "</div>";

if (chat.has_unread === "true") b.setAttribute("class", "unread");
var get_texts_string = "getTexts(\"" + chat.chat_identifier + "\", " + num_texts + ");";
Expand Down Expand Up @@ -351,13 +364,11 @@

var t = getTextElement(texts[i], i === 0);

/// So uh do ((date/1000000000) + 978307200) == unix timestamp.
if (i != 0 && texts[i].date - texts[i - 1].date < -3600000000000) {
var time = document.createElement("div");
time.setAttribute("class", "time-display");

let unix_timestamp = (texts[i].date / 1000000000) + 978307200
var formattedTime = timeConverter(unix_timestamp)
var formattedTime = timeConverter(texts[i].date);

time.innerHTML = "<p>" + formattedTime + "</p>"
doc.insertBefore(time, document.getElementById("moretextsbutton").nextSibling)
Expand Down Expand Up @@ -415,14 +426,11 @@

var t = getTextElement(texts[i], i === 0);

/// So uh do ((date/1000000000) + 978307200) == unix timestamp.
if (i != 0 && texts[i].date - texts[i - 1].date < -3600000000000) {
var time = document.createElement("div");
time.setAttribute("class", "time-display");

let unix_timestamp = (texts[i].date / 1000000000) + 978307200

var formattedTime = timeConverter(unix_timestamp)
var formattedTime = timeConverter(texts[i].date)

time.innerHTML = "<p>" + formattedTime + "</p>"
doc.insertBefore(time, document.getElementById("moretextsbutton").nextSibling)
Expand Down
62 changes: 27 additions & 35 deletions src/SMServer/html/light_theme.css
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
:root {
--chats-border: #e5e5e5;
--font-color: #070707;
--chats-border: #e5e5e5;
--font-color: #070707;
--text-box-gradient: linear-gradient(to bottom right, #ccc, #bbb);
}
body, html {
background-color: #fff;
body, html, .messages, .chats button:hover {
background-color: #fff;
}
.messages {
background-color: #fff;
border-color: var(--chats-border);
border-color: var(--chats-border);
}
.chats button {
background-color: #ddd;
}
.chats button:hover {
background-color: #fff;
}
.messages .title {
background-color: #ddd;
}
.is_from_them {
background-color: #ddd;
.chats button, .messages .title, .is_from_them, #sendbox
#unhiddenbutton, #camerarollbutton, #composeShowButton, #notificationbutton {
background-color: #ddd;
}
.is_from_me {
background-color: #58f;
background-image: none;
color: #fff;
}
#sendbox {
background-color: #ddd;
}
#unhiddenbutton {
background-color: #ddd
background-color: #58f;
background-image: none;
color: #fff;
}
#sendbutton {
font-size: 16px;
color: #fff;
padding-left: 6px;
padding-top: 2px;
}
#composeShowButton {
background-color: #ddd;
font-size: 16px;
color: #fff;
padding-left: 6px;
padding-top: 2px;
}
.centered {
text-shadow: -2px 2px #e5e5e5;
Expand All @@ -55,5 +38,14 @@ body, html {
color: rgba(0, 0, 100, 0.6);
}
#morechatsbutton {
border: none;
}
border: none;
}
#composeShowingAttachmentButton {
box-shadow: 0px 0px 6px #858585;
}
#composeHideButton, #camerarollHideButton, #composeSendBox {
background-color: #ddd4;
}
#composeSendBox {
color: white;
}
Loading

0 comments on commit 0597e01

Please sign in to comment.